/**
  * Get Permissions for the given Group ID
  * @param $groupId
  *
  * @return array
  */
 public function getGroupPrivileges($groupId)
 {
     $getPrivileges = function () use($groupId) {
         return (array) $this->fetchGroupPrivileges($groupId);
     };
     return $this->memcache->getOrCache(MemcacheProvider::getKeyDirectusGroupPrivileges($groupId), $getPrivileges, 1800);
 }
 public function getMessagesNewerThan($maxId, $currentUser)
 {
     $fetchFn = function () use($maxId, $currentUser) {
         $select = new Select($this->getTable());
         $select->columns(['id', 'message_id'])->join('directus_messages', 'directus_messages_recipients.message_id = directus_messages.id', ['response_to'])->where->greaterThan('message_id', $maxId)->and->equalTo('recipient', $currentUser)->and->equalTo('read', 0);
         $result = $this->selectWith($select)->toArray();
         return $result;
     };
     $cacheKey = MemcacheProvider::getKeyDirectusMessagesNewerThan($maxId, $currentUser);
     $result = $this->memcache->getOrCache($cacheKey, $fetchFn, 1800);
     $messageThreads = [];
     foreach ($result as $message) {
         $messageThreads[] = empty($message['response_to']) ? $message['message_id'] : $message['response_to'];
     }
     return array_values(array_unique($messageThreads));
 }
Пример #3
0
 * @var \Zend\Db\Adapter
 */
$ZendDb = Bootstrap::get('ZendDb');
/**
 * @var \Directus\Acl
 */
$acl = Bootstrap::get('acl');
/**
 * Authentication
 */
$DirectusUsersTableGateway = new DirectusUsersTableGateway($acl, $ZendDb);
Auth::setUserCacheRefreshProvider(function ($userId) use($DirectusUsersTableGateway) {
    $cacheFn = function () use($userId, $DirectusUsersTableGateway) {
        return $DirectusUsersTableGateway->find($userId);
    };
    $cacheKey = MemcacheProvider::getKeyDirectusUserFind($userId);
    $user = $DirectusUsersTableGateway->memcache->getOrCache($cacheKey, $cacheFn, 10800);
    return $user;
});
if (Auth::loggedIn()) {
    $user = Auth::getUserRecord();
    $acl->setUserId($user['id']);
    $acl->setGroupId($user['group']);
}
/**
 * Request Payload
 */
$params = $_GET;
$requestPayload = json_decode($app->request()->getBody(), true);
/**
 * Extension Alias
Пример #4
0
 /**
  * Construct Acl provider
  * @return \Directus\Acl
  */
 private static function acl()
 {
     $acl = new acl();
     $db = self::get('ZendDb');
     $DirectusTablesTableGateway = new DirectusTablesTableGateway($acl, $db);
     $getTables = function () use($DirectusTablesTableGateway) {
         return $DirectusTablesTableGateway->select()->toArray();
     };
     $tableRecords = $DirectusTablesTableGateway->memcache->getOrCache(MemcacheProvider::getKeyDirectusTables(), $getTables, 1800);
     $magicOwnerColumnsByTable = [];
     foreach ($tableRecords as $tableRecord) {
         if (!empty($tableRecord['user_create_column'])) {
             $magicOwnerColumnsByTable[$tableRecord['table_name']] = $tableRecord['user_create_column'];
         }
     }
     $acl::$cms_owner_columns_by_table = $magicOwnerColumnsByTable;
     if (AuthProvider::loggedIn()) {
         $currentUser = AuthProvider::getUserInfo();
         $Users = new DirectusUsersTableGateway($acl, $db);
         $cacheFn = function () use($currentUser, $Users) {
             return $Users->find($currentUser['id']);
         };
         $cacheKey = MemcacheProvider::getKeyDirectusUserFind($currentUser['id']);
         $currentUser = $Users->memcache->getOrCache($cacheKey, $cacheFn, 10800);
         if ($currentUser) {
             $privilegesTable = new DirectusPrivilegesTableGateway($acl, $db);
             $acl->setGroupPrivileges($privilegesTable->getGroupPrivileges($currentUser['group']));
         }
     }
     return $acl;
 }
Пример #5
0
 public static function getAllSchemas($userGroupId, $versionHash)
 {
     $cacheKey = MemcacheProvider::getKeyDirectusGroupSchema($userGroupId, $versionHash);
     $acl = Bootstrap::get('acl');
     $ZendDb = Bootstrap::get('ZendDb');
     $directusPreferencesTableGateway = new DirectusPreferencesTableGateway($acl, $ZendDb);
     $getPreferencesFn = function () use($directusPreferencesTableGateway) {
         $currentUser = Auth::getUserInfo();
         $preferences = $directusPreferencesTableGateway->fetchAllByUser($currentUser['id']);
         return $preferences;
     };
     $getSchemasFn = function () {
         $tableSchemas = TableSchema::getTableSchemas();
         $columnSchemas = TableSchema::getColumnSchemas();
         // Nest column schemas in table schemas
         foreach ($tableSchemas as &$table) {
             $tableName = $table['id'];
             $table['columns'] = array_values($columnSchemas[$tableName]);
             foreach ($columnSchemas[$tableName] as $column) {
                 if ($column['column_key'] == 'PRI') {
                     $table['primary_column'] = $column['column_name'];
                     break;
                 }
             }
             $table = array('schema' => $table);
         }
         return $tableSchemas;
     };
     // 3 hr cache
     $schemas = $directusPreferencesTableGateway->memcache->getOrCache($cacheKey, $getSchemasFn, 10800);
     // Append preferences post cache
     $preferences = $getPreferencesFn();
     foreach ($schemas as &$table) {
         $table['preferences'] = $preferences[$table['schema']['id']];
     }
     return $schemas;
 }