Exemple #1
0
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')))
Exemple #2
0
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', ))
Exemple #3
0
    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}
Exemple #4
0
    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
Exemple #5
0
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)))
Exemple #6
0
    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)
Exemple #7
0
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'))
Exemple #8
0
    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)
Exemple #9
0
def seeinv_processsecurity_validation(process, context):
    organization = context.organization
    return (organization and \
            has_role(role=('OrganizationResponsible',
                           organization))) or \
            has_any_roles(roles=('Moderator',
                                'Anonymous'))
Exemple #10
0
    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 {}
Exemple #11
0
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
Exemple #13
0
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
Exemple #15
0
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',))
Exemple #16
0
def seeinv_processsecurity_validation(process, context):
    organization = context.organization
    return (organization and \
            has_role(role=('OrganizationResponsible',
                           organization))) or \
            has_any_roles(roles=('Moderator',
                                'Anonymous'))
Exemple #17
0
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')))
Exemple #18
0
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))
Exemple #19
0
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')))
Exemple #20
0
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')))
Exemple #21
0
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()
Exemple #22
0
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()
Exemple #23
0
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.'}
Exemple #25
0
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)
Exemple #26
0
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'))
Exemple #27
0
    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.'}
Exemple #29
0
    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)
Exemple #30
0
    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.')
Exemple #32
0
    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 {}
Exemple #33
0
    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
Exemple #34
0
def cont_roles_validation(process, context):
    site = get_site_folder(True)
    return has_any_roles(roles=(('PortalManager', site), ('Owner', context)))
Exemple #35
0
def addapplication_roles_validation(process, context):
    site = get_site_folder(True)
    return has_any_roles(roles=('SiteAdmin', 'Admin'), root=site)
Exemple #36
0
def see_processsecurity_validation(process, context):
    site = get_site_folder(True)
    return has_any_roles(roles=('SiteAdmin', 'Admin'), root=site)
Exemple #37
0
def siteadmin_roles_validation(process, context):
    return has_any_roles(roles=('SiteAdmin', ))
Exemple #38
0
def validate_roles_validation(process, context):
    return has_any_roles(roles=(('Owner', context), 'Moderator'))
Exemple #39
0
def edit_roles_validation(process, context):
    site = get_site_folder(True)
    return has_any_roles(roles=(('Owner', context), ('SiteAdmin', site), ('Moderator', site)))
Exemple #40
0
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))))
Exemple #41
0
def see_all_roles_validation(process, context):
    return has_any_roles(roles=('SiteAdmin', ))
Exemple #42
0
def unsubscribe_roles_validation(process, context):
    return has_any_roles(roles=('SiteAdmin', ))
Exemple #43
0
def userunsubscribe_roles_validation(process, context):
    return has_any_roles(roles=('Anonymous', 'Member'))
Exemple #44
0
def seeregs_processsecurity_validation(process, context):
    return has_any_roles(roles=('SiteAdmin', 'OrganizationResponsible')) and \
           global_user_processsecurity()
Exemple #45
0
def add_roles_validation(process, context):
    site = get_site_folder(True)
    return has_any_roles(
        roles=(('SiteAdmin', site), ('Owner', context), 'Admin'))
Exemple #46
0
def seealldup_roles_validation(process, context):
    site = get_site_folder(True)
    return has_any_roles(roles=(('Moderator', site), ('SiteAdmin', site),
                                'Admin'))
Exemple #47
0
def del_roles_validation(process, context):
    return has_any_roles(roles=('Moderator', ))
Exemple #48
0
def add_state_validation(process, context):
    site = get_site_folder(True)
    return 'editable' in context.state or \
           has_any_roles(roles=(('SiteAdmin', site), 'Admin'))
Exemple #49
0
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')))
Exemple #50
0
def login_roles_validation(process, context):
    return has_any_roles(roles=('Anonymous', 'Collaborator'))
Exemple #51
0
def login_roles_validation(process, context):
    return has_any_roles(roles=('Anonymous', 'Collaborator'))
Exemple #52
0
def participate_roles_validation(process, context):
    return has_any_roles(roles=('Anonymous', 'Member'))
Exemple #53
0
def archive_roles_validation(process, context):
    site = get_site_folder(True)
    return has_any_roles(roles=('Admin', ('SiteAdmin', site))) or\
           is_site_moderator()
Exemple #54
0
def seerep_roles_validation(process, context):
    return has_any_roles(roles=('Moderator', ('LocalModerator', context)))
Exemple #55
0
def edit_roles_validation(process, context):
    return has_any_roles(roles=(('Owner', context), 'SiteAdmin'))