Example #1
0
    def add_permission(self):
        if ISiteRoot.providedBy(self.context):
            self.response['title'] = _(u"Add permission")
        post = self.request.POST
        if 'cancel' in post:
            url = resource_url(self.context, self.request)
            return HTTPFound(location=url)
        schema = createSchema('SinglePermissionSchema')
        add_csrf_token(self.context, self.request, schema)
        schema = schema.bind(context=self.context,
                             request=self.request,
                             api=self.api)
        form = Form(schema, buttons=(button_add, button_cancel))
        self.api.register_form_resources(form)
        if IMeeting.providedBy(self.context):
            self.response['tabs'] = self.api.render_single_view_component(
                self.context, self.request, 'tabs', 'manage_tickets')
        if 'add' in post:
            controls = post.items()
            try:
                appstruct = form.validate(controls)
            except ValidationFailure, e:
                self.response['form'] = e.render()
                return self.response

            #Set permissions
            self.context.set_groups(appstruct['userid'],
                                    appstruct['groups'],
                                    event=True)
            msg = _(u"Added permssion for user ${userid}",
                    mapping={'userid': appstruct['userid']})
            self.api.flash_messages.add(msg)
            url = resource_url(self.context, self.request)
            return HTTPFound(location=url)
Example #2
0
def navigation_sections(context, request, va, **kwargs):
    """ Navigation sections. These doesn't work for unauthenticated currently. """
    api = kwargs['api']
    if not api.userid:
        return u""
    state = va.kwargs['state']
    response = {}
    response['api'] = api
    response['state'] = state
    response['section_title'] = va.title
    response['toggle_id'] = '%s-%s' % (context.uid, state)

    if request.cookies.get(response['toggle_id']):
        response['closed_section'] = True
        return render('templates/sidebars/navigation_section.pt', response, request = request)

    context_path = resource_path(context)
    query = dict(
        workflow_state = state,
        path = context_path,
    )
    #Meeting or root context?
    if ISiteRoot.providedBy(context):
        query['content_type'] = 'Meeting'
        #Note that None is not a valid query. This view shouldn't be called for unauthenticated.
        query['view_meeting_userids'] = api.userid
    else:
        query['content_type'] = 'AgendaItem'
        #Principals taken from this context will be okay for a query within the meetings
        query['allowed_to_view'] = {'operator': 'or', 'query': api.context_effective_principals(context)}
        query['sort_index'] = 'order'
    
    def _count_query(path, content_type, unread = False):
        """ Returns number of an item, possbly unread only. """
        query = {}
        query['path'] = path
        query['content_type'] = content_type
        
        if content_type == 'Proposal':
            query['workflow_state'] = {'query':('published', 'retracted', 'unhandled', 'voting', 'approved', 'denied'), 'operator':'or'}        
        if unread:
            query['unread'] = api.userid
        return api.search_catalog(**query)[0]
    
    def _in_current_context(path, context_path):
        path = path.split('/')
        context_path = context_path.split('/')
        if len(path) > len(context_path):
            path = path[0:len(context_path)]
            
        return path == context_path

    response['brains'] = api.get_metadata_for_query(**query)
    response['context_path'] = context_path
    response['count_query'] = _count_query
    response['closed_section'] = False
    response['in_current_context'] = _in_current_context
    return render('templates/sidebars/navigation_section.pt', response, request = request)
Example #3
0
def deferred_roles_widget(node, kw):
    """ Only handles role-like groups with prefix 'role:'"""
    context = kw['context']
    if ISiteRoot.providedBy(context):
        roles_choices = ROOT_ROLES
    elif IMeeting.providedBy(context):
        roles_choices = MEETING_ROLES
    else:
        TypeError("Wrong context for deferred_roles_widget - must be IMeeting or ISiteRoot.")
    return deform.widget.CheckboxChoiceWidget(values=roles_choices,
                                              missing=colander.null,)
Example #4
0
 def import_data(self, parent, name, filedata):
     connection = parent._p_jar
     new_obj = connection.importFile(filedata)
     if ISiteRoot.providedBy(new_obj):
         raise ValueError(
             "Importing a new site root is not supported. If you want to import a complete database, simply copy the database file Data.fs"
         )
     parent[name] = new_obj
     # Reindex all objects
     for obj in find_all_base_content(new_obj):
         index_object(self.context.catalog, obj)
