mirror of
https://github.com/nextcloud/passman.git
synced 2025-01-08 16:27:42 +08:00
49 lines
1.1 KiB
PHP
49 lines
1.1 KiB
PHP
|
<?php
|
||
|
/**
|
||
|
* Created by PhpStorm.
|
||
|
* User: wolfi
|
||
|
* Date: 2/10/16
|
||
|
* Time: 13:27
|
||
|
*/
|
||
|
|
||
|
namespace OCA\Passman\Utility;
|
||
|
|
||
|
|
||
|
use OCP\AppFramework\Db\Entity;
|
||
|
|
||
|
class PermissionEntity extends Entity {
|
||
|
CONST READ = 0b00000001;
|
||
|
CONST WRITE = 0b00000010;
|
||
|
CONST OWNER = 0b10000000;
|
||
|
|
||
|
/**
|
||
|
* Checks wether a user matches one or more permissions at once
|
||
|
* @param $permission
|
||
|
* @return bool
|
||
|
*/
|
||
|
public function hasPermission($permission) {
|
||
|
$tmp = $this->getPermissions();
|
||
|
$tmp = $tmp & $permission;
|
||
|
return $tmp == $permission;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Adds the given permission or permissions set to the user current permissions
|
||
|
* @param $permission
|
||
|
*/
|
||
|
public function addPermission($permission) {
|
||
|
$tmp = $this->getPermissions();
|
||
|
$tmp = $tmp | $permission;
|
||
|
$this->setPermissions($tmp);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Takes the given permission or permissions out from the user
|
||
|
* @param $permission
|
||
|
*/
|
||
|
public function removePermission($permission) {
|
||
|
$tmp = $this->getPermissions();
|
||
|
$tmp = $tmp & !$permission;
|
||
|
$this->setPermissions($tmp);
|
||
|
}
|
||
|
}
|