diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index f5084b61693c..9e44a9ad66b5 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -6637,7 +6637,15 @@ def to_dict(self, view='element'): return rval -class PageUserShareAssociation(UserShareAssociation): +class PageUserShareAssociation(Base, UserShareAssociation): + __tablename__ = 'page_user_share_association' + + id = Column("id", Integer, primary_key=True) + page_id = Column("page_id", Integer, ForeignKey("page.id"), index=True) + user_id = Column("user_id", Integer, ForeignKey("galaxy_user.id"), index=True) + user = relationship('User', back_populates='pages_shared_by_others') + page = relationship('Page', back_populates='users_shared_with') + def __init__(self): self.page = None self.user = None diff --git a/lib/galaxy/model/mapping.py b/lib/galaxy/model/mapping.py index ff00a39862f2..bf730ea1c3bd 100644 --- a/lib/galaxy/model/mapping.py +++ b/lib/galaxy/model/mapping.py @@ -1062,12 +1062,6 @@ Index('ix_page_slug', 'slug', mysql_length=200), ) -model.PageUserShareAssociation.table = Table( - "page_user_share_association", metadata, - Column("id", Integer, primary_key=True), - Column("page_id", Integer, ForeignKey("page.id"), index=True), - Column("user_id", Integer, ForeignKey("galaxy_user.id"), index=True)) - model.Visualization.table = Table( "visualization", metadata, Column("id", Integer, primary_key=True), @@ -1633,6 +1627,7 @@ def simple_mapping(model, **kwds): galaxy_sessions=relation(model.GalaxySession, backref="user", order_by=desc(model.GalaxySession.table.c.update_time)), + pages_shared_by_others=relation(model.PageUserShareAssociation, back_populates='user'), quotas=relation(model.UserQuotaAssociation, back_populates='user'), social_auth=relation(model.UserAuthnzToken, back_populates='user'), stored_workflow_menu_entries=relation(model.StoredWorkflowMenuEntry, @@ -2309,7 +2304,8 @@ def simple_mapping(model, **kwds): average_rating=column_property( select(func.avg(model.PageRatingAssociation.table.c.rating)).where(model.PageRatingAssociation.table.c.page_id == model.Page.table.c.id).scalar_subquery(), deferred=True - ) + ), + users_shared_with=relation(model.PageUserShareAssociation, back_populates='page') )) # Set up proxy so that @@ -2317,10 +2313,6 @@ def simple_mapping(model, **kwds): # returns a list of users that page is shared with. model.Page.users_shared_with_dot_users = association_proxy('users_shared_with', 'user') # type: ignore -mapper_registry.map_imperatively(model.PageUserShareAssociation, model.PageUserShareAssociation.table, - properties=dict(user=relation(model.User, backref='pages_shared_by_others'), - page=relation(model.Page, backref='users_shared_with'))) - mapper_registry.map_imperatively(model.Visualization, model.Visualization.table, properties=dict( user=relation(model.User), revisions=relation(model.VisualizationRevision, diff --git a/test/unit/model/test_model.py b/test/unit/model/test_model.py index 731484bb5275..322c36100f08 100644 --- a/test/unit/model/test_model.py +++ b/test/unit/model/test_model.py @@ -200,6 +200,21 @@ def test_PageRevision(model, session, page): assert stored_obj.page.id == page.id +def test_PageUserShareAssociation(model, session, page, user): + cls = model.PageUserShareAssociation + assert cls.__tablename__ == 'page_user_share_association' + with dbcleanup(session, cls): + obj = cls() + obj.page = page + obj.user = user + obj_id = persist(session, obj) + + stored_obj = get_stored_obj(session, cls, obj_id) + assert stored_obj.id == obj_id + assert stored_obj.page == page + assert stored_obj.user == user + + def test_PSAAssociation(model, session): cls = model.PSAAssociation assert cls.__tablename__ == 'psa_association'