mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Merge branch '0.7.x' of github.com:appwrite/appwrite into feat-730-new-webhook-events
This commit is contained in:
commit
a4ea9e78a8
12 files changed
+216
-29
No files matched your search
@@ -23,7 +23,6 @@ class Auth
|
||||
const USER_ROLE_OWNER = 4;
|
||||
const USER_ROLE_APP = 5;
|
||||
const USER_ROLE_SYSTEM = 6;
|
||||
const USER_ROLE_ALL = '*';
|
||||
|
||||
/**
|
||||
* Token Types.
|
||||
@@ -49,9 +48,9 @@ class Auth
|
||||
/**
|
||||
* User Unique ID.
|
||||
*
|
||||
* @var int
|
||||
* @var string
|
||||
*/
|
||||
public static $unique = 0;
|
||||
public static $unique = '';
|
||||
|
||||
/**
|
||||
* User Secret Key.
|
||||
@@ -75,7 +74,7 @@ class Auth
|
||||
/**
|
||||
* Encode Session.
|
||||
*
|
||||
* @param int $id
|
||||
* @param string $id
|
||||
* @param string $secret
|
||||
*
|
||||
* @return string
|
||||
@@ -206,4 +205,40 @@ class Auth
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is Previligged User?
|
||||
*
|
||||
* @param array $roles
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isPreviliggedUser(array $roles): bool
|
||||
{
|
||||
if(
|
||||
array_key_exists('role:'.self::USER_ROLE_OWNER, $roles) ||
|
||||
array_key_exists('role:'.self::USER_ROLE_DEVELOPER, $roles) ||
|
||||
array_key_exists('role:'.self::USER_ROLE_ADMIN, $roles)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is App User?
|
||||
*
|
||||
* @param array $roles
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isAppUser(array $roles): bool
|
||||
{
|
||||
if(array_key_exists('role:'.self::USER_ROLE_APP, $roles)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class Authorization extends Validator
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
static $roles = ['*'];
|
||||
static $roles = ['*' => true];
|
||||
|
||||
/**
|
||||
* @var Document
|
||||
@@ -77,7 +77,7 @@ class Authorization extends Validator
|
||||
foreach ($permissions[$this->action] as $permission) {
|
||||
$permission = \str_replace(':{self}', ':'.$this->document->getId(), $permission);
|
||||
|
||||
if (\in_array($permission, self::getRoles())) {
|
||||
if (\array_key_exists($permission, self::$roles)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -92,17 +92,35 @@ class Authorization extends Validator
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function setRole($role): void
|
||||
public static function setRole(string $role): void
|
||||
{
|
||||
self::$roles[] = $role;
|
||||
self::$roles[$role] = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public static function getRoles()
|
||||
public static function getRoles(): array
|
||||
{
|
||||
return self::$roles;
|
||||
return \array_keys(self::$roles);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public static function cleanRoles(): void
|
||||
{
|
||||
self::$roles = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $role
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function isRole(string $role): bool
|
||||
{
|
||||
return (\array_key_exists($role, self::$roles));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -280,7 +280,7 @@ class OpenAPI3 extends Format
|
||||
'x-example' => $node['x-example'] ?? null,
|
||||
];
|
||||
|
||||
if(!\is_null($node['default'])) {
|
||||
if(isset($node['default'])) {
|
||||
$body['content'][$consumes[0]]['schema']['properties'][$name]['default'] = $node['default'];
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user