feedback + tests fix

This commit is contained in:
Hemachandar
2026-01-26 00:00:31 +05:30
parent e7d711e8c8
commit f28975117d
3 changed files with 30 additions and 8 deletions
+6 -1
View File
@@ -247,6 +247,7 @@ App::init()
$teamWideRoles = \array_filter($adminRoles, fn ($role) => !str_starts_with($role, "project-"));
foreach ($teamWideRoles as $teamRole) {
$scopes = \array_merge($scopes, $roles[$teamRole]['scopes']);
$authorization->addRole($teamRole);
}
$projectId = $project->getId();
@@ -260,8 +261,12 @@ App::init()
$projectSpecificRoles = \array_filter($adminRoles, fn ($role) => str_starts_with($role, "project-$projectId"));
foreach ($projectSpecificRoles as $projectRole) {
$actualRole = explode('-', $projectRole)[2];
$actualRole = \substr($projectRole, \strlen("project-$projectId-"));
if ($actualRole === '' || !isset($roles[$actualRole])) {
continue;
}
$scopes = \array_merge($scopes, $roles[$actualRole]['scopes']);
$authorization->addRole($actualRole);
}
$authorization->setDefaultStatus(false); // Cancel security segmentation for admin users.
+9 -3
View File
@@ -79,12 +79,18 @@ class Role extends Validator
$role = $value;
if (str_starts_with($value, "project-")) {
$parts = explode("-", $value);
if (\count($parts) !== 3) {
$prefix = "project-";
$rest = \substr($value, \strlen($prefix));
$lastDash = \strrpos($rest, '-');
if ($lastDash === false) {
return false;
}
$role = $parts[2];
$projectId = \substr($rest, 0, $lastDash);
$role = \substr($rest, $lastDash + 1);
if ($projectId === '' || $role === '') {
return false;
}
}
if (!\in_array($role, $this->roles)) {
@@ -73,17 +73,28 @@ class User extends Document
if ($projectId !== 'console') {
$roles[] = Role::team($node['teamId'])->toString(); // Populate team-wide base role.
} else {
$teamWideRoles = \array_filter($nodeRoles, fn ($role) => !str_starts_with($role, "project-"));
$projectRolePrefix = "project-";
$teamWideRoles = \array_filter($nodeRoles, fn ($role) => !str_starts_with($role, $projectRolePrefix));
$populateTeamWideRole = !str_starts_with($path, "/v1/projects") || !empty($teamWideRoles);
if ($populateTeamWideRole) {
$roles[] = Role::team($node['teamId'])->toString(); // Populate team-wide base role.
}
$projectSpecificRoles = \array_filter($nodeRoles, fn ($role) => str_starts_with($role, "project-"));
$projectSpecificRoles = \array_filter($nodeRoles, fn ($role) => str_starts_with($role, $projectRolePrefix));
foreach ($projectSpecificRoles as $projectRole) {
$parts = explode("-", $projectRole);
$roles[] = Role::team($node['teamId'], "$parts[0]-$parts[1]")->toString(); // Populate project-wide base role.
$rest = \substr($projectRole, \strlen($projectRolePrefix));
$lastDash = \strrpos($rest, '-');
if ($lastDash === false) {
continue;
}
$projectId = \substr($rest, 0, $lastDash);
if ($projectId === '') {
continue;
}
$roles[] = Role::team($node['teamId'], "{$projectRolePrefix}{$projectId}")->toString(); // Populate project-wide base role.
}
}