示例#1
0
    def group_permission_post(self):
        request = self.request
        resource = self.request.context.resource
        came_from = request.headers.get('Referer')
        schema = GroupResourcePermissionSchema(context={
            'request': self.request,
            'resource': resource
        })
        data = {
            'group_id': self.request.POST.get('group_id'),
            'perm_name': self.request.POST.get('perm_name')
        }
        data = schema.load(data).data
        group = GroupService.get(data['group_id'],
                                 db_session=self.request.dbsession)

        perm_inst = self.shared.group_permission_post(resource, group.id,
                                                      data['perm_name'])
        location = came_from or request.route_url('admin')
        return httpexceptions.HTTPFound(location=location)
示例#2
0
    def group_permission_delete(self):
        request = self.request
        resource = self.request.context.resource
        group = GroupService.get(request.GET.get('group_id'),
                                 db_session=self.request.dbsession)
        permission = self.shared.group_permission_get(
            resource.resource_id, group.id, request.GET.get('perm_name'))

        back_url = request.route_url('admin_object',
                                     object=resource.plural_type,
                                     object_id=resource.resource_id,
                                     verb='GET')

        if request.method == "POST":
            self.shared.group_permission_delete(resource, group.id,
                                                request.GET.get('perm_name'))
            return httpexceptions.HTTPFound(location=back_url)

        return {
            "parent_obj": group,
            "member_obj": permission,
            "confirm_url": request.current_route_url(),
            "back_url": back_url
        }
示例#3
0
 def validate_group_id(self, value):
     request = self.context['request']
     group = GroupService.get(value, db_session=request.dbsession)
     if not group:
         raise validate.ValidationError(_('Group not found'))
示例#4
0
 def test_get(self, db_session):
     group1 = add_group(db_session, "group1")
     group = GroupService.get(group_id=group1.id, db_session=db_session)
     assert group.id == group1.id