def delete(self, trans, id: EncodedDatabaseIdField): """ Deletes a page (or marks it as deleted) """ page = base.get_object(trans, id, 'Page', check_ownership=True) # Mark a page as deleted page.deleted = True trans.sa_session.flush()
def _get_item_by_id(self, trans, id: EncodedDatabaseIdField): class_name = self.manager.model_class.__name__ item = base.get_object(trans, id, class_name, check_ownership=True, check_accessible=True, deleted=False) return item
def get_quota(self, trans, id: EncodedDatabaseIdField, deleted: Optional[bool] = None) -> model.Quota: return base.get_object(trans, id, 'Quota', check_ownership=False, check_accessible=False, deleted=deleted)
def show(self, trans, id: EncodedDatabaseIdField) -> PageDetails: """View a page summary and the content of the latest revision :param id: ID of page to be displayed :rtype: dict :returns: Dictionary return of the Page.to_dict call with the 'content' field populated by the most recent revision """ page = base.get_object(trans, id, 'Page', check_ownership=False, check_accessible=True) rval = trans.security.encode_all_ids(page.to_dict(), recursive=True) rval['content'] = page.latest_revision.content rval['content_format'] = page.latest_revision.content_format self.manager.rewrite_content_for_export(trans, rval) return PageDetails.parse_obj(rval)
def show_pdf(self, trans, id: EncodedDatabaseIdField): """ View a page summary and the content of the latest revision as PDF. :param id: ID of page to be displayed :rtype: dict :returns: Dictionary return of the Page.to_dict call with the 'content' field populated by the most recent revision """ page = base.get_object(trans, id, 'Page', check_ownership=False, check_accessible=True) if page.latest_revision.content_format != PageContentFormat.markdown.value: raise exceptions.RequestParameterInvalidException("PDF export only allowed for Markdown based pages") internal_galaxy_markdown = page.latest_revision.content return internal_galaxy_markdown_to_pdf(trans, internal_galaxy_markdown, 'page')
def get_object(self, trans, id, class_name, check_ownership=False, check_accessible=False, deleted=None): """ Convenience method to get a model object with the specified checks. """ return managers_base.get_object(trans, id, class_name, check_ownership=check_ownership, check_accessible=check_accessible, deleted=deleted)
def delete(self, trans, id, **kwd): """ delete( self, trans, id, **kwd ) * DELETE /api/pages/{id} Create a page and return dictionary containing Page summary :param id: ID of page to be deleted :rtype: dict :returns: Dictionary with 'success' or 'error' element to indicate the result of the request """ page = get_object(trans, id, 'Page', check_ownership=True) # Mark a page as deleted page.deleted = True trans.sa_session.flush() return '' # TODO: Figure out what to return on DELETE, document in guidelines!
def create(self, trans, page_id, payload, **kwd): """ create( self, trans, page_id, payload **kwd ) * POST /api/pages/{page_id}/revisions Create a new revision for a page :param page_id: Add revision to Page with ID=page_id :param payload: A dictionary containing:: 'content' = New content of new page revision :rtype: dictionary :returns: Dictionary with 'success' or 'error' element to indicate the result of the request """ page = get_object(trans, page_id, 'Page', check_ownership=True) page_revision = self.manager.save_new_revision(trans, page, payload) rval = self.encode_all_ids(trans, page_revision.to_dict(view="element"), True) self.manager.rewrite_content_for_export(trans, rval) return rval
def show(self, trans, id, **kwd): """ show( self, trans, id, **kwd ) * GET /api/pages/{id} View a page summary and the content of the latest revision :param id: ID of page to be displayed :rtype: dict :returns: Dictionary return of the Page.to_dict call with the 'content' field populated by the most recent revision """ page = get_object(trans, id, 'Page', check_ownership=False, check_accessible=True) rval = self.encode_all_ids(trans, page.to_dict(), True) rval['content'] = page.latest_revision.content self.manager.rewrite_content_for_export(trans, rval) return rval
def show_pdf(self, trans, id, **kwd): """ show( self, trans, id, **kwd ) * GET /api/pages/{id}.pdf View a page summary and the content of the latest revision as PDF. :param id: ID of page to be displayed :rtype: dict :returns: Dictionary return of the Page.to_dict call with the 'content' field populated by the most recent revision """ page = get_object(trans, id, 'Page', check_ownership=False, check_accessible=True) if page.latest_revision.content_format != "markdown": raise RequestParameterInvalidException( "PDF export only allowed for Markdown based pages") internal_galaxy_markdown = page.latest_revision.content trans.response.set_content_type("application/pdf") return internal_galaxy_markdown_to_pdf(trans, internal_galaxy_markdown, 'page')
def index(self, trans, page_id, **kwd): """ index( self, trans, page_id, **kwd ) * GET /api/pages/{page_id}/revisions return a list of Page revisions :param page_id: Display the revisions of Page with ID=page_id :rtype: list :returns: dictionaries containing different revisions of the page """ page = get_object(trans, page_id, 'Page', check_ownership=False, check_accessible=True) r = trans.sa_session.query( trans.app.model.PageRevision).filter_by(page_id=page.id) out = [] for page in r: as_dict = self.encode_all_ids(trans, page.to_dict(), True) self.manager.rewrite_content_for_export(trans, as_dict) out.append(as_dict) return out
def get(self, trans, id, check_accessible=True): return manager_base.get_object(trans, id, 'LibraryDatasetDatasetAssociation', check_ownership=False, check_accessible=check_accessible)
def get( self, trans, id, check_accessible=True ): return manager_base.get_object( trans, id, 'LibraryDatasetDatasetAssociation', check_ownership=False, check_accessible=check_accessible )
def sharing(self, trans, id: EncodedDatabaseIdField, payload: Optional[SharingPayload] = None) -> SharingStatus: """Allows to publish or share with other users the given resource (by id) and returns the current sharing status of the resource. :param id: The encoded ID of the resource to share. :type id: EncodedDatabaseIdField :param payload: The options to share this resource, defaults to None :type payload: Optional[sharable.SharingPayload], optional :return: The current sharing status of the resource. :rtype: sharable.SharingStatus """ skipped = False class_name = self.manager.model_class.__name__ item = base.get_object(trans, id, class_name, check_ownership=True, check_accessible=True, deleted=False) actions = [] if payload: actions += payload.action.split("-") for action in actions: if action == "make_accessible_via_link": self._make_item_accessible(trans.sa_session, item) if hasattr(item, "has_possible_members") and item.has_possible_members: skipped = self._make_members_public(trans, item) elif action == "make_accessible_and_publish": self._make_item_accessible(trans.sa_session, item) if hasattr(item, "has_possible_members") and item.has_possible_members: skipped = self._make_members_public(trans, item) item.published = True elif action == "publish": if item.importable: item.published = True if hasattr(item, "has_possible_members") and item.has_possible_members: skipped = self._make_members_public(trans, item) else: raise exceptions.MessageException(f"{class_name} not importable.") elif action == "disable_link_access": item.importable = False elif action == "unpublish": item.published = False elif action == "disable_link_access_and_unpublish": item.importable = item.published = False elif action == "unshare_user": if payload is None or payload.user_id is None: raise exceptions.MessageException(f"Missing required user_id to perform {action}") user = trans.sa_session.query(trans.app.model.User).get(trans.app.security.decode_id(payload.user_id)) class_name_lc = class_name.lower() ShareAssociation = getattr(trans.app.model, f"{class_name}UserShareAssociation") usas = trans.sa_session.query(ShareAssociation).filter_by(**{"user": user, class_name_lc: item}).all() if not usas: raise exceptions.MessageException(f"{class_name} was not shared with user.") for usa in usas: trans.sa_session.delete(usa) trans.sa_session.add(item) trans.sa_session.flush() if item.importable and not item.slug: self._make_item_accessible(trans.sa_session, item) item_dict = self.serializer.serialize_to_view(item, user=trans.user, trans=trans, default_view="sharing") item_dict["users_shared_with"] = [{"id": self.manager.app.security.encode_id(a.user.id), "email": a.user.email} for a in item.users_shared_with] if skipped: item_dict["skipped"] = True return SharingStatus.parse_obj(item_dict)