Skip to content

Commit

Permalink
Add preliminary support for users having access to the history
Browse files Browse the repository at this point in the history
  • Loading branch information
guerler committed May 2, 2018
1 parent 6e2f410 commit 606b6e4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 4 additions & 1 deletion lib/galaxy/managers/histories.py
Expand Up @@ -261,9 +261,12 @@ def add_serializers(self):

'contents_states': self.serialize_contents_states,
'contents_active': self.serialize_contents_active,
'users_shared_with': lambda i, k, **c: [{'id': a.user.id, 'email': a.user.email} for a in i.users_shared_with],
'users_shared_with': self.serialize_users_shared_with,
})

def serialize_users_shared_with(self, history, key=None, **context):
return [{'id': self.app.security.encode_id(a.user.id), 'email': a.user.email} for a in history.users_shared_with]

# remove this
def serialize_state_ids(self, history, key, **context):
"""
Expand Down
15 changes: 9 additions & 6 deletions lib/galaxy/webapps/galaxy/api/histories.py
Expand Up @@ -560,19 +560,22 @@ def sharing(self, trans, history_id, payload=None, **kwd):
elif action == "unshare_user":
user = trans.sa_session.query(trans.app.model.User).get(self.decode_id(payload.get("user_id")))
husas = trans.sa_session.query(trans.app.model.HistoryUserShareAssociation).filter_by(user=user, history=history).all()
if husas:
for husa in husas:
trans.sa_session.delete(husa)
else:
if not husas:
raise exceptions.MessageException("History was not shared with user.")
for husa in husas:
trans.sa_session.delete(husa)
if history.importable and not history.slug:
self._make_item_accessible(trans.sa_session, history)
trans.sa_session.add(history)
trans.sa_session.flush()
return {"message": "Sharing status updated.", "item": {"published": history.published, "importable": history.importable}}
return {"message": "Sharing status updated.", "item": {
"published": history.published,
"importable": history.importable,
"users_shared_with": [{"id": trans.app.security.encode_id(a.user.id), "email": a.user.email} for a in history.users_shared_with]
}}

def _get_history(self, trans, id):
history = self.history_manager.get_accessible(self.decode_id(id), trans.user, current_history=trans.history)
if not history:
raise MessageException('Invalid history (%s).' % id)
raise MessageException("Invalid history (%s)." % id)
return history

0 comments on commit 606b6e4

Please sign in to comment.