def get_publishers(self): from ckan.model.group import Group if Authorizer().is_sysadmin(c.user): groups = Group.all(group_type='publisher') elif c.userobj: # need to get c.userobj again as it may be detached from the # session since the last time we called get_groups (it caches) c.userobj = model.User.by_name(c.user) groups = c.userobj.get_groups('publisher') else: # anonymous user shouldn't have access to this page anyway. groups = [] # Be explicit about which fields we make available in the template groups = [{ 'name': g.name, 'id': g.id, 'title': g.title, 'contact-name': g.extras.get('contact-name', ''), 'contact-email': g.extras.get('contact-email', ''), 'contact-phone': g.extras.get('contact-phone', ''), 'foi-name': g.extras.get('foi-name', ''), 'foi-email': g.extras.get('foi-email', ''), 'foi-phone': g.extras.get('foi-phone', ''), } for g in groups] return dict((g['name'], g) for g in groups)
def _setup_template_variables(self, context, data_dict=None, package_type=None): log.debug("_setup_template_variables") c.update_frequency = update_frequency c.categorization = categorization c.groups_authz = get_action('group_list_authz')(context, data_dict) data_dict.update({'available_only':True}) #c.groups_available = get_action('group_list_authz')(context, data_dict) c.groups_available = c.userobj and c.userobj.get_groups('organization') or [] c.licences = [('', '')] + model.Package.get_license_options() c.is_sysadmin = Authorizer().is_sysadmin(c.user) if c.is_sysadmin: c.groups_available = Group.all('organization') log.fatal("is_sysadmin: %s" % c.is_sysadmin) log.fatal("groups: %s" % c.groups_available) ## This is messy as auths take domain object not data_dict context_pkg = context.get('package',None) pkg = context_pkg or c.pkg if pkg: try: if not context_pkg: context['package'] = pkg check_access('package_change_state',context) c.auth_for_change_state = True except NotAuthorized: c.auth_for_change_state = False
def _setup_template_variables(self, context, data_dict=None, package_type=None): log.debug("_setup_template_variables") c.update_frequency = update_frequency c.categorization = categorization c.groups_authz = get_action('group_list_authz')(context, data_dict) data_dict.update({'available_only': True}) #c.groups_available = get_action('group_list_authz')(context, data_dict) c.groups_available = c.userobj and c.userobj.get_groups( 'organization') or [] c.licences = [('', '')] + model.Package.get_license_options() c.is_sysadmin = Authorizer().is_sysadmin(c.user) if c.is_sysadmin: c.groups_available = Group.all('organization') log.fatal("is_sysadmin: %s" % c.is_sysadmin) log.fatal("groups: %s" % c.groups_available) ## This is messy as auths take domain object not data_dict context_pkg = context.get('package', None) pkg = context_pkg or c.pkg if pkg: try: if not context_pkg: context['package'] = pkg check_access('package_change_state', context) c.auth_for_change_state = True except NotAuthorized: c.auth_for_change_state = False
def get_publishers(self): from ckan.model.group import Group if Authorizer().is_sysadmin(c.user): groups = Group.all(group_type='publisher') elif c.userobj: # need to get c.userobj again as it may be detached from the # session since the last time we called get_groups (it caches) c.userobj = model.User.by_name(c.user) groups = c.userobj.get_groups('publisher') else: # anonymous user shouldn't have access to this page anyway. groups = [] # Be explicit about which fields we make available in the template groups = [ { 'name': g.name, 'id': g.id, 'title': g.title, 'contact-name': g.extras.get('contact-name', ''), 'contact-email': g.extras.get('contact-email', ''), 'contact-phone': g.extras.get('contact-phone', ''), 'foi-name': g.extras.get('foi-name', ''), 'foi-email': g.extras.get('foi-email', ''), 'foi-phone': g.extras.get('foi-phone', ''), } for g in groups ] return dict( (g['name'], g) for g in groups )
def _get_publishers(self): groups = None if ckan.new_authz.is_sysadmin(c.user): groups = Group.all(group_type='organization') elif c.userobj: groups = c.userobj.get_groups('organization') else: # anonymous user shouldn't have access to this page anyway. groups = [] # Be explicit about which fields we make available in the template groups = [ { 'name': g.name, 'id': g.id, 'title': g.title, } for g in groups ] return groups
def _get_publishers(self): groups = None if ckan.new_authz.is_sysadmin(c.user): groups = Group.all(group_type='organization') elif c.userobj: groups = c.userobj.get_groups('organization') else: # anonymous user shouldn't have access to this page anyway. groups = [] # Be explicit about which fields we make available in the template groups = [{ 'name': g.name, 'id': g.id, 'title': g.title, } for g in groups] return groups
def get_publishers(self): from ckan.model.group import Group if Authorizer().is_sysadmin(c.user): groups = Group.all(group_type='publisher') elif c.userobj: # need to get c.userobj again as it may be detached from the # session since the last time we called get_groups (it caches) c.userobj = model.User.by_name(c.user) # For each group where the user is an admin, we should also include # all of the child publishers. admin_groups = set() for g in c.userobj.get_groups('publisher', 'admin'): for pub in publib.go_down_tree(g): admin_groups.add(pub) editor_groups = c.userobj.get_groups('publisher', 'editor') groups = list(admin_groups) + editor_groups else: # anonymous user shouldn't have access to this page anyway. groups = [] # Be explicit about which fields we make available in the template groups = [ { 'name': g.name, 'id': g.id, 'title': g.title, 'contact-name': g.extras.get('contact-name', ''), 'contact-email': g.extras.get('contact-email', ''), 'contact-phone': g.extras.get('contact-phone', ''), 'foi-name': g.extras.get('foi-name', ''), 'foi-email': g.extras.get('foi-email', ''), 'foi-phone': g.extras.get('foi-phone', ''), 'foi-web': g.extras.get('foi-name', ''), } for g in groups ] return dict( (g['name'], g) for g in groups )
def get_publishers(self): from ckan.model.group import Group if dgu_helpers.is_sysadmin(): groups = Group.all(group_type='organization') elif c.userobj: # need to get c.userobj again as it may be detached from the # session since the last time we called get_groups (it caches) c.userobj = model.User.by_name(c.user) # For each group where the user is an admin, we should also include # all of the child publishers. admin_groups = set() for g in c.userobj.get_groups('organization', 'admin'): for pub in publib.go_down_tree(g): admin_groups.add(pub) editor_groups = c.userobj.get_groups('organization', 'editor') groups = list(admin_groups) + editor_groups else: # anonymous user shouldn't have access to this page anyway. groups = [] # Be explicit about which fields we make available in the template groups = [{ 'name': g.name, 'id': g.id, 'title': g.title, 'contact-name': g.extras.get('contact-name', ''), 'contact-email': g.extras.get('contact-email', ''), 'contact-phone': g.extras.get('contact-phone', ''), 'foi-name': g.extras.get('foi-name', ''), 'foi-email': g.extras.get('foi-email', ''), 'foi-phone': g.extras.get('foi-phone', ''), 'foi-web': g.extras.get('foi-web', ''), } for g in groups] return dict((g['name'], g) for g in groups)