Skip to content

Commit

Permalink
fix: task possible assignees (#2644)
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 authored Oct 30, 2024
1 parent 09b80ee commit 89b0000
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class TaskTestData : BaseTestData("tasksTestUser", "Project with tasks") {
var orgMember: UserAccountBuilder
var projectViewScopeUser: UserAccountBuilder
var projectViewRoleUser: UserAccountBuilder
var projectManageRoleUser: UserAccountBuilder
var translateTask: TaskBuilder
var reviewTask: TaskBuilder
var relatedProject: ProjectBuilder
Expand Down Expand Up @@ -64,6 +65,12 @@ class TaskTestData : BaseTestData("tasksTestUser", "Project with tasks") {
name = "Project view role user (en)"
}

projectManageRoleUser =
root.addUserAccount {
username = "[email protected]"
name = "Project manage role user (en)"
}

userAccountBuilder.defaultOrganizationBuilder.apply {
addRole {
user = orgMember.self
Expand Down Expand Up @@ -91,6 +98,11 @@ class TaskTestData : BaseTestData("tasksTestUser", "Project with tasks") {
type = ProjectPermissionType.EDIT
}

addPermission {
user = projectManageRoleUser.self
type = ProjectPermissionType.MANAGE
}

addPermission {
user = projectViewScopeUser.self
scopes = arrayOf(Scope.TRANSLATIONS_VIEW)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,25 @@ enum class ProjectPermissionType(val availableScopes: Array<Scope>) {
;

companion object {
private fun expandAvailableScopes(permission: ProjectPermissionType): Array<Scope> {
val result = mutableSetOf<Scope>()
permission.availableScopes.forEach {
result.add(it)
it.expand().forEach { scope ->
result.add(scope)
}
}
return result.toTypedArray()
}

fun getRoles(): Map<String, Array<Scope>> {
val result = mutableMapOf<String, Array<Scope>>()
values().forEach { value -> result[value.name] = value.availableScopes }
values().forEach { value -> result[value.name] = expandAvailableScopes(value) }
return result.toMap()
}

fun findByScope(scope: Scope): List<ProjectPermissionType> {
return values().filter { it.availableScopes.contains(scope) }
return values().filter { expandAvailableScopes(it).contains(scope) }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class TaskControllerAssigneesTest : ProjectAuthControllerTest("/v2/projects/") {
node("_embedded.users").isArray.anySatisfy {
(it as JsonMap).get("name").assert.isEqualTo("Project view role user (en)")
}
node("_embedded.users").isArray.anySatisfy {
(it as JsonMap).get("name").assert.isEqualTo("Project manage role user (en)")
}
node("_embedded.users").isArray.anySatisfy {
(it as JsonMap).get("name").assert.isEqualTo("Organization member")
}
Expand Down

0 comments on commit 89b0000

Please sign in to comment.