Added the permission models

This commit is contained in:
Cédric Belin
2018-11-01 23:37:40 +01:00
parent 55b0fa7951
commit 187dd91bcd
2 changed files with 86 additions and 0 deletions

49
lib/models/Permission.php Normal file
View File

@ -0,0 +1,49 @@
<?php
declare(strict_types=1);
namespace yii\gitea\models;
use yii\base\{Model};
/**
* Represents a set of permissions.
*/
class Permission extends Model {
/**
* @var bool Value indicating whether administrator access is allowed.
*/
public $admin = false;
/**
* @var bool Value indicating whether pull is allowed.
*/
public $pull = false;
/**
* @var bool Value indicating whether push is allowed.
*/
public $push = false;
/**
* Creates a new user from the specified JSON map.
* @param object $map A JSON map representing a user.
* @return static The instance corresponding to the specified JSON map.
*/
static function fromJson(object $map): self {
return new static([
'admin' => isset($map->admin) && is_bool($map->admin) ? $map->admin : false,
'pull' => isset($map->pull) && is_bool($map->pull) ? $map->pull : false,
'push' => isset($map->push) && is_bool($map->push) ? $map->push : false
]);
}
/**
* Returns the validation rules for attributes.
* @return array[] The validation rules.
*/
function rules(): array {
return [
[['admin', 'pull', 'push'], 'boolean', 'falseValue' => false, 'trueValue' => true]
];
}
}

View File

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace yii\gitea\models;
use Enum\{EnumTrait};
/**
* Defines the permission of a Gitea status.
*/
final class TeamPermission {
use EnumTrait;
/**
* @var string The team has the administrator permission.
*/
const ADMIN = 'admin';
/**
* @var string The team doesn't have any permission.
*/
const NONE = 'none';
/**
* @var string The team has the owner permission.
*/
const OWNER = 'owner';
/**
* @var string The team has the read permission.
*/
const READ = 'read';
/**
* @var string The team has the write permission.
*/
const WRITE = 'write';
}