Skip to content

Commit

Permalink
Map PageUserShareAssociation declaratively
Browse files Browse the repository at this point in the history
  • Loading branch information
jdavcs committed Sep 7, 2021
1 parent 37edac4 commit bc174c4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
10 changes: 9 additions & 1 deletion lib/galaxy/model/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 3 additions & 11 deletions lib/galaxy/model/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -2309,18 +2304,15 @@ 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
# Page.users_shared_with
# 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,
Expand Down
15 changes: 15 additions & 0 deletions test/unit/model/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit bc174c4

Please sign in to comment.