Notification if external user management is activated

A notification will be displayed when an external user
management system is activated to inform that users
created within the SCMM will not be transferred to the
external system.

Co-authored-by: René Pfeuffer<rene.pfeuffer@cloudogu.com>
This commit is contained in:
Laura Gorzitze
2024-07-04 09:05:17 +02:00
parent 1c57342cd9
commit b12f4d579a
14 changed files with 146 additions and 27 deletions

View File

@@ -0,0 +1,2 @@
- type: added
description: Notification when external user management is activated during user creation

View File

@@ -0,0 +1,32 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.user;
import sonia.scm.plugin.ExtensionPoint;
@ExtensionPoint
public interface ExternalAuthenticationAvailableNotifier {
boolean isExternalAuthenticationAvailable();
}

View File

@@ -37,6 +37,7 @@ import org.eclipse.jgit.lib.ObjectReader;
import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.treewalk.CanonicalTreeParser; import org.eclipse.jgit.treewalk.CanonicalTreeParser;
import org.eclipse.jgit.treewalk.filter.PathFilter; import org.eclipse.jgit.treewalk.filter.PathFilter;
import sonia.scm.NotFoundException;
import sonia.scm.repository.GitRepositoryHandler; import sonia.scm.repository.GitRepositoryHandler;
import sonia.scm.repository.GitWorkingCopyFactory; import sonia.scm.repository.GitWorkingCopyFactory;
import sonia.scm.repository.InternalRepositoryException; import sonia.scm.repository.InternalRepositoryException;
@@ -107,7 +108,7 @@ public class GitMergeCommand extends AbstractGitCommand implements MergeCommand
throw new MergeStrategyNotSupportedException(repository, request.getMergeStrategy()); throw new MergeStrategyNotSupportedException(repository, request.getMergeStrategy());
} }
} }
@Override @Override
public MergeDryRunCommandResult dryRun(MergeCommandRequest request) { public MergeDryRunCommandResult dryRun(MergeCommandRequest request) {
try (Repository repository = context.open()) { try (Repository repository = context.open()) {

View File

@@ -72,6 +72,7 @@ describe("Test user hooks", () => {
_embedded: { _embedded: {
users: [yoda], users: [yoda],
}, },
externalAuthenticationAvailable: false,
}; };
afterEach(() => { afterEach(() => {

View File

@@ -47,7 +47,9 @@ export type UserCreation = User;
export type UserCollection = PagedCollection<{ export type UserCollection = PagedCollection<{
users: User[]; users: User[];
}>; }> & {
externalAuthenticationAvailable: boolean;
};
export type PermissionOverview = HalRepresentation & { export type PermissionOverview = HalRepresentation & {
relevantGroups: PermissionOverviewGroupEntry[]; relevantGroups: PermissionOverviewGroupEntry[];

View File

@@ -50,6 +50,7 @@
"createUser": { "createUser": {
"title": "Benutzer erstellen", "title": "Benutzer erstellen",
"subtitle": "Erstellen eines neuen Benutzers", "subtitle": "Erstellen eines neuen Benutzers",
"notification": "Ein externes Benutzerverwaltungssystem ist aktiviert. Die hier angelegten Benutzer werden nicht in die externe Benutzerverwaltung übertragen.",
"form": { "form": {
"submit": "Speichern", "submit": "Speichern",
"submit-success-notification": "Der Benutzer wurde erfolgreich aktualisiert", "submit-success-notification": "Der Benutzer wurde erfolgreich aktualisiert",

View File

@@ -50,6 +50,7 @@
"createUser": { "createUser": {
"title": "Create User", "title": "Create User",
"subtitle": "Create a new user", "subtitle": "Create a new user",
"notification": "An external user management system is activated. Users created here will not be transferred to the external user management.",
"form": { "form": {
"submit": "Submit", "submit": "Submit",
"submit-success-notification": "The user was updated successfully", "submit-success-notification": "The user was updated successfully",

View File

@@ -24,21 +24,21 @@
import React, { FC, useRef } from "react"; import React, { FC, useRef } from "react";
import { Redirect } from "react-router-dom"; import { Redirect } from "react-router-dom";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useRequiredIndexLink } from "@scm-manager/ui-api";
import { Page } from "@scm-manager/ui-components"; import { Page } from "@scm-manager/ui-components";
import { Form, useCreateResource } from "@scm-manager/ui-forms"; import { Form, useCreateResource } from "@scm-manager/ui-forms";
import * as userValidator from "../components/userValidation"; import * as userValidator from "../components/userValidation";
import { User, UserCreation } from "@scm-manager/ui-types"; import { Link, User, UserCollection, UserCreation } from "@scm-manager/ui-types";
import { ErrorNotification, Loading, Notification } from "@scm-manager/ui-core";
import { useUsers } from "@scm-manager/ui-api";
type UserCreationForm = Pick<UserCreation, "password" | "name" | "displayName" | "active" | "external" | "mail"> & { type UserCreationForm = Pick<UserCreation, "password" | "name" | "displayName" | "active" | "external" | "mail"> & {
passwordConfirmation: string; passwordConfirmation: string;
}; };
const CreateUser: FC = () => { const CreateUserForm: FC<{ users: UserCollection }> = ({ users }) => {
const [t] = useTranslation("users"); const [t] = useTranslation("users");
const indexLink = useRequiredIndexLink("users");
const { submit, submissionResult: createdUser } = useCreateResource<UserCreationForm, User>( const { submit, submissionResult: createdUser } = useCreateResource<UserCreationForm, User>(
indexLink, (users._links.create as Link).href,
["user", "users"], ["user", "users"],
(user) => user.name, (user) => user.name,
{ {
@@ -61,6 +61,9 @@ const CreateUser: FC = () => {
return ( return (
<Page title={t("createUser.title")} subtitle={t("createUser.subtitle")} showContentOnError={true}> <Page title={t("createUser.title")} subtitle={t("createUser.subtitle")} showContentOnError={true}>
{users.externalAuthenticationAvailable && (
<Notification type="warning">{t("createUser.notification")}</Notification>
)}
<Form onSubmit={submit} translationPath={["users", "createUser.form"]} defaultValues={defaultValuesRef.current}> <Form onSubmit={submit} translationPath={["users", "createUser.form"]} defaultValues={defaultValuesRef.current}>
{({ watch }) => ( {({ watch }) => (
<> <>
@@ -114,4 +117,17 @@ const CreateUser: FC = () => {
); );
}; };
const CreateUser: FC = () => {
const { data: users, isLoading, error } = useUsers({ page: 0 });
if (isLoading) {
return <Loading />;
}
if (error) {
return <ErrorNotification error={error} />;
}
return <CreateUserForm users={users!} />;
};
export default CreateUser; export default CreateUser;

View File

@@ -26,15 +26,8 @@ import { Redirect, useLocation, useParams } from "react-router-dom";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useUsers } from "@scm-manager/ui-api"; import { useUsers } from "@scm-manager/ui-api";
import { User, UserCollection } from "@scm-manager/ui-types"; import { User, UserCollection } from "@scm-manager/ui-types";
import { import { CreateButton, LinkPaginator, OverviewPageActions, Page, PageActions, urls } from "@scm-manager/ui-components";
CreateButton, import { Notification } from "@scm-manager/ui-core";
LinkPaginator,
Notification,
OverviewPageActions,
Page,
PageActions,
urls,
} from "@scm-manager/ui-components";
import { UserTable } from "./../components/table"; import { UserTable } from "./../components/table";
type UserPageProps = { type UserPageProps = {

View File

@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
package sonia.scm.api.v2.resources; package sonia.scm.api.v2.resources;
import de.otto.edison.hal.Embedded; import de.otto.edison.hal.Embedded;
@@ -55,14 +55,18 @@ abstract class PagedCollectionToDtoMapper<E extends ModelObject, D extends HalRe
CollectionDto map(int pageNumber, int pageSize, PageResult<E> pageResult, String selfLink, Optional<String> createLink, Function<E, ? extends HalRepresentation> mapper) { CollectionDto map(int pageNumber, int pageSize, PageResult<E> pageResult, String selfLink, Optional<String> createLink, Function<E, ? extends HalRepresentation> mapper) {
NumberedPaging paging = zeroBasedNumberedPaging(pageNumber, pageSize, pageResult.getOverallCount()); NumberedPaging paging = zeroBasedNumberedPaging(pageNumber, pageSize, pageResult.getOverallCount());
List<HalRepresentation> dtos = pageResult.getEntities().stream().map(mapper).collect(toList()); List<HalRepresentation> dtos = pageResult.getEntities().stream().map(mapper).collect(toList());
CollectionDto collectionDto = new CollectionDto( Links links = createLinks(paging, selfLink, createLink);
createLinks(paging, selfLink, createLink), Embedded embedded = embedDtos(dtos);
embedDtos(dtos)); CollectionDto collectionDto = createCollectionDto(links, embedded);
collectionDto.setPage(pageNumber); collectionDto.setPage(pageNumber);
collectionDto.setPageTotal(computePageTotal(pageSize, pageResult)); collectionDto.setPageTotal(computePageTotal(pageSize, pageResult));
return collectionDto; return collectionDto;
} }
CollectionDto createCollectionDto(Links links, Embedded embedded) {
return new CollectionDto(links, embedded);
}
private int computePageTotal(int pageSize, PageResult<E> pageResult) { private int computePageTotal(int pageSize, PageResult<E> pageResult) {
if (pageResult.getOverallCount() % pageSize > 0) { if (pageResult.getOverallCount() % pageSize > 0) {
return pageResult.getOverallCount() / pageSize + 1; return pageResult.getOverallCount() / pageSize + 1;

View File

@@ -0,0 +1,40 @@
/*
* MIT License
*
* Copyright (c) 2020-present Cloudogu GmbH and Contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package sonia.scm.api.v2.resources;
import de.otto.edison.hal.Embedded;
import de.otto.edison.hal.Links;
import lombok.Getter;
@Getter
class UserCollectionDto extends CollectionDto {
private final boolean externalAuthenticationAvailable;
UserCollectionDto(Links links, Embedded embedded, boolean externalAuthenticationAvailable) {
super(links, embedded);
this.externalAuthenticationAvailable = externalAuthenticationAvailable;
}
}

View File

@@ -21,15 +21,19 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE. * SOFTWARE.
*/ */
package sonia.scm.api.v2.resources; package sonia.scm.api.v2.resources;
import de.otto.edison.hal.Embedded;
import de.otto.edison.hal.Links;
import jakarta.inject.Inject; import jakarta.inject.Inject;
import sonia.scm.PageResult; import sonia.scm.PageResult;
import sonia.scm.user.ExternalAuthenticationAvailableNotifier;
import sonia.scm.user.User; import sonia.scm.user.User;
import sonia.scm.user.UserPermissions; import sonia.scm.user.UserPermissions;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import static java.util.Optional.empty; import static java.util.Optional.empty;
import static java.util.Optional.of; import static java.util.Optional.of;
@@ -38,10 +42,13 @@ public class UserCollectionToDtoMapper extends BasicCollectionToDtoMapper<User,
private final ResourceLinks resourceLinks; private final ResourceLinks resourceLinks;
private final Set<ExternalAuthenticationAvailableNotifier> externalAuthenticationAvailableNotifier;
@Inject @Inject
public UserCollectionToDtoMapper(UserToUserDtoMapper userToDtoMapper, ResourceLinks resourceLinks) { public UserCollectionToDtoMapper(UserToUserDtoMapper userToDtoMapper, ResourceLinks resourceLinks, Set<ExternalAuthenticationAvailableNotifier> externalAuthenticationAvailableNotifier) {
super("users", userToDtoMapper); super("users", userToDtoMapper);
this.resourceLinks = resourceLinks; this.resourceLinks = resourceLinks;
this.externalAuthenticationAvailableNotifier = externalAuthenticationAvailableNotifier;
} }
public CollectionDto map(int pageNumber, int pageSize, PageResult<User> pageResult) { public CollectionDto map(int pageNumber, int pageSize, PageResult<User> pageResult) {
@@ -49,10 +56,27 @@ public class UserCollectionToDtoMapper extends BasicCollectionToDtoMapper<User,
} }
Optional<String> createCreateLink() { Optional<String> createCreateLink() {
return UserPermissions.create().isPermitted() ? of(resourceLinks.userCollection().create()): empty(); return UserPermissions.create().isPermitted() ? of(resourceLinks.userCollection().create()) : empty();
} }
String createSelfLink() { String createSelfLink() {
return resourceLinks.userCollection().self(); return resourceLinks.userCollection().self();
} }
@Override
CollectionDto createCollectionDto(Links links, Embedded embedded) {
return new UserCollectionDto(links, embedded, isExternalAuthenticationAvailable());
}
boolean isExternalAuthenticationAvailable() {
for (ExternalAuthenticationAvailableNotifier externalAuthenticationAvailable : externalAuthenticationAvailableNotifier) {
if (externalAuthenticationAvailable.isExternalAuthenticationAvailable()) {
return true;
}
}
return false;
}
} }

View File

@@ -40,6 +40,7 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set;
import static java.util.stream.Collectors.toList; import static java.util.stream.Collectors.toList;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@@ -58,14 +59,14 @@ public class UserCollectionToDtoMapperTest {
@InjectMocks @InjectMocks
private SubjectThreadState subjectThreadState; private SubjectThreadState subjectThreadState;
@InjectMocks
private UserCollectionToDtoMapper mapper;
private URI expectedBaseUri; private URI expectedBaseUri;
private UserCollectionToDtoMapper mapper;
@Before @Before
public void init() throws URISyntaxException { public void init() throws URISyntaxException {
initMocks(this); initMocks(this);
mapper = new UserCollectionToDtoMapper(userToDtoMapper, resourceLinks, Set.of());
expectedBaseUri = baseUri.resolve(UserRootResource.USERS_PATH_V2 + "/"); expectedBaseUri = baseUri.resolve(UserRootResource.USERS_PATH_V2 + "/");
subjectThreadState.bind(); subjectThreadState.bind();
ThreadContext.bind(subject); ThreadContext.bind(subject);

View File

@@ -63,6 +63,7 @@ import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.net.URL; import java.net.URL;
import java.util.Collection; import java.util.Collection;
import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import static de.otto.edison.hal.Links.emptyLinks; import static de.otto.edison.hal.Links.emptyLinks;
@@ -149,7 +150,7 @@ public class UserRootResourceTest {
doNothing().when(userManager).delete(userCaptor.capture()); doNothing().when(userManager).delete(userCaptor.capture());
when(userManager.getDefaultType()).thenReturn("xml"); when(userManager.getDefaultType()).thenReturn("xml");
UserCollectionToDtoMapper userCollectionToDtoMapper = new UserCollectionToDtoMapper(userToDtoMapper, resourceLinks); UserCollectionToDtoMapper userCollectionToDtoMapper = new UserCollectionToDtoMapper(userToDtoMapper, resourceLinks, Set.of());
UserCollectionResource userCollectionResource = new UserCollectionResource(userManager, dtoToUserMapper, UserCollectionResource userCollectionResource = new UserCollectionResource(userManager, dtoToUserMapper,
userCollectionToDtoMapper, resourceLinks, passwordService); userCollectionToDtoMapper, resourceLinks, passwordService);
UserPermissionResource userPermissionResource = new UserPermissionResource(permissionAssigner, permissionCollectionToDtoMapper); UserPermissionResource userPermissionResource = new UserPermissionResource(permissionAssigner, permissionCollectionToDtoMapper);