def seefile_processsecurity_validation(process, context): application_files = [f.get('name') for f in DEFAULT_FILES] is_application_file = context.__name__ in application_files return (is_application_file or \ access_user_processsecurity(process, context)) and \ ('published' in context.state or \ has_any_roles(roles=(('Owner', context), 'Moderator')))
def remind_roles_validation(process, context): organization = getattr(context, 'organization', None) if organization: return has_any_roles(roles=('SiteAdmin', ('OrganizationResponsible', organization))) return has_role(role=('SiteAdmin', ))
def breadcrumbs(self): request = self.request context = self.context breadcrumbs = [] for resource in lineage(context): if has_any_roles(roles=('Anonymous',), ignore_superiors=True): return {'breadcrumbs':[]} if isinstance(resource, Entity): url = request.resource_url(resource, '@@index') else: url = request.resource_url(resource) name = getattr(resource, 'title', None) if name is None: name = resource.__name__ or 'Home' icon = request.registry.content.metadata(resource, 'icon') content_type = request.registry.content.typeof(resource) active = resource is request.context and 'active' or None bcinfo = { 'url':url, 'name':name, 'active':active, 'icon':icon, 'content_type':content_type, } breadcrumbs.insert(0, bcinfo) if resource is request.virtual_root: break return {'breadcrumbs':breadcrumbs}
def update(self): self.execute(None) try: navbars = generate_navbars(self, self.context, self.request) except ObjectRemovedException: return HTTPFound(self.request.resource_url(getSite(), '')) result = {} user = get_current() site = get_site_folder(True) add_participants_view = False if not any(s in ('editable', 'rejected', 'submitted', 'prepublished') for s in self.context.state): add_participants_view = has_any_roles(roles=(('GameResponsible', site), 'Admin')) values = { 'object': self.context, 'state': get_states_mapping( user, self.context, getattr(self.context, 'state_or_none', [None])[0]), 'navbar_body': navbars['navbar_body'], 'add_participants_view': add_participants_view } body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) item['messages'] = navbars['messages'] item['isactive'] = navbars['isactive'] result.update(navbars['resources']) result['coordinates'] = {self.coordinates: [item]} return result
def seewebadvertising_processsecurity_validation(process, context): site = get_site_folder(True) return 'published' in context.state or \ has_any_roles( roles=(('Owner', context), ('SiteAdmin', site), ('Moderator', site)))
def bind(self): bindings = {} bindings['navbars'] = None bindings['vote_actions'] = None vote_actions = get_vote_actions_body( self.context, self.request) try: navbars = generate_navbars( self.request, self.context, text_action=vote_actions['activators']) bindings['navbars'] = navbars bindings['vote_actions'] = vote_actions except ObjectRemovedException: return bindings['user'] = get_current() bindings['root'] = getSite() bindings['is_participant'] = has_role( user=bindings['user'], role=('Participant', self.context)) bindings['is_censored'] = 'censored' in self.context.state bindings['to_hide'] = bindings['is_censored'] and not has_any_roles( user=bindings['user'], roles=(('Participant', self.context), 'Moderator')) bindings['corrections'] = [c for c in self.context.corrections if 'in process' in c.state] bindings['enable_corrections'] = self._enable_corrections( bindings['is_participant'], bindings['corrections']) bindings['content_data'] = self._get_adapted_text( bindings['user'], bindings['is_participant'], bindings['corrections'], bindings['enable_corrections']) setattr(self, '_bindings', bindings)
def remove_roles_validation(process, context): site = get_site_folder(True) return ('editable' in context.state and \ has_role(role=('Owner', context))) or \ is_site_moderator() or\ has_any_roles(roles=(('SiteAdmin', site), 'Admin'))
def bind(self): bindings = {} bindings['navbars'] = None bindings['vote_actions'] = None vote_actions = get_vote_actions_body(self.context, self.request) try: navbars = generate_navbars(self.request, self.context, text_action=vote_actions['activators']) bindings['navbars'] = navbars bindings['vote_actions'] = vote_actions except ObjectRemovedException: return bindings['user'] = get_current() bindings['root'] = getSite() bindings['is_participant'] = has_role(user=bindings['user'], role=('Participant', self.context)) bindings['is_censored'] = 'censored' in self.context.state bindings['to_hide'] = bindings['is_censored'] and not has_any_roles( user=bindings['user'], roles=(('Participant', self.context), 'Moderator')) bindings['corrections'] = [ c for c in self.context.corrections if 'in process' in c.state ] bindings['enable_corrections'] = self._enable_corrections( bindings['is_participant'], bindings['corrections']) bindings['content_data'] = self._get_adapted_text( bindings['user'], bindings['is_participant'], bindings['corrections'], bindings['enable_corrections']) setattr(self, '_bindings', bindings)
def seeinv_processsecurity_validation(process, context): organization = context.organization return (organization and \ has_role(role=('OrganizationResponsible', organization))) or \ has_any_roles(roles=('Moderator', 'Anonymous'))
def start(self, context, request, appstruct, **kw): site = get_site_folder(True, request) user = get_current(request) is_manager = has_any_roles( user=user, roles=('Admin', ('SiteAdmin', site))) or\ is_site_moderator(request) if is_manager or all(has_role(user=user, role=('Owner', v)) for v in appstruct['targets'] if 'published' not in v.state): root = getSite() source = appstruct['source'] targets = appstruct['targets'] for artist in targets: replaced = artist.replace_by(source) if replaced: request.registry.notify(ObjectReplaced( old_object=artist, new_object=source )) root.delfromproperty('artists', artist) else: return {'error': True} return {}
def remove_roles_validation(process, context): site = get_site_folder(True) return ('editable' in context.state and \ has_role(role=('Owner', context))) or \ has_any_roles(roles=(('SiteAdmin', site), 'Admin')) or\ is_site_moderator()
def update(self): result = {} site = get_site_folder(True, self.request) user = get_current(self.request) is_manager = has_any_roles( user=user, roles=('Admin', ('SiteAdmin', site))) or\ is_site_moderator(self.request) duplicates = find_duplicates_artist(self.context, self.duplicates_state) diff_bodies = {} context_view = self.content( args={'object': self.context}, template=self.context.templates.get('diff', None))['body'] for duplicate in duplicates: duplicate_view = self.content( args={'object': duplicate}, template=duplicate.templates.get('diff', None))['body'] soupt, textdiff = html_diff_wrapper.render_html_diff( context_view, duplicate_view) diff_bodies[duplicate] = (textdiff, get_oid(duplicate)) values = {'context': self.context, 'oid': get_oid(self.context), 'context_view': context_view, 'contents': diff_bodies, 'row_len': math.ceil(len(diff_bodies)/2), 'is_manager': is_manager, 'view': self} body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) result['coordinates'] = {self.coordinates: [item]} return result
def seevenue_processsecurity_validation(process, context): site = get_site_folder(True) return 'published' in context.state or \ has_any_roles(roles=(('Owner', context), ('SiteAdmin', site), ('Moderator', site), 'Admin'))
def update(self): self.execute(None) root = getSite() try: navbars = generate_navbars( self.request, self.context) except ObjectRemovedException: return HTTPFound(self.request.resource_url(root, '')) user = self.get_binding('user') is_censored = 'censored' in self.context.state to_hide = is_censored and not has_any_roles( user=user, roles=(('Owner', self.context), 'Moderator')) evaluation_chart = render_object_evaluation_stat(self.context, self.request) examination_chart = render_object_examination_stat(self.context, self.request) result = {} values = { 'challenge': self.context, 'to_hide': to_hide, 'is_censored': is_censored, 'text': self.context.text, 'current_user': user, 'navbar_body': navbars['navbar_body'], 'footer_body': navbars['footer_body'], 'evaluation_chart': evaluation_chart, 'examination_chart': examination_chart } body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) item['isactive'] = True result['coordinates'] = {self.coordinates: [item]} # result.update(resources) return result
def remind_roles_validation(process, context): organization = getattr(context, 'organization', None) if organization: return has_any_roles( roles=('SiteAdmin', ('OrganizationResponsible', organization))) return has_role(role=('SiteAdmin',))
def seeinv_processsecurity_validation(process, context): organization = context.organization return (organization and \ has_role(role=('OrganizationResponsible', organization))) or \ has_any_roles(roles=('Moderator', 'Anonymous'))
def seefile_processsecurity_validation(process, context): application_files = [f.get('name') for f in DEFAULT_FILES] is_application_file = context.__name__ in application_files return (is_application_file or \ access_user_processsecurity(process, context)) and \ ('published' in context.state or \ has_any_roles(roles=(('Owner', context), 'Moderator')))
def add_processsecurity_validation(process, context): services = context.get_all_services( kinds=['promotionservice'], validate=True, delegation=True) site = get_site_folder(True) return has_any_roles(roles=(('SiteAdmin', site), 'Admin')) or\ (services and global_user_processsecurity(process, context))
def seechallenge_processsecurity_validation(process, context): is_restricted = getattr(context, 'is_restricted', False) can_access = True if is_restricted: can_access = has_role(role=('ChallengeParticipant', context)) return can_access and access_user_processsecurity(process, context) and \ ('published' in context.state or 'censored' in context.state or has_any_roles(roles=(('Owner', context), 'Moderator')))
def seequestion_processsecurity_validation(process, context): challenge = getattr(context, 'challenge', None) is_restricted = getattr(challenge, 'is_restricted', False) can_access = True if is_restricted: can_access = has_role(role=('ChallengeParticipant', challenge)) return can_access and access_user_processsecurity(process, context) and \ ('published' in context.state or 'censored' in context.state or\ has_any_roles(roles=(('Owner', context), 'Moderator')))
def seereg_processsecurity_validation(process, context): has_role_cond = False organization = getattr(context, 'organization', None) if organization: has_role_cond = has_any_roles( roles=('SiteAdmin', ('OrganizationResponsible', context))) else: has_role_cond = has_role(role=('SiteAdmin',)) return has_role_cond and \ global_user_processsecurity()
def seereg_processsecurity_validation(process, context): has_role_cond = False organization = getattr(context, 'organization', None) if organization: has_role_cond = has_any_roles(roles=('SiteAdmin', ('OrganizationResponsible', context))) else: has_role_cond = has_role(role=('SiteAdmin', )) return has_role_cond and \ global_user_processsecurity()
def seecomment_processsecurity_validation(process, context): if 'published' in context.state: user = get_current() subject = context.channel.get_subject(user) channel = subject.get_channel(user) if channel is not context.channel: return False see_action = VALIDATOR_BY_CONTEXT.get(subject.__class__, {}).get('see', None) return see_action.processsecurity_validation( process, subject) if see_action else True else: return has_any_roles(roles=(('Owner', context), 'Moderator'))
def delete(self): user = get_current() path = self.params('path') file_ = None if path is not None: #file_ = traversal.traverse(self.context, path).get('context', None) file_ = get_file(path) if file_ and has_any_roles(user=user, roles=(('Owner', file_), 'Admin')): root = file_.__parent__ root.delfromproperty('files', file_) return {'Path': self.request.resource_url(root, ''), 'Code': 0} return {'Error': 'There was an error renaming the file.'}
def keyword_widget(node, kw): request = node.bindings['request'] site = request.get_site_folder can_create = 0 if has_role(role=('Member', )): can_create = 1 if has_any_roles(roles=('Admin', ('SiteAdmin', site))): can_create = 0 levels = site.get_tree_nodes_by_level() return KeywordsTreeWidget( min_len=2, max_len=DEFAULT_TREE_LEN, can_create=can_create, levels=levels)
def seecomment_processsecurity_validation(process, context): if 'published' in context.state: user = get_current() subject = context.channel.get_subject(user) channel = subject.get_channel(user) if channel is not context.channel: return False see_action = VALIDATOR_BY_CONTEXT.get( subject.__class__, {}).get('see', None) return see_action.processsecurity_validation( process, subject) if see_action else True else: return has_any_roles( roles=(('Owner', context), 'Moderator'))
def bind(self): bindings = {} bindings['navbars'] = None try: navbars = generate_navbars(self.request, self.context) bindings['navbars'] = navbars except ObjectRemovedException: return bindings['user'] = get_current() bindings['root'] = getSite() bindings['is_censored'] = 'censored' in self.context.state bindings['to_hide'] = bindings['is_censored'] and not has_any_roles( user=bindings['user'], roles=(('Owner', self.context), 'Moderator')) setattr(self, '_bindings', bindings)
def delete(self): user = get_current() path = self.params('path') file_ = None if path is not None: #file_ = traversal.traverse(self.context, path).get('context', None) file_ = get_file(path) if file_ and has_any_roles( user=user, roles=(('Owner', file_), 'Admin')): root = file_.__parent__ root.delfromproperty('files', file_) return {'Path': self.request.resource_url(root, ''), 'Code': 0} return {'Error': 'There was an error renaming the file.'}
def bind(self): bindings = {} bindings['navbars'] = None try: navbars = generate_navbars( self.request, self.context) bindings['navbars'] = navbars except ObjectRemovedException: return bindings['user'] = get_current() bindings['root'] = getSite() bindings['is_censored'] = 'censored' in self.context.state bindings['to_hide'] = bindings['is_censored'] and not has_any_roles( user=bindings['user'], roles=(('Owner', self.context), 'Moderator')) setattr(self, '_bindings', bindings)
def before_update(self): site = get_site_folder(True) is_moderator = has_any_roles(roles=(('Moderator', site), ('SiteAdmin', site), 'Admin')) services = self.context.get_all_services(kinds=['sellingtickets'], delegation=False) if 'sellingtickets' not in services and not is_moderator: self.schema = omit( self.schema, ['selling_tickets', ('schedules', ['ticketing_url'])]) services = site.get_all_services(kinds=['extractionservice'], delegation=False) if 'extractionservice' in services: self.schema.get('description').description = _( 'Describe succinctly the event.' ' Only this part of the description will ' 'be included in the paper version of the magazine.')
def before_update(self): site = get_site_folder(True) is_moderator = has_any_roles( roles=(('Moderator', site), ('SiteAdmin', site), 'Admin')) services = self.context.get_all_services( kinds=['sellingtickets'], delegation=False) if 'sellingtickets' not in services and not is_moderator: self.schema = omit( self.schema, ['selling_tickets', ('schedules', ['ticketing_url'])]) services = site.get_all_services( kinds=['extractionservice'], delegation=False) if 'extractionservice' in services: self.schema.get('description').description = _( 'Describe succinctly the event.' ' Only this part of the description will ' 'be included in the paper version of the magazine.')
def start(self, context, request, appstruct, **kw): site = get_site_folder(True, request) user = get_current(request) is_manager = has_any_roles( user=user, roles=('Admin', ('SiteAdmin', site))) or\ is_site_moderator(request) if is_manager or all( has_role(user=user, role=('Owner', v)) for v in appstruct['targets'] if 'published' not in v.state): root = getSite() source = appstruct['source'] targets = appstruct['targets'] for venue in targets: replaced = venue.replace_by(source) if replaced: request.registry.notify( ObjectReplaced(old_object=venue, new_object=source)) root.delfromproperty('venues', venue) else: return {'error': True} return {}
def update(self): result = {} site = get_site_folder(True, self.request) user = get_current(self.request) is_manager = has_any_roles( user=user, roles=('Admin', ('SiteAdmin', site))) or\ is_site_moderator(self.request) duplicates = find_duplicates_artist(self.context, self.duplicates_state) diff_bodies = {} context_view = self.content(args={'object': self.context}, template=self.context.templates.get( 'diff', None))['body'] for duplicate in duplicates: duplicate_view = self.content(args={'object': duplicate}, template=duplicate.templates.get( 'diff', None))['body'] soupt, textdiff = html_diff_wrapper.render_html_diff( context_view, duplicate_view) diff_bodies[duplicate] = (textdiff, get_oid(duplicate)) values = { 'context': self.context, 'oid': get_oid(self.context), 'context_view': context_view, 'contents': diff_bodies, 'row_len': math.ceil(len(diff_bodies) / 2), 'is_manager': is_manager, 'view': self } body = self.content(args=values, template=self.template)['body'] item = self.adapt_item(body, self.viewid) result['coordinates'] = {self.coordinates: [item]} return result
def cont_roles_validation(process, context): site = get_site_folder(True) return has_any_roles(roles=(('PortalManager', site), ('Owner', context)))
def addapplication_roles_validation(process, context): site = get_site_folder(True) return has_any_roles(roles=('SiteAdmin', 'Admin'), root=site)
def see_processsecurity_validation(process, context): site = get_site_folder(True) return has_any_roles(roles=('SiteAdmin', 'Admin'), root=site)
def siteadmin_roles_validation(process, context): return has_any_roles(roles=('SiteAdmin', ))
def validate_roles_validation(process, context): return has_any_roles(roles=(('Owner', context), 'Moderator'))
def edit_roles_validation(process, context): site = get_site_folder(True) return has_any_roles(roles=(('Owner', context), ('SiteAdmin', site), ('Moderator', site)))
def seegame_processsecurity_validation(process, context): site = get_site_folder(True) return ('published' in context.state or \ has_any_roles(roles=(('Owner', context), ('GameResponsible', site))))
def see_all_roles_validation(process, context): return has_any_roles(roles=('SiteAdmin', ))
def unsubscribe_roles_validation(process, context): return has_any_roles(roles=('SiteAdmin', ))
def userunsubscribe_roles_validation(process, context): return has_any_roles(roles=('Anonymous', 'Member'))
def seeregs_processsecurity_validation(process, context): return has_any_roles(roles=('SiteAdmin', 'OrganizationResponsible')) and \ global_user_processsecurity()
def add_roles_validation(process, context): site = get_site_folder(True) return has_any_roles( roles=(('SiteAdmin', site), ('Owner', context), 'Admin'))
def seealldup_roles_validation(process, context): site = get_site_folder(True) return has_any_roles(roles=(('Moderator', site), ('SiteAdmin', site), 'Admin'))
def del_roles_validation(process, context): return has_any_roles(roles=('Moderator', ))
def add_state_validation(process, context): site = get_site_folder(True) return 'editable' in context.state or \ has_any_roles(roles=(('SiteAdmin', site), 'Admin'))
def seeanswer_processsecurity_validation(process, context): return access_user_processsecurity(process, context) and \ ('published' in context.state or 'censored' in context.state or\ has_any_roles(roles=(('Owner', context), 'Moderator')))
def login_roles_validation(process, context): return has_any_roles(roles=('Anonymous', 'Collaborator'))
def login_roles_validation(process, context): return has_any_roles(roles=('Anonymous', 'Collaborator'))
def participate_roles_validation(process, context): return has_any_roles(roles=('Anonymous', 'Member'))
def archive_roles_validation(process, context): site = get_site_folder(True) return has_any_roles(roles=('Admin', ('SiteAdmin', site))) or\ is_site_moderator()
def seerep_roles_validation(process, context): return has_any_roles(roles=('Moderator', ('LocalModerator', context)))
def edit_roles_validation(process, context): return has_any_roles(roles=(('Owner', context), 'SiteAdmin'))