Example #5
0
 def __call__(self, node, value):
     if not has_permission(MANAGE_GROUPS, self.context, self.request):
         raise colander.Invalid(node, _(u"You can't change groups in this context"))
     roles = []
     if ISiteRoot.providedBy(self.context):
         roles.extend([x[0] for x in ROOT_ROLES])
     elif IMeeting.providedBy(self.context):
         roles.extend([x[0] for x in MEETING_ROLES])
     for v in value:
         if v not in roles:
             raise colander.Invalid(node, _(u"wrong_context_for_roles_error",
                                            default = u"Group ${group} can't be assigned in this context",
                                            mapping = {'group': v}))
Example #6
0
def deferred_roles_widget(node, kw):
    """ Only handles role-like groups with prefix 'role:'"""
    context = kw['context']
    if ISiteRoot.providedBy(context):
        roles_choices = ROOT_ROLES
    elif IMeeting.providedBy(context):
        roles_choices = MEETING_ROLES
    else:
        TypeError(
            "Wrong context for deferred_roles_widget - must be IMeeting or ISiteRoot."
        )
    return deform.widget.CheckboxChoiceWidget(
        values=roles_choices,
        missing=colander.null,
    )
Example #7
0
 def __call__(self, node, value):
     if not has_permission(MANAGE_GROUPS, self.context, self.request):
         raise colander.Invalid(
             node, _(u"You can't change groups in this context"))
     roles = []
     if ISiteRoot.providedBy(self.context):
         roles.extend([x[0] for x in ROOT_ROLES])
     elif IMeeting.providedBy(self.context):
         roles.extend([x[0] for x in MEETING_ROLES])
     for v in value:
         if v not in roles:
             raise colander.Invalid(
                 node,
                 _(u"wrong_context_for_roles_error",
                   default=
                   u"Group ${group} can't be assigned in this context",
                   mapping={'group': v}))
Example #8
0
 def __init__(self, context):
     assert ISiteRoot.providedBy(context)
     self.context = context
Example #9
0
def navigation_sections(context, request, va, **kwargs):
    """ Navigation sections. These doesn't work for unauthenticated currently. """
    api = kwargs['api']
    if not api.userid:
        return u""
    state = va.kwargs['state']
    response = {}
    response['api'] = api
    response['state'] = state
    response['section_title'] = va.title
    response['toggle_id'] = '%s-%s' % (context.uid, state)

    if request.cookies.get(response['toggle_id']):
        response['closed_section'] = True
        return render('templates/sidebars/navigation_section.pt',
                      response,
                      request=request)

    context_path = resource_path(context)
    query = dict(
        workflow_state=state,
        path=context_path,
    )
    #Meeting or root context?
    if ISiteRoot.providedBy(context):
        query['content_type'] = 'Meeting'
        #Note that None is not a valid query. This view shouldn't be called for unauthenticated.
        query['view_meeting_userids'] = api.userid
    else:
        query['content_type'] = 'AgendaItem'
        #Principals taken from this context will be okay for a query within the meetings
        query['allowed_to_view'] = {
            'operator': 'or',
            'query': api.context_effective_principals(context)
        }
        query['sort_index'] = 'order'

    def _count_query(path, content_type, unread=False):
        """ Returns number of an item, possbly unread only. """
        query = {}
        query['path'] = path
        query['content_type'] = content_type

        if content_type == 'Proposal':
            query['workflow_state'] = {
                'query': ('published', 'retracted', 'unhandled', 'voting',
                          'approved', 'denied'),
                'operator':
                'or'
            }
        if unread:
            query['unread'] = api.userid
        return api.search_catalog(**query)[0]

    def _in_current_context(path, context_path):
        path = path.split('/')
        context_path = context_path.split('/')
        if len(path) > len(context_path):
            path = path[0:len(context_path)]

        return path == context_path

    response['brains'] = api.get_metadata_for_query(**query)
    response['context_path'] = context_path
    response['count_query'] = _count_query
    response['closed_section'] = False
    response['in_current_context'] = _in_current_context
    return render('templates/sidebars/navigation_section.pt',
                  response,
                  request=request)
Example #10
0
 def __init__(self, context):
     assert ISiteRoot.providedBy(context)
     self.context = context