Create roles, permissions and roles_permissions
190492
private function generateRolesAndPermissions()
    {
        if( empty($this->aclData) ) {
            $this->error('empty roles and permissions in "generateRolesAndPermissions" method');

            return;
        }

        foreach ( $this->aclData as $acl ) {
            $this->createPermissions($acl['acl']);
            $this->createRoles($acl['acl']);
        }

        $this->createRolesPermissions($this->aclData);
    }
59506
def roles_table(user):
    """"""
    table = formatting.Table(['id', 'Role Name', 'Description'])
    for role in user['roles']:
        table.add_row([role['id'], role['name'], role['description']])
    return table
74178
def check_role_permissions(role, permissions, current_permissions):
    
    role_permissions = []

    # get all the current permissions, we'll remove these as we verify they should still be granted
    for permission in permissions:
        splits = permission.split(".")
        if len(splits) != 2 and len(splits) != 3:
            sys.stderr.write("  invalid permission %s, ignoring\n" % permission)
            continue

        app = splits[0]
        codenames = []

        if len(splits) == 2:
            codenames.append(splits[1])
        else:
            (object, action) = splits[1:]

            # if this is a wildcard, then query our database for all the permissions that exist on this object
            if action == '*':
                for perm in Permission.objects.filter(codename__startswith="%s_" % object, content_type__app_label=app):
                    codenames.append(perm.codename)
            # otherwise, this is an error, continue
            else:
                sys.stderr.write("  invalid permission %s, ignoring\n" % permission)
                continue

        if len(codenames) == 0:
            continue

        for codename in codenames:
            # the full codename for this permission
            full_codename = "%s.%s" % (app, codename)

            # this marks all the permissions which should remain
            role_permissions.append(full_codename)

            try:
                assign_perm(full_codename, role)
            except ObjectDoesNotExist:
                pass
                # sys.stderr.write("  unknown permission %s, ignoring\n" % permission)

    # remove any that are extra
    for permission in current_permissions:
        if isinstance(permission, str):
            key = permission
        else:
            key = "%s.%s" % (permission.content_type.app_label, permission.codename)

        if key not in role_permissions:
            remove_perm(key, role)
998167
def create_user(self, username, password, roles):
    
    return users.create_user(self, username, password, roles)
762548
protected function _setRoles()
    {
        $this->loadModel('Block.Blocks');
        $roles = $this->Blocks->Roles->find('list');
        $this->set('roles', $roles);
    }
143825
function addRolePrivilege (access, role, privilege) {
  if (role === true || access[privilege].role === true) {
    access[privilege] = {
      role: true
    }
    return
  }

  access[privilege].role = _.union(access[privilege].role, _.concat(role))
}
826124
def _apply_role_tree(self, perm_tree, role):
        """"""
        role_permissions = role.get_permissions()
        for perm in role_permissions:
            self._traverse_tree(perm_tree, perm)['checked'] = True
        return perm_tree
559084
def get_all_permissions(self):
        """"""
        perms = set()
        for role in self.get_user_roles():
            for perm_view in role.permissions:
                t = (perm_view.permission.name, perm_view.view_menu.name)
                perms.add(t)
        return perms
748895
public function installRoles()
    {
        $this->_roleService = new erdiko\users\models\Role();

        $results = array(
            "successes" => array(),
            "failures"  => array(),
        );

        foreach($this->_rolesArray as $role) {
            // attempt to create the role
            // wrap this in a try/catch since this throws an exception if failure on create
            $createResult = false;
            try {
                $createResult = (boolean)$this->_roleService->create($role);
            } catch(\Exception $e) {
                // TODO do we need to log this elsewhere?
            }

            if(true !== $createResult) {
                $results["failures"][] = $role;
            } else {
                $results["successes"][] = $role;
            }
        }

        return $results;
    }
1022076
def _setup(self):
        
        role_directory = os.path.join(self._config.scenario.directory,
                                      self.options['roles-path'])
        if not os.path.isdir(role_directory):
            os.makedirs(role_directory)
491796
def create_guild_role(data)
      role_data = data['role']
      server_id = data['guild_id'].to_i
      server = @servers[server_id]
      new_role = Role.new(role_data, self, server)
      existing_role = server.role(new_role.id)
      if existing_role
        existing_role.update_from(new_role)
      else
        server.add_role(new_role)
      end
    end
116683
def _create_permissions(**kwargs):
    
    from django.contrib.contenttypes.models import ContentType

    object_tools.autodiscover()
    tools = object_tools.tools._registry

    # This will hold the permissions we're looking for as
    # (content_type, (codename, name))
    searched_perms = list()
    # The codenames and ctypes that should exist.
    ctypes = set()
    for model, tools in tools.items():
        ctype = ContentType.objects.get_for_model(model)
        ctypes.add(ctype)
        for perm in _get_all_permissions(model._meta, tools):
            searched_perms.append((ctype, perm))

    # Find all the Permissions that have a context_type for a model we're
    # looking for.  We don't need to check for codenames since we already have
    # a list of the ones we're going to create.
    all_perms = set(auth_app.Permission.objects.filter(
        content_type__in=ctypes,
    ).values_list(
        "content_type", "codename"
    ))

    for ctype, (codename, name) in searched_perms:
        # If the permissions exists, move on.
        if (ctype.pk, codename) in all_perms:
            continue
        p = auth_app.Permission.objects.create(
            codename=codename,
            name=name,
            content_type=ctype
        )
        if kwargs.get("verbosity", 2) >= 2:
            print("Adding permission '%s'" % p)
24743
protected function initPermissions()
    {
        if (isset($this->settings) && $this->settings->exists('permissions') && !self::$init_stages[$this->name]['permissions']) {

            $permissions = [
                'admin'
            ];

            if ($this->settings->exists('config')) {
                $permissions[] = 'config';
            }

            $permissions = array_merge($permissions, $this->settings->get('permissions'));

            $this->permissions = new Permissions();
            $this->permissions->set($permissions);

            // Set flat that permission init is done
            self::$init_stages[$this->name]['perms'] = true;
        }
    }
247777
def create_db(self):
        
        self.add_role(self.auth_role_admin)
        self.add_role(self.auth_role_public)
        if self.count_users() == 0:
            log.warning(LOGMSG_WAR_SEC_NO_USER)
582892
def add_role(self, name, **attrs):
        
        return Roles(self.requester).create(self.id, name, **attrs)
76041
public function actionRoleAssign() : void
    {
        $username = $this->prompt('Username:', ['required' => true]);
        $user = $this->findModel($username);
        $roleName = $this->select('Role:', ArrayHelper::map($this->authManager->getRoles(), 'name', 'description'));
        $role = $this->authManager->getRole($roleName);
        $this->authManager->assign($role, $user->id);
        $this->log(true);
    }
962730
def create_user(self, **kwargs):
        """"""
        roles = kwargs.pop('roles', [])
        user = self.user_model(**self._prepare_create_user_args(**kwargs))
        user = self.put(user)
        for role in roles:
            self.add_role_to_user(user, role)
        self.put(user)
        return user