-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: grant/revoke ADMIN role (#111)
- Loading branch information
1 parent
4fe7ca0
commit dfb0fdc
Showing
18 changed files
with
179 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,6 +25,7 @@ | |
import org.projectcheckins.security.forms.TeamMemberDelete; | ||
import org.projectcheckins.security.forms.TeamMemberSave; | ||
import org.projectcheckins.security.forms.TeamInvitationDelete; | ||
import org.projectcheckins.security.forms.TeamMemberUpdate; | ||
import org.projectcheckins.security.services.TeamService; | ||
import org.projectcheckins.security.services.TeamServiceImpl; | ||
import org.projectcheckins.security.TeamInvitationRecord; | ||
|
@@ -53,6 +54,7 @@ class TeamControllerTest { | |
static final String URI_SAVE = UriBuilder.of("/team").path("save").build().toString(); | ||
static final String URI_DELETE = UriBuilder.of("/team").path("delete").build().toString(); | ||
static final String URI_UNINVITE = UriBuilder.of("/team").path("uninvite").build().toString(); | ||
static final String URI_UPDATE = UriBuilder.of("/team").path("update").build().toString(); | ||
|
||
static final PublicProfile USER_1 = new PublicProfileRecord( | ||
"user1", | ||
|
@@ -125,6 +127,12 @@ void testListTeamMembers(@Client("/") HttpClient httpClient) { | |
.satisfies(htmlPage()) | ||
.satisfies(htmlBody(""" | ||
<span>User One</span>""")) | ||
.satisfies(htmlBody(""" | ||
<form action="/team/delete" method="post">""")) | ||
.satisfies(htmlBody(""" | ||
<form action="/team/update" method="post">""")) | ||
.satisfies(htmlBody("Revoke Admin privileges")) | ||
.satisfies(htmlBody("Grant Admin privileges")) | ||
.satisfies(htmlBody(""" | ||
<code>[email protected]</code>""")) | ||
.satisfies(htmlBody(""" | ||
|
@@ -143,10 +151,17 @@ void testListTeamMembersNonAdmin(@Client("/") HttpClient httpClient) { | |
<span>User One</span>""")) | ||
.satisfies(htmlBody(""" | ||
<code>[email protected]</code>""")) | ||
.satisfies(htmlBody(body -> Assertions.assertThat(body).doesNotContain(""" | ||
<code>[email protected]</code>"""))) | ||
.satisfies(htmlBody(body -> Assertions.assertThat(body).doesNotContain(""" | ||
<a href="/team/create">"""))); | ||
.satisfies(htmlBody(body -> Assertions.assertThat(body) | ||
.doesNotContain("<code>[email protected]</code>") | ||
.doesNotContain(""" | ||
<form action="/team/delete" method="post">""") | ||
.doesNotContain(""" | ||
<form action="/team/update" method="post">""") | ||
.doesNotContain(""" | ||
<a href="/team/create">""") | ||
.doesNotContain("Revoke Admin privileges") | ||
.doesNotContain("Grant Admin privileges") | ||
)); | ||
} | ||
|
||
@Test | ||
|
@@ -260,6 +275,16 @@ void testRemoveTeamMemberNonAdmin(@Client("/") HttpClient httpClient) { | |
.satisfies(redirection("/unauthorized")); | ||
} | ||
|
||
@Test | ||
void testMemberUpdate(@Client("/") HttpClient httpClient) { | ||
final BlockingHttpClient client = httpClient.toBlocking(); | ||
authMock.setAuthentication(AbstractAuthenticationFetcher.ADMIN); | ||
final Map<String, Object> body = Map.of("email", "[email protected]", "isAdmin", true); | ||
final HttpRequest<?> request = BrowserRequest.POST(URI_UPDATE, body); | ||
Assertions.assertThat(client.exchange(request, String.class)) | ||
.satisfies(redirection(URI_LIST)); | ||
} | ||
|
||
@Requires(property = "spec.name", value = "TeamControllerTest") | ||
@Singleton | ||
static class AuthenticationFetcherMock extends AbstractAuthenticationFetcher { | ||
|
@@ -313,6 +338,9 @@ public void remove(@NotNull @Valid TeamMemberDelete form, @Nullable Tenant tenan | |
public void uninvite(@NotNull @Valid TeamInvitationDelete form, @Nullable Tenant tenant) { | ||
|
||
} | ||
|
||
@Override | ||
public void update(@NotNull @Valid TeamMemberUpdate form, @Nullable Tenant tenant) {} | ||
} | ||
|
||
record PublicProfileRecord(String id, String email, String fullName, boolean isAdmin) implements PublicProfile { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
security/src/main/java/org/projectcheckins/security/UserRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,19 @@ | ||
package org.projectcheckins.security; | ||
|
||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.core.annotation.Nullable; | ||
import io.micronaut.multitenancy.Tenant; | ||
import jakarta.validation.constraints.Email; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
import java.util.List; | ||
|
||
public interface UserRepository { | ||
boolean existsByEmail(@NotBlank @Email String email, @Nullable Tenant tenant); | ||
|
||
void deleteByEmail(@NotBlank @Email String email, @Nullable Tenant tenant); | ||
|
||
void updateAuthorities(@NotBlank @Email String email, | ||
@NonNull List<String> authorities, | ||
@Nullable Tenant tenant); | ||
} |
9 changes: 9 additions & 0 deletions
9
security/src/main/java/org/projectcheckins/security/forms/TeamMemberUpdate.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.projectcheckins.security.forms; | ||
|
||
import io.micronaut.core.annotation.NonNull; | ||
import io.micronaut.serde.annotation.Serdeable; | ||
import io.micronaut.views.fields.annotations.InputHidden; | ||
import jakarta.validation.constraints.NotBlank; | ||
|
||
@Serdeable | ||
public record TeamMemberUpdate(@NonNull @NotBlank @InputHidden String email, @InputHidden boolean isAdmin) { } |
Oops, something went wrong.