Skip to content

Commit

Permalink
πŸ”’ : add updatable isAdmin flag
Browse files Browse the repository at this point in the history
  • Loading branch information
juwit committed Dec 28, 2020
1 parent d8fe174 commit 685db79
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/main/java/io/gaia_app/teams/bo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ data class User(
@Id val username: String,
@DBRef val team: Team?) {

val isAdmin: Boolean
get() = "admin" == this.username
var isAdmin: Boolean = false

var oAuth2User: OAuth2User? = null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import io.gaia_app.teams.Team
import io.gaia_app.teams.User
import io.gaia_app.test.whenever
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
Expand All @@ -30,7 +31,13 @@ class DashboardRestControllerTest {
@Nested
inner class WhenAdminUserTest {

private val user = User("admin", null)
private lateinit var user: User

@BeforeEach
internal fun setUp() {
user = User("admin", null)
user.isAdmin = true
}

@Test
fun `summary() should return modules count`() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class TerraformModuleTest {
void module_shouldBeAuthorized_forAdminUser(){
// given
var admin = new User("admin", null);
admin.setAdmin(true);
var module = new TerraformModule();

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ModuleRestControllerTest {
@BeforeEach
void setUp() {
admin = new User("admin", null);
admin.setAdmin(true);

john = new User("John Dorian", null);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import io.gaia_app.modules.bo.TerraformImage;
import io.gaia_app.modules.bo.TerraformModule;
import io.gaia_app.stacks.bo.Stack;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
Expand Down Expand Up @@ -63,6 +64,11 @@ class StackRestControllerTest {
@Mock
private CredentialsRepository credentialsRepository;

@BeforeEach
void setUp() {
adminUser.setAdmin(true);
}

@Test
void listStack_shouldFindAllStacks_forAdminUser() {
// when
Expand Down
3 changes: 2 additions & 1 deletion src/test/resources/db/10_user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ gaia.user.drop();
gaia.user.insert([
{
"_id": "admin",
"team": {"$ref": "team", "$id": "Ze Team"}
"team": {"$ref": "team", "$id": "Ze Team"},
"isAdmin": true
},
{
"_id": "Mary J",
Expand Down

0 comments on commit 685db79

Please sign in to comment.