From bf8e01ceffd48bf0669336a64c428f7785e912f5 Mon Sep 17 00:00:00 2001 From: Jeremy Goecks Date: Mon, 16 Aug 2010 17:05:59 -0400 Subject: [PATCH] Enhancements and fixes for sharing framework: (a) sharing/publishing webpages can now be displayed in frames; (b) sharing webpages can display messages; (c) workflow sharing highlights correct tab; (d) history sharing for individual users now uses sharing framework; (e) item sharing with individual users now uses common template. --- lib/galaxy/web/controllers/history.py | 18 ++- lib/galaxy/web/controllers/page.py | 9 +- lib/galaxy/web/controllers/visualization.py | 9 +- lib/galaxy/web/controllers/workflow.py | 12 +- templates/history/sharing.mako | 71 --------- templates/ind_share_base.mako | 108 +++++++++++++ templates/share_base.mako | 36 ----- templates/sharing_base.mako | 72 +++++++-- templates/workflow/share.mako | 36 ----- templates/workflow/sharing.mako | 162 +------------------- 10 files changed, 201 insertions(+), 332 deletions(-) delete mode 100644 templates/history/sharing.mako create mode 100644 templates/ind_share_base.mako delete mode 100644 templates/share_base.mako delete mode 100644 templates/workflow/share.mako diff --git a/lib/galaxy/web/controllers/history.py b/lib/galaxy/web/controllers/history.py index a74907f9efe..504f887528d 100644 --- a/lib/galaxy/web/controllers/history.py +++ b/lib/galaxy/web/controllers/history.py @@ -1114,16 +1114,18 @@ class HistoryController( BaseController, Sharable, UsesAnnotations, UsesItemRati history.importable = history.published = False elif 'unshare_user' in kwargs: user = trans.sa_session.query( trans.app.model.User ).get( trans.security.decode_id( kwargs[ 'unshare_user' ] ) ) - if not user: - message = 'History (%s) does not seem to be shared with user (%s)' % ( history.name, user.email ) - return trans.fill_template( 'history/sharing.mako', - histories=histories, - message=message, - status='error' ) + # Look for and delete sharing relation for history-user. + deleted_sharing_relation = False husas = trans.sa_session.query( trans.app.model.HistoryUserShareAssociation ).filter_by( user=user, history=history ).all() if husas: + deleted_sharing_relation = True for husa in husas: - trans.sa_session.delete( husa ) + trans.sa_session.delete( husa ) + if not deleted_sharing_relation: + message = "History '%s' does not seem to be shared with user '%s'" % ( history.name, user.email ) + return trans.fill_template( '/sharing_base.mako', item=history, + message=message, status='error' ) + # Legacy issue: histories made accessible before recent updates may not have a slug. Create slug for any histories that need them. for history in histories: @@ -1188,7 +1190,7 @@ class HistoryController( BaseController, Sharable, UsesAnnotations, UsesItemRati elif not send_to_err: # User seems to be sharing an empty history send_to_err = "You cannot share an empty history. " - return trans.fill_template( "/history/share.mako", histories=histories, email=email, send_to_err=send_to_err ) + return trans.fill_template( "/ind_sharing_base.mako", histories=histories, email=email, send_to_err=send_to_err ) @web.expose @web.require_login( "share restricted histories with other users" ) diff --git a/lib/galaxy/web/controllers/page.py b/lib/galaxy/web/controllers/page.py index a80e0c42502..410c6833071 100644 --- a/lib/galaxy/web/controllers/page.py +++ b/lib/galaxy/web/controllers/page.py @@ -470,11 +470,11 @@ class PageController( BaseController, Sharable, UsesAnnotations, UsesHistory, session.flush() return trans.fill_template( "/sharing_base.mako", - item=page ) + item=page, use_panels=True ) @web.expose @web.require_login( "use Galaxy pages" ) - def share( self, trans, id, email="" ): + def share( self, trans, id, email="", use_panels=False ): """ Handle sharing with an individual user. """ msg = mtype = None page = trans.sa_session.query( model.Page ).get( trans.security.decode_id( id ) ) @@ -503,11 +503,12 @@ class PageController( BaseController, Sharable, UsesAnnotations, UsesHistory, session.flush() trans.set_message( "Page '%s' shared with user '%s'" % ( page.title, other.email ) ) return trans.response.send_redirect( url_for( controller='page', action='sharing', id=id ) ) - return trans.fill_template( "/share_base.mako", + return trans.fill_template( "/ind_share_base.mako", message = msg, messagetype = mtype, item=page, - email=email ) + email=email, + use_panels=use_panels ) @web.expose @web.require_login() diff --git a/lib/galaxy/web/controllers/visualization.py b/lib/galaxy/web/controllers/visualization.py index d0721076aa9..04728980267 100644 --- a/lib/galaxy/web/controllers/visualization.py +++ b/lib/galaxy/web/controllers/visualization.py @@ -225,11 +225,11 @@ class VisualizationController( BaseController, Sharable, UsesAnnotations, UsesVi session.flush() - return trans.fill_template( "/sharing_base.mako", item=visualization ) + return trans.fill_template( "/sharing_base.mako", item=visualization, use_panels=True ) @web.expose @web.require_login( "share Galaxy visualizations" ) - def share( self, trans, id=None, email="", **kwd ): + def share( self, trans, id=None, email="", use_panels=False ): """ Handle sharing a visualization with a particular user. """ msg = mtype = None visualization = trans.sa_session.query( model.Visualization ).get( trans.security.decode_id( id ) ) @@ -258,11 +258,12 @@ class VisualizationController( BaseController, Sharable, UsesAnnotations, UsesVi session.flush() trans.set_message( "Visualization '%s' shared with user '%s'" % ( visualization.title, other.email ) ) return trans.response.send_redirect( url_for( action='sharing', id=id ) ) - return trans.fill_template( "/share_base.mako", + return trans.fill_template( "/ind_share_base.mako", message = msg, messagetype = mtype, item=visualization, - email=email ) + email=email, + use_panels=use_panels ) @web.expose diff --git a/lib/galaxy/web/controllers/workflow.py b/lib/galaxy/web/controllers/workflow.py index 8c286e427f7..c0f82ffb8be 100644 --- a/lib/galaxy/web/controllers/workflow.py +++ b/lib/galaxy/web/controllers/workflow.py @@ -239,7 +239,7 @@ class WorkflowController( BaseController, Sharable, UsesStoredWorkflow, UsesAnno @web.expose @web.require_login( "use Galaxy workflows" ) - def share( self, trans, id, email="" ): + def share( self, trans, id, email="", use_panels=False ): msg = mtype = None # Load workflow from database stored = self.get_stored_workflow( trans, id ) @@ -268,11 +268,12 @@ class WorkflowController( BaseController, Sharable, UsesStoredWorkflow, UsesAnno session.flush() trans.set_message( "Workflow '%s' shared with user '%s'" % ( stored.name, other.email ) ) return trans.response.send_redirect( url_for( controller='workflow', action='sharing', id=id ) ) - return trans.fill_template( "workflow/share.mako", + return trans.fill_template( "/ind_share_base.mako", message = msg, messagetype = mtype, - stored=stored, - email=email ) + item=stored, + email=email, + use_panels=use_panels ) @web.expose @web.require_login( "use Galaxy workflows" ) @@ -312,8 +313,7 @@ class WorkflowController( BaseController, Sharable, UsesStoredWorkflow, UsesAnno session.flush() - return trans.fill_template( "/sharing_base.mako", - item=stored ) + return trans.fill_template( "/workflow/sharing.mako", use_panels=True, item=stored ) @web.expose @web.require_login( "to import a workflow", use_panels=True ) diff --git a/templates/history/sharing.mako b/templates/history/sharing.mako deleted file mode 100644 index 5a4f573708c..00000000000 --- a/templates/history/sharing.mako +++ /dev/null @@ -1,71 +0,0 @@ -<%inherit file="/base.mako"/> -<%namespace file="/message.mako" import="render_msg" /> -<%namespace file="/display_base.mako" import="get_history_link" /> - -##

Import via link

- -%if message: - ${render_msg( message, status )} -%endif - -

Histories that you've shared with others or enabled to be imported

- -%if not histories: - You have no histories that you've shared with others or enabled to be imported -%else: - %for history in histories: -
-
History '${history.get_display_name()}' shared with
-
- - %if history.users_shared_with: - %for i, association in enumerate( history.users_shared_with ): - <% user = association.user %> -
- Unshare - ${user.email} -
- %endfor - %endif - %if history.importable: -
- <% url = get_history_link( history, True )%> - ${url} -
- Send the above link to users as an easy way for them to view the history. -
-
-
- <% url = h.url_for( controller='history', action='imp', id=trans.security.encode_id(history.id), qualified=True ) %> - ${url} -
- Send the above link to users as an easy way for them to import the history, making a copy of their own. -
-
-
-
-
- -
-
-
- %else: -
-
- -
- Click to generate a URL that you can give to a user to allow them to import this history, making a copy of their own -
-
-
- %endif -
-
- %endfor -%endif diff --git a/templates/ind_share_base.mako b/templates/ind_share_base.mako new file mode 100644 index 00000000000..6fd79a48a29 --- /dev/null +++ b/templates/ind_share_base.mako @@ -0,0 +1,108 @@ +## +## Base template for sharing an item with an individual user. Template expects the following parameters: +## (a) item - item to be shared. +## +<%! + def inherit(context): + if context.get('use_panels'): + if context.get('webapp'): + webapp = context.get('webapp') + else: + webapp = 'galaxy' + return '/webapps/%s/base_panels.mako' % webapp + else: + return '/base.mako' +%> +<%inherit file="${inherit(context)}"/> + +<%namespace file="./display_common.mako" import="*" /> + +## +## Page methods. +## + +<%def name="init()"> +<% + self.has_left_panel=False + self.has_right_panel=False + self.message_box_visible=False + self.overlay_visible=False + self.message_box_class="" + self.active_view="" + self.body_class="" +%> + + +<%def name="stylesheets()"> + ${parent.stylesheets()} + + + + +<%def name="center_panel()"> + ${self.body()} + + +<%def name="body()"> + %if message: + <% + if messagetype is UNDEFINED: + mt = "done" + else: + mt = messagetype + %> +

+

+ ${message} +
+

+ %endif + + <% + # + # Setup and variables needed for page. + # + + # Get class name strings. + item_class_name = get_class_display_name( item.__class__ ) + item_class_name_lc = item_class_name.lower() + item_class_plural_name = get_class_plural_display_name( item.__class__ ) + item_class_plural_name_lc = item_class_plural_name.lower() + + # Get item name. + item_name = get_item_name(item) + %> + +

+
Share ${item_class_name} '${item_name}' with Another User
+
+
+
+ +
+ +
+
+
+
+ +
+ + +
+
+
+ + \ No newline at end of file diff --git a/templates/share_base.mako b/templates/share_base.mako deleted file mode 100644 index fe2174705b3..00000000000 --- a/templates/share_base.mako +++ /dev/null @@ -1,36 +0,0 @@ -<%inherit file="/base.mako"/> - -%if message: -<% -if messagetype is UNDEFINED: - mt = "done" -else: - mt = messagetype -%> -

-

- ${message} -
-

-%endif - -

-
Share page '${item.title}'
-
-
-
- -
- -
-
-
-
- -
-
-
-
- \ No newline at end of file diff --git a/templates/sharing_base.mako b/templates/sharing_base.mako index 28e708e629e..5f558b2c25d 100644 --- a/templates/sharing_base.mako +++ b/templates/sharing_base.mako @@ -1,16 +1,39 @@ ## -## Base template for sharing an item. Template expects the following parameters: +## Base template for sharing/publishing/exporting an item. Template expects the following parameters: ## (a) item - item to be shared. ## - -<%inherit file="/base.mako"/> +<%! + def inherit(context): + if context.get('use_panels', False) == True: + if context.get('webapp'): + webapp = context.get('webapp') + else: + webapp = 'galaxy' + return '/webapps/%s/base_panels.mako' % webapp + else: + return '/base.mako' +%> +<%inherit file="${inherit(context)}"/> <%namespace file="./display_common.mako" import="*" /> +<%namespace file="/message.mako" import="render_msg" /> ## ## Page methods. ## +<%def name="init()"> +<% + self.has_left_panel=False + self.has_right_panel=False + self.message_box_visible=False + self.overlay_visible=False + self.message_box_class="" + self.active_view="" + self.body_class="" +%> + + <%def name="title()"> Sharing and Publishing ${get_class_display_name( item.__class__ )} '${get_item_name( item )}' @@ -57,18 +80,38 @@ <%def name="stylesheets()"> ${parent.stylesheets()} +<%def name="center_panel()"> + ${self.body()} + + <%def name="body()"> + ## Set use_panels var for use in page's URLs. + <% use_panels = context.get('use_panels', False) %> + + ## Render message. + %if message: + ${render_msg( message, status )} + %endif + <% # # Setup and variables needed for page. @@ -79,8 +122,10 @@ item_class_name_lc = item_class_name.lower() item_class_plural_name = get_class_plural_display_name( item.__class__ ) item_class_plural_name_lc = item_class_plural_name.lower() + + # Get item name. + item_name = get_item_name(item) %> - <% item_name = get_item_name(item) %>

Sharing and Publishing ${item_class_name} '${item_name}'

@@ -103,7 +148,6 @@ %else: ## User has a public username, so private sharing and publishing options. -

Making ${item_class_name} Accessible via Link and Publishing It

@@ -174,8 +218,10 @@ %endif -
+ ## + ## Sharing with Galaxy users. + ##

Sharing ${item_class_name} with Specific Users

@@ -183,7 +229,7 @@

The following users will see this ${item_class_name_lc} in their ${item_class_name_lc} list and will be - able to run/view and import it. + able to view, import, and run it.

@@ -200,7 +246,7 @@ @@ -208,7 +254,8 @@

- + Share with another user @@ -216,7 +263,8 @@

You have not shared this ${item_class_name_lc} with any users.

- + Share with a user
diff --git a/templates/workflow/share.mako b/templates/workflow/share.mako deleted file mode 100644 index 3b7b4848c5a..00000000000 --- a/templates/workflow/share.mako +++ /dev/null @@ -1,36 +0,0 @@ -<%inherit file="/base.mako"/> - -%if message: -<% -if messagetype is UNDEFINED: - mt = "done" -else: - mt = messagetype -%> -

-

- ${message} -
-

-%endif - -

-
Share workflow '${stored.name}'
-
-
-
- -
- -
-
-
-
- -
-
-
-
-
\ No newline at end of file diff --git a/templates/workflow/sharing.mako b/templates/workflow/sharing.mako index b282d5ade8c..7aab75e0f9f 100644 --- a/templates/workflow/sharing.mako +++ b/templates/workflow/sharing.mako @@ -1,161 +1,13 @@ -<%inherit file="/base.mako"/> -<%! from galaxy import model %> +<%inherit file="/sharing_base.mako"/> -## -## Page methods. -## - -<%def name="title()"> - Sharing Workflow '${stored.name}' - - -<%def name="stylesheets()"> - ${parent.stylesheets()} - - - -## Get display name for a class. -<%def name="get_class_display_name( a_class )"> +<%def name="init()"> <% - if a_class is model.History: - return "History" - elif a_class is model.StoredWorkflow: - return "Workflow" - elif a_class is model.Page: - return "Page" + parent.init() + self.active_view="workflow" %> -## -## Page content. -## +<%def name="center_panel()"> + ${parent.body()} + -

Sharing Workflow '${stored.name}'

- -
-

Making Workflow Accessible via Link and Publishing It

- -
- %if stored.importable: - <% - item_status = "accessible via link" - if stored.published: - item_status = item_status + " and published" - %> - This workflow ${item_status}. -
-

Anyone can view and import this workflow by visiting the following URL: - <% url = h.url_for( action='display_by_username_and_slug', username=trans.get_user().username, slug=stored.slug, qualified=True ) %> -

- ${url} -
- - %if stored.published: - This workflow is publicly listed and searchable in Galaxy's Published Workflows section. - %endif -
- -

You can: -

-
- %if not stored.published: - ## Item is importable but not published. User can disable importable or publish. - -
Disables workflow's link so that it is not accessible.
-
- -
Publishes the workflow to Galaxy's Published Workflows section, where it is publicly listed and searchable.
- -
- %else: ## stored.published == True - ## Item is importable and published. User can unpublish or disable import and unpublish. - -
Removes workflow from Galaxy's Published Workflows section so that it is not publicly listed or searchable.
-
- -
Disables workflow's link so that it is not accessible and removes workflow from Galaxy's Published Workflows section so that it is not publicly listed or searchable.
- %endif - -
-
- - %else: - - This workflow is currently restricted so that only you and the users listed below can access it. You can: -

-

- -
Generates a web link that you can share with other people so that they can view and import the workflow.
- -
- -
Makes the workflow accessible via link (see above) and publishes the workflow to Galaxy's Published Workflows section, where it is publicly listed and searchable.
-
- - %endif -
- -

Sharing Workflow with Specific Users

- -
- %if stored.users_shared_with: - -

- The following users will see this workflow in their workflow list and will be - able to run/view and import it. -

- - - - - - - - - %for i, association in enumerate( stored.users_shared_with ): - <% user = association.user %> - - - - - %endfor -
Email
- ${user.email} - - -
- Unshare -
-
- - %else: - -

You have not shared this workflow with any users.

- - - Share with another user - -
- - %endif -
-
- -



-Back to Workflows List \ No newline at end of file