diff --git a/app/config/roles.php b/app/config/roles.php index 0a4ec4369c..8dfaf78eb4 100644 --- a/app/config/roles.php +++ b/app/config/roles.php @@ -24,6 +24,8 @@ $logged = [ 'projects.write', 'locale.read', 'avatars.read', + 'execution.read', + 'execution.write', ]; $admins = [ @@ -37,8 +39,6 @@ $admins = [ 'users.write', 'collections.read', 'collections.write', - 'functions.read', - 'functions.write', 'platforms.read', 'platforms.write', 'keys.read', @@ -50,6 +50,10 @@ $admins = [ 'locale.read', 'avatars.read', 'health.read', + 'functions.read', + 'functions.write', + 'execution.read', + 'execution.write', ]; return [ @@ -63,6 +67,8 @@ return [ 'files.read', 'locale.read', 'avatars.read', + 'execution.read', + 'execution.write', ], ], ROLE_MEMBER => [ diff --git a/app/config/scopes.php b/app/config/scopes.php index 88c67d70dd..05bd63be31 100644 --- a/app/config/scopes.php +++ b/app/config/scopes.php @@ -13,6 +13,8 @@ return [ // List of publicly visible scopes 'files.write', 'functions.read', 'functions.write', + 'execution.read', + 'execution.write', 'health.read', // 'platforms.read', // 'platforms.write', diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 51d0b1ff72..b10a735877 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -618,7 +618,7 @@ App::delete('/v1/functions/:functionId/tags/:tagId') App::post('/v1/functions/:functionId/executions') ->groups(['api', 'functions']) ->desc('Create Execution') - ->label('scope', 'functions.write') + ->label('scope', 'execution.write') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'functions') ->label('sdk.method', 'createExecution') @@ -654,16 +654,20 @@ App::post('/v1/functions/:functionId/executions') throw new Exception('Tag not found. Deploy tag before trying to execute a function', 404); } + Authorization::reset(); + $validator = new Authorization($function, 'execute'); if (!$validator->isValid($function->getPermissions())) { // Check if user has write access to execute function throw new Exception($validator->getDescription(), 401); } + Authorization::disable(); + $execution = $projectDB->createDocument([ '$collection' => Database::SYSTEM_COLLECTION_EXECUTIONS, '$permissions' => [ - 'read' => $function->getPermissions(), + 'read' => $function->getPermissions()['execute'] ?? [], 'write' => [], ], 'dateCreated' => time(), @@ -698,7 +702,7 @@ App::post('/v1/functions/:functionId/executions') App::get('/v1/functions/:functionId/executions') ->groups(['api', 'functions']) ->desc('List Executions') - ->label('scope', 'functions.read') + ->label('scope', 'execution.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'functions') ->label('sdk.method', 'listExecutions') @@ -740,7 +744,7 @@ App::get('/v1/functions/:functionId/executions') App::get('/v1/functions/:functionId/executions/:executionId') ->groups(['api', 'functions']) ->desc('Get Execution') - ->label('scope', 'functions.read') + ->label('scope', 'execution.read') ->label('sdk.platform', [APP_PLATFORM_CLIENT, APP_PLATFORM_SERVER]) ->label('sdk.namespace', 'functions') ->label('sdk.method', 'getExecution') diff --git a/tests/e2e/Scopes/ProjectCustom.php b/tests/e2e/Scopes/ProjectCustom.php index c17bd52878..e1059f6afa 100644 --- a/tests/e2e/Scopes/ProjectCustom.php +++ b/tests/e2e/Scopes/ProjectCustom.php @@ -75,6 +75,8 @@ trait ProjectCustom 'files.write', 'functions.read', 'functions.write', + 'execution.read', + 'execution.write', 'locale.read', 'avatars.read', 'health.read', diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index cca171561e..66d95ffeca 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -680,6 +680,7 @@ class FunctionsCustomServerTest extends Scope ]); $executionId = $execution['body']['$id'] ?? ''; + $this->assertEquals(201, $execution['headers']['status-code']); sleep(15);