Attach permission

@param mixed ...$permissions
@return $this
519050
public function attachPermission(...$permissions)
    {
        $this->eachPermission($permissions, function($permission) {
            if (! $this->hasDirectPermission($permission)) {
                $this->permissions()->attach($permission->id);
            }
        });

        return $this;
    }
972005
public function attachPermissions($permissions, $reload = true)
    {
        event(new AttachingPermissionsToGroup($this, $permissions));
        $permissions = $this->permissions()->saveMany($permissions);
        event(new AttachedPermissionsToGroup($this, $permissions));

        $this->loadPermissions($reload);

        return $permissions;
    }
816526
public function attachPermission(&$permission, $reload = true)
    {
        if ($this->hasPermission($permission)) return;

        event(new AttachingPermissionToGroup($this, $permission));
        $permission = $this->permissions()->save($permission);
        event(new AttachedPermissionToGroup($this, $permission));

        $this->loadPermissions($reload);
    }
306120
protected function setDirPermissions($permissions)
    {
        $permissions = (int) $permissions;

        if (! (0b100000000 & $permissions)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid permissions "%s" for directories. '
                . 'Directories will not available for reading.',
                decoct($permissions)
            ));
        }
        if (! (0b010000000 & $permissions)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid permissions "%s" for directories. '
                . 'Directories will not available for writing.',
                decoct($permissions)
            ));
        }
        if (! (0b001000000 & $permissions)) {
            throw new InvalidArgumentException(sprintf(
                'Invalid permissions "%s" for directories. '
                . 'The content of directories will not available.',
                decoct($permissions)
            ));
        }
        $this->dirPermissions = $permissions;
    }
1140517
protected function canOne(array $permissions)
    {
        foreach ($permissions as $permission) {
            if ($this->hasPermission($permission)) {
                return true;
            }
        }

        return false;
    }
1028634
public function detachPermissions($permissions = null)
    {
        if (!$permissions) {
            $permissions = $this->permissions()->get();
        }

        foreach ($permissions as $permission) {
            $this->detachPermission($permission);
        }

        return $this;
    }
1222815
public function setPermissions($permissions)
	{
		if (is_string($permissions))
		{
			$permissions = '0'.ltrim($permissions, '0');
			$permissions = octdec($permissions);
		}

		return chmod($this->path, $permissions);
	}
940256
private function getAllowedPermissions($permissions)
    {
        $allowedPermissions = [];
        foreach ($permissions as $permission => $allowed) {
            if ($allowed) {
                $allowedPermissions[] = $permission;
            }
        }

        return $allowedPermissions;
    }
695513
public function setPermissions($permissions , $password)
    {
        if ( ! is_array($permissions) || ! is_string($password) || $password === '' ) {
            throw new InvalidException('Permissions and password must be respectively an array and a string');
        }
        try {
            $this->getSoapClient()->SetDocumentAccessPermissions(array(
                'permissions' => $permissions ,
                'password'    => $password ,
            ));

            return $this;
        } catch ( SoapException $ex ) {
            throw new PermissionsException('Error while setting the list of permissions and master password for the document' , $ex);
        }
    }
834657
public function create($permissions = 0755)
    {
        Filesystem::checkNotExists($this->path);
        Filesystem::checkWritable(dirname($this->path));
        mkdir($this->path, $permissions, true);
    }
849827
protected function toDotPermissions(array $permissions)
    {
        $data = [];
        //$permissions = $this->permissions->lists('slug', 'name');
        foreach ($permissions as $alias => $perm) {
            if ( ! is_array($perm) ) continue;
            foreach ($perm as $key => $value) {
                //if ( (bool) $value == false ) continue;
                $slug = $key . '.' . $alias;
                $data[$slug] = $value;
                //$data[] = $slug;
            }
        }

        return $data;
    }
50072
public function detachPermission(...$permissions)
    {
        $this->eachPermission($permissions, function($permission) {
            if ($this->hasDirectPermission($permission)) {
                $this->permissions()->detach($permission->id);
            }
        });

        return $this;
    }
599195
public function joinPermissionTo($permission)
    {
        $self = $this;

        return $this->join(
            $this->permissions(
                function(HasMany $permissions) use ($permission, $self) {
                    $permissions->where($self->getPermissionableTable() . '.action', $permission);
                }
            )
        )->prependSelect([$this->getTable() . $this->permissionableTableSuffix . '.*']);
    }
1101719
public function givePermissionTo(...$permissions)
    {
        $permissions = collect($permissions)
            ->flatten()
            ->map(function ($permission) {
                if (empty($permission)) {
                    return false;
                }

                return $this->getStoredPermission($permission);
            })
            ->filter(function ($permission) {
                return $permission instanceof Permission;
            })
            ->each(function ($permission) {
                $this->ensureModelSharesGuard($permission);
            })
            ->map->id
            ->all();

        $model = $this->getModel();

        if ($model->exists) {
            $this->permissions()->sync($permissions, false);
            $model->load('permissions');
        } else {
            $class = \get_class($model);

            $class::saved(
                function ($object) use ($permissions, $model) {
                    static $modelLastFiredOn;
                    if ($modelLastFiredOn !== null && $modelLastFiredOn === $model) {
                        return;
                    }
                    $object->permissions()->sync($permissions, false);
                    $object->load('permissions');
                    $modelLastFiredOn = $object;
                }
            );
        }

        $this->forgetCachedPermissions();

        return $this;
    }
258916
public function givePermissionTo(...$permissions)
    {
        $permissions = collect($permissions)
            ->flatten()
            ->map(function ($permission) {
                return $this->getStoredPermission($permission);
            })
            ->each(function ($permission) {
                $this->ensureModelSharesGuard($permission);
            })
            ->all();

        $this->permissions()->saveMany($permissions);

        $this->forgetCachedPermissions();

        return $this;
    }
931835
public function losePermissions($permissions): void
    {
        if (!is_array($permissions) && !$permissions instanceof Collection) {
            $permissions = func_get_args();
        }

        foreach ($permissions as $permission) {
            $permission = $this->resolvePermission($permission);

            $this->permissions()->detach($permission);
        }
    }
278352
public function syncPermissions(array $permissions)
    {
        foreach ($this->permissions as $current)
        {
            /** @var Permission $current */
            if ($current->isAllowed() && ! in_array($current->getName(), $permissions))
            {
                $this->removePermission($current);
            }
        }

        $this->allow($permissions);
    }