def customMenu(self, menu_items): """ """ # print user.get_roles(obj=self) if not "Reviewer" in user.get_roles(obj=self): return SimpleFolder.customMenu(self, menu_items) else: # print "Reviewer" dts = getAllowedDocumentTypesForGroup(self) filter = False if self.allowedPartnerDocTypes: # print self.allowedPartnerDocTypes filter = True res = [] for menu_item in menu_items: if menu_item.get('id') == 'DPDocument': for dt in dts: #print dt.id if not dt.getObject().globalAllow: # only generally allowed doctypes continue if not filter or dt.id in self.allowedPartnerDocTypes: res.append({'extra': {'separator': None, 'id': dt.id, 'class': 'contenttype-%s' % dt.id}, 'submenu': None, 'description': '', 'title': dt.Title, 'action': '%s/++add++DPDocument?form.widgets.docType:list=%s' % (self.absolute_url(), dt.id), 'selected': False, 'id': dt.id, 'icon': None}) else: res.append(menu_item) return res
def show_results(self): # check if user is owner/has permission to view all the poodle data # if stealth voting is disabled this will just return true if not self.context.stealth_voting: return True return 'Owner' in user.get_roles(user=user.get_current(), obj=self.context)
def _get_user_group(self, user): """ Returns the color according to the role of the user, EC or TL """ roles = get_roles(username=user, obj=self.context) if 'Editor' in roles: return 'dark' return 'light'
def get_current_user_roles(self, context=None): current_user = user.get_current().getId() params = {"username": current_user} if context: params['obj'] = context roles = get_roles(**params) return roles
def can_checkin(self): # user is Reviewer/Editor, state is submitted, context is wc local_roles = get_roles(obj=self.context, inherit=True) control = getMultiAdapter((self.context, self.request), name="iterate_control") if not hasattr(control, 'is_checkout'): return False is_wc = control.is_checkout() is_ready = get_state(self.context) == 'ready_for_checkin' can_checkin = bool(set(['Editor', 'Reviewer']). intersection(set(local_roles))) return is_wc and is_ready and can_checkin
def query_active_objects(query, portal_type, context=None): params = { 'portal_type': portal_type, 'sort_on': 'sortable_title', PKAN_STATE_NAME: ACTIVE_STATE, } query.update(params) catalog = api.portal.get_tool('portal_catalog') brains = list(catalog(query)) harvester = get_ancestor(context, CT_HARVESTER) if context and harvester: # add objects from the same harvest query['path'] = '/'.join(harvester.getPhysicalPath()) brains += list(catalog(query)) elif context: # add objects of the same user try: current = api.user.get_current() roles = api.user.get_roles(user=current, obj=context) except UserNotFoundError: return brains check_admin = PROVIDER_ADMIN_ROLE in roles check_editor = PROVIDER_DATA_EDITOR_ROLE in roles check_chief = PROVIDER_CHIEF_EDITOR_ROLE in roles if check_admin or check_editor or check_chief: # if the user is a data provider collect all deactivated objects # where he is a data provider, too. # for example used in vocabs for linked data query[PKAN_STATE_NAME] = DEACTIVE_STATE new_brains = catalog(query) for brain in new_brains: obj = brain.getObject() roles = get_roles(user=current, obj=obj) perm = PROVIDER_ADMIN_ROLE in roles perm = perm or PROVIDER_CHIEF_EDITOR_ROLE in roles perm = perm or PROVIDER_DATA_EDITOR_ROLE in roles if perm: brains.append(brain) return brains
def can_checkout(self): # user is Contributer, state is published, context is baseline and # doesn't have a checkout # if self.context.portal_type == 'Document': # import pdb; pdb.set_trace() local_roles = get_roles(obj=self.context, inherit=True) control = getMultiAdapter((self.context, self.request), name="iterate_control") # currently enable the viewlet only for mtr page if 'mtr/countries' not in self.context.absolute_url_path(): return False # this happens if the context is not registered for @@iterate_control # for example, content types we don't care about if not hasattr(control, 'is_checkout'): return False policy = ICheckinCheckoutPolicy(self.context, None) if policy is None: return False wc = policy.getWorkingCopy() is_baseline = not control.is_checkout() is_published = get_state(self.context) == 'published' # is_country_draft = get_state(self.context) == 'country_draft' is_contributor = 'Contributor' in local_roles has_wc = wc is not None correct_state = is_published # or is_country_draft return is_baseline \ and correct_state \ and is_contributor \ and (not has_wc)
def can_reset_token(self): """ Returns True if current logged in user can reset public token """ roles = set(['Editor', 'Manager']) here_roles = set(user.get_roles(obj=self)) return bool(roles.intersection(here_roles))
def available(self): local_roles = get_roles(obj=self.context, inherit=True) # hide Actions menu for Contributor return 'Contributor' not in local_roles
def is_contributor(self): local_roles = get_roles(obj=self.context, inherit=True) return 'Contributor' in local_roles