예제 #1
0
 public function testTableName()
 {
     $this->assertEquals('column_name_here', SchemaUtils::cleanTableName('column name here'));
     $this->assertEquals('column_name_here', SchemaUtils::cleanTableName('column name$here'));
     $this->assertEquals('column_name_here', SchemaUtils::cleanTableName('column  name  $here'));
     $this->assertEquals('column_', SchemaUtils::cleanTableName('column '));
     $this->assertEquals('column_3', SchemaUtils::cleanTableName('column 3'));
 }
예제 #2
0
        throw new Exception(__t('permission_denied'));
    }
    if (isset($requestPayload['addTable'])) {
        $isTableNameAlphanumeric = preg_match("/[a-z0-9]+/i", $requestPayload['table_name']);
        $zeroOrMoreUnderscoresDashes = preg_match("/[_-]*/i", $requestPayload['table_name']);
        if (!($isTableNameAlphanumeric && $zeroOrMoreUnderscoresDashes)) {
            $app->response->setStatus(400);
            return JsonView::render(['message' => __t('invalid_table_name')]);
        }
        unset($requestPayload['addTable']);
        if (!SchemaManager::tableExists($requestPayload['table_name'])) {
            $app->emitter->run('table.create:before', $requestPayload['table_name']);
            // Through API:
            // Remove spaces and symbols from table name
            // And in lowercase
            $requestPayload['table_name'] = SchemaUtils::cleanTableName($requestPayload['table_name']);
            SchemaManager::createTable($requestPayload['table_name']);
            $app->emitter->run('table.create', $requestPayload['table_name']);
            $app->emitter->run('table.create:after', $requestPayload['table_name']);
        }
    }
    $privileges = new DirectusPrivilegesTableGateway($acl, $ZendDb);
    $response = $privileges->insertPrivilege($requestPayload);
    return JsonView::render($response);
})->via('POST');
$app->map("/{$v}/privileges/:groupId/:privilegeId", function ($groupId, $privilegeId) use($acl, $ZendDb, $params, $requestPayload, $app) {
    $currentUser = Auth::getUserRecord();
    $myGroupId = $currentUser['group'];
    if ($myGroupId != 1) {
        throw new Exception(__t('permission_denied'));
    }