Merge pull request #4711 from guerler/replace_history_permission_form

Removes the history permissions form mako
This commit is contained in:
John Chilton
2017-09-29 12:44:26 -04:00
committed by GitHub
9 changed files with 64 additions and 58 deletions
+5
View File
@@ -53,6 +53,7 @@ window.app = function app( options, bootstrapped ){
'(/)visualizations/(:action_id)' : 'show_visualizations',
'(/)workflows/list_published(/)' : 'show_workflows_published',
'(/)histories(/)rename(/)' : 'show_histories_rename',
'(/)histories(/)permissions(/)' : 'show_histories_permissions',
'(/)histories(/)(:action_id)' : 'show_histories',
'(/)datasets(/)list(/)' : 'show_datasets',
'(/)workflow/import_workflow' : 'show_import_workflow',
@@ -108,6 +109,10 @@ window.app = function app( options, bootstrapped ){
this.page.display( new FormWrapper.View ( { url : 'history/rename?id=' + QueryStringParsing.get( 'id' ), redirect: 'histories/list' } ) );
},
show_histories_permissions : function() {
this.page.display( new FormWrapper.View ( { url : 'history/permissions?id=' + QueryStringParsing.get( 'id' ), redirect: 'histories/list' } ) );
},
show_datasets : function() {
this.page.display( new GridView( { url_base: Galaxy.root + 'dataset/list', dict_format: true } ) );
},
@@ -93,7 +93,11 @@ var menu = [
},
{
html : _l( 'Dataset Security' ),
href : 'root/history_set_default_permissions',
func : function() {
if ( Galaxy && Galaxy.currHistoryPanel && Galaxy.router ) {
Galaxy.router.push( '/histories/permissions?id=' + Galaxy.currHistoryPanel.model.id );
}
}
},
{
html : _l( 'Resume Paused Jobs' ),
@@ -106,7 +110,7 @@ var menu = [
if( Galaxy && Galaxy.currHistoryPanel ){
Galaxy.currHistoryPanel.collapseAll();
}
},
}
},
{
html : _l( 'Unhide Hidden Datasets' ),
+1
View File
@@ -127,6 +127,7 @@ def paste_app_factory(global_conf, **kwargs):
webapp.add_client_route('/histories/list_published')
webapp.add_client_route('/histories/list_shared')
webapp.add_client_route('/histories/rename')
webapp.add_client_route('/histories/permissions')
webapp.add_client_route('/datasets/list')
webapp.add_client_route('/datasets/edit')
webapp.add_client_route('/datasets/error')
@@ -1,4 +1,5 @@
import logging
import sets
import urllib
from markupsafe import escape
@@ -108,6 +109,7 @@ class HistoryListGrid(grids.Grid):
grids.GridOperation("Switch", allow_multiple=False, condition=(lambda item: not item.deleted), async_compatible=True),
grids.GridOperation("View", allow_multiple=False, url_args=dict(action='view')),
grids.GridOperation("Share or Publish", allow_multiple=False, condition=(lambda item: not item.deleted), url_args=dict(action='sharing')),
grids.GridOperation("Change Permissions", allow_multiple=False, condition=(lambda item: not item.deleted), url_args=dict(controller="", action="histories/permissions")),
grids.GridOperation("Copy", allow_multiple=False, condition=(lambda item: not item.deleted), async_compatible=False),
grids.GridOperation("Rename", condition=(lambda item: not item.deleted), url_args=dict(controller="", action="histories/rename"), target="top"),
grids.GridOperation("Delete", condition=(lambda item: not item.deleted), async_compatible=True),
@@ -734,6 +736,45 @@ class HistoryController(BaseUIController, SharableMixin, UsesAnnotations, UsesIt
return trans.fill_template("/sharing_base.mako", controller_list='histories', item=history, use_panels=True)
@web.expose_api
@web.require_login("changing default permissions")
def permissions(self, trans, payload=None, **kwd):
"""
Sets the permissions on a history.
"""
history_id = kwd.get('id')
if not history_id:
return self.message_exception(trans, 'Invalid history id (%s) received' % str(history_id))
history = self.history_manager.get_owned(self.decode_id(history_id), trans.user, current_history=trans.history)
if trans.request.method == 'GET':
inputs = []
all_roles = trans.user.all_roles()
current_actions = history.default_permissions
permitted_actions = trans.app.model.Dataset.permitted_actions.items()
for action_key, action in permitted_actions:
in_roles = sets.Set()
for a in current_actions:
if a.action == action.action:
in_roles.add(a.role)
inputs.append({'type' : 'select',
'multiple' : True,
'optional' : True,
'individual': True,
'name' : action_key,
'label' : action.action,
'help' : action.description,
'options' : [(role.name, trans.security.encode_id(role.id)) for role in set(all_roles)],
'value' : [trans.security.encode_id(role.id) for role in in_roles]})
return {'title' : 'Change default dataset permissions for history \'%s\'' % history.name, 'inputs' : inputs}
else:
permissions = {}
for action_key, action in trans.app.model.Dataset.permitted_actions.items():
in_roles = payload.get(action_key) or []
in_roles = [trans.sa_session.query(trans.app.model.Role).get(trans.security.decode_id(x)) for x in in_roles]
permissions[trans.app.security_agent.get_action(action.action)] = in_roles
trans.app.security_agent.history_set_default_permissions(history, permissions)
return {'message': 'Default history \'%s\' dataset permissions have been changed.' % history.name}
@web.expose
@web.require_login("share histories with other users")
def share(self, trans, id=None, email="", **kwd):
+1 -37
View File
@@ -11,7 +11,7 @@ from paste.httpexceptions import HTTPNotFound, HTTPBadGateway
from galaxy import web
from galaxy import util
from galaxy.util import listify, Params, string_as_bool, FILENAME_VALID_CHARS
from galaxy.util import listify, string_as_bool, FILENAME_VALID_CHARS
from galaxy.web.base import controller
from galaxy.model.item_attrs import UsesAnnotations
@@ -409,42 +409,6 @@ class RootController(controller.JSAppLauncher, UsesAnnotations):
trans.log_event(msg)
return trans.show_error_message("Adding File to History has Failed")
@web.expose
def history_set_default_permissions(self, trans, id=None, **kwd):
"""Sets the permissions on a history.
"""
# TODO: unencoded id
if trans.user:
if 'update_roles_button' in kwd:
history = None
if id:
try:
id = int(id)
except:
id = None
if id:
history = trans.sa_session.query(trans.app.model.History).get(id)
if not history:
# If we haven't retrieved a history, use the current one
history = trans.get_history()
p = Params(kwd)
permissions = {}
for k, v in trans.app.model.Dataset.permitted_actions.items():
in_roles = p.get(k + '_in', [])
if not isinstance(in_roles, list):
in_roles = [in_roles]
in_roles = [trans.sa_session.query(trans.app.model.Role).get(x) for x in in_roles]
permissions[trans.app.security_agent.get_action(v.action)] = in_roles
dataset = 'dataset' in kwd
bypass_manage_permission = 'bypass_manage_permission' in kwd
trans.app.security_agent.history_set_default_permissions(history, permissions,
dataset=dataset, bypass_manage_permission=bypass_manage_permission)
return trans.show_ok_message('Default history permissions have been changed.')
return trans.fill_template('history/permissions.mako')
else:
# user not logged in, history group must be only public
return trans.show_error_message("You must be logged in to change a history's default permissions.")
@web.expose
def dataset_make_primary(self, trans, id=None):
"""Copies a dataset and makes primary.
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -1,9 +0,0 @@
<%inherit file="/base.mako"/>
<%def name="title()">Change Default Permissions on New Datasets in This History</%def>
<%namespace file="/dataset/security_common.mako" import="render_permission_form" />
%if trans.user:
<% history = trans.get_history() %>
${render_permission_form( history, history.name,
h.url_for( controller='root', action='history_set_default_permissions' ), trans.user.all_roles() )}
%endif