Exemplo n.º 1
0
    def __show_group(self, group, path, errors = []):
        assert group is not None
        assert group.is_group()
        assert path is not None

        # Make sure that current_user has "view" permissions on it.
        current_user = self.api.get_current_user()
        if group.get_id() is not None:
            view = self.guard.get_action(handle = 'view', type = UserAction)
            assert view is not None
            if not self.guard.has_permission(current_user, view, group):
                group     = Group(group.get_name())
                errors    = [_("You do not have permission to view " +
                                  "this group.")]

        # Collect information for the browser.
        users    = []
        groups   = []
        if group.get_id() is not None:
            acls     = self.userdb.get_permission_list(group)
            parents  = self.guard.get_resource_parents(group)
            children = self.guard.get_resource_children(group)
            for child in children:
                if child.is_group():
                    groups.append(child)
                else:
                    users.append(child)
        else:
            parent_id = path.crop().get_current_id()
            parent    = self.guard.get_resource(id = parent_id)
            parents   = [parent]
            acls      = []

        # Render the template.
        self.api.render('group_editor.tmpl',
                        path         = path,
                        parents      = parents,
                        group        = group,
                        users        = users,
                        groups       = groups,
                        acls         = acls,
                        get_resource = self.guard.get_resource,
                        errors       = errors)
Exemplo n.º 2
0
    def index(self, **kwargs):
        # Find out which item was requested.
        path_str = self.api.get_data().get_str('path_str')
        if path_str is None:
            resource = self.guard.get_resource(handle = 'everybody',
                                               type   = Group)
            path = SpiffGuard.ResourcePath([resource.get_id()])
        else:
            path = SpiffGuard.ResourcePath(path_str)

        # Fetch the requested user or group info.
        errors = []
        id     = path.get_current_id()
        if self.api.post_data().get_bool('group_add'):
            resource = Group('')
            path     = path.append(0)
        elif self.api.post_data().get_bool('user_add'):
            resource = User('')
            path     = path.append(0)
        elif self.api.post_data().get_bool('group_save') and id == 0:
            resource = Group('')
            errors   = self.__save_resource(resource)
            if not errors:
                path = path.crop().append(resource.get_id())
        elif self.api.post_data().get_bool('group_save'):
            resource = self.guard.get_resource(id = id)
            errors   = self.__save_resource(resource)
            path     = path.crop().append(resource.get_id())
        elif self.api.post_data().get_bool('user_save') and id == 0:
            resource = User('')
            errors   = self.__save_resource(resource)
            if not errors:
                path = path.crop().append(resource.get_id())
        elif self.api.post_data().get_bool('user_save'):
            resource = self.guard.get_resource(id = id)
            errors   = self.__save_resource(resource)
            path     = path.crop().append(resource.get_id())
        elif (self.api.post_data().get_bool('group_delete') and
              self.api.post_data().get_str('group_delete_really') == 'yes'):
            resource = self.guard.get_resource(id = id)
            # Check if the group still has users in it.
            children = self.guard.get_resource_children(resource)
            if len(children) > 0:
                #FIXME: Rather ask what to do with the children.
                errors = [_("Group can not be deleted because " +
                                    "it still has users in it.")]
            else:
                errors   = self.__delete_resource(resource)
                path     = path.crop()
                id       = path.get_current_id()
                resource = self.guard.get_resource(id = id)
        elif (self.api.post_data().get_bool('user_delete') and
              self.api.post_data().get_str('user_delete_really') == 'yes'):
            resource = self.guard.get_resource(id = id)
            errors   = self.__delete_resource(resource)
            path     = path.crop()
            id       = path.get_current_id()
            resource = self.guard.get_resource(id = id)
        elif path_str is not None:
            resource = self.guard.get_resource(id = id)

        # Display the editor.
        if resource.is_group():
            self.__show_group(resource, path, errors)
        else:
            self.__show_user(resource, path, errors)