From 3efe23e74df5f5179e242e4ac1d97fa76c3ba3ee Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Tue, 13 Oct 2020 16:33:05 +0200 Subject: [PATCH] Add external flag to user config --- .../src/main/java/sonia/scm/user/User.java | 449 +++--------------- scm-ui/ui-types/src/User.ts | 1 + scm-ui/ui-webapp/public/locales/de/users.json | 4 +- scm-ui/ui-webapp/public/locales/en/users.json | 4 +- .../src/users/components/UserForm.tsx | 35 +- .../src/users/components/table/Details.tsx | 6 + .../sonia/scm/api/v2/resources/UserDto.java | 1 + 7 files changed, 109 insertions(+), 391 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/user/User.java b/scm-core/src/main/java/sonia/scm/user/User.java index 3379041100..3f0898d348 100644 --- a/scm-core/src/main/java/sonia/scm/user/User.java +++ b/scm-core/src/main/java/sonia/scm/user/User.java @@ -24,12 +24,14 @@ package sonia.scm.user; -//~--- non-JDK imports -------------------------------------------------------- - import com.github.sdorra.ssp.PermissionObject; import com.github.sdorra.ssp.StaticPermissions; import com.google.common.base.MoreObjects; import com.google.common.base.Objects; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; import sonia.scm.BasicPropertiesAware; import sonia.scm.ModelObject; import sonia.scm.ReducedModelObject; @@ -41,12 +43,6 @@ import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import java.security.Principal; -//~--- JDK imports ------------------------------------------------------------ - -/** - * - * @author Sebastian Sdorra - */ @StaticPermissions( value = "user", globalPermissions = {"create", "list", "autocomplete"}, @@ -55,57 +51,36 @@ import java.security.Principal; ) @XmlRootElement(name = "users") @XmlAccessorType(XmlAccessType.FIELD) -public class User extends BasicPropertiesAware implements Principal, ModelObject, PermissionObject, ReducedModelObject -{ +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +public class User extends BasicPropertiesAware implements Principal, ModelObject, PermissionObject, ReducedModelObject { - /** Field description */ private static final long serialVersionUID = -3089541936726329663L; - //~--- constructors --------------------------------------------------------- + private boolean active = true; + private boolean external; + private Long creationDate; + private String displayName; + private Long lastModified; + private String mail; + private String name; + private String password; + private String type; - /** - * Constructs ... - * - */ - public User() {} - - /** - * Constructs ... - * - * - * @param name - */ - public User(String name) - { + public User(String name) { this.name = name; this.displayName = name; } - /** - * Constructs ... - * - * - * @param name - * @param displayName - * @param mail - */ - public User(String name, String displayName, String mail) - { + public User(String name, String displayName, String mail) { this.name = name; this.displayName = displayName; this.mail = mail; } - /** - * Constructs ... - * - * - * @param name - * @param displayName - * @param mail - */ - public User(String name, String displayName, String mail, String password, String type, boolean active) - { + public User(String name, String displayName, String mail, String password, String type, boolean active) { this.name = name; this.displayName = displayName; this.mail = mail; @@ -114,90 +89,57 @@ public class User extends BasicPropertiesAware implements Principal, ModelObject this.active = active; } - //~--- methods -------------------------------------------------------------- - - /** - * Method description - * - * - * @return - * - */ @Override - public User clone() - { - User user = null; + public User clone() { + User user; - try - { + try { user = (User) super.clone(); - } - catch (CloneNotSupportedException ex) - { + } catch (CloneNotSupportedException ex) { throw new RuntimeException(ex); } return user; } - /** - * Method description - * - * - * @param user - * - * @return - */ - public boolean copyProperties(User user) - { + public boolean copyProperties(User user) { return copyProperties(user, true); } - /** - * Method description - * - * - * @param user - * @param copyPassword - * - * @return - */ - public boolean copyProperties(User user, boolean copyPassword) - { + public boolean copyProperties(User user, boolean copyPassword) { boolean result = false; - if (user.isActive() != active) - { + if (user.isActive() != active) { result = true; user.setActive(active); } - if (Util.isNotEquals(user.getDisplayName(), displayName)) - { + if (user.isExternal() != external) { + result = true; + user.setExternal(external); + } + + if (Util.isNotEquals(user.getDisplayName(), displayName)) { result = true; user.setDisplayName(displayName); } - if (Util.isNotEquals(user.getMail(), mail)) - { + if (Util.isNotEquals(user.getMail(), mail)) { result = true; user.setMail(mail); } - if (Util.isNotEquals(user.getName(), name)) - { + if (Util.isNotEquals(user.getName(), name)) { result = true; user.setName(name); } - if (copyPassword && Util.isNotEquals(user.getPassword(), password)) - { + if (copyPassword && Util.isNotEquals(user.getPassword(), password)) { result = true; user.setPassword(password); } - if (Util.isNotEquals(user.getType(), type)) - { + if (Util.isNotEquals(user.getType(), type)) { result = true; user.setType(type); } @@ -205,316 +147,65 @@ public class User extends BasicPropertiesAware implements Principal, ModelObject return result; } - /** - * {@inheritDoc} - * - * - * @param obj - * - * @return - */ @Override - public boolean equals(Object obj) - { - if (obj == null) - { + public boolean equals(Object obj) { + if (obj == null) { return false; } - if (getClass() != obj.getClass()) - { + if (getClass() != obj.getClass()) { return false; } final User other = (User) obj; return Objects.equal(name, other.name) - && Objects.equal(displayName, other.displayName) - && Objects.equal(mail, other.mail) - && Objects.equal(type, other.type) - && Objects.equal(active, other.active) - && Objects.equal(password, other.password) - && Objects.equal(creationDate, other.creationDate) - && Objects.equal(lastModified, other.lastModified) - && Objects.equal(properties, other.properties); + && Objects.equal(displayName, other.displayName) + && Objects.equal(mail, other.mail) + && Objects.equal(type, other.type) + && Objects.equal(active, other.active) + && Objects.equal(password, other.password) + && Objects.equal(creationDate, other.creationDate) + && Objects.equal(lastModified, other.lastModified) + && Objects.equal(properties, other.properties); } - /** - * {@inheritDoc} - * - * - * @return - */ @Override - public int hashCode() - { + public int hashCode() { return Objects.hashCode(name, displayName, mail, type, password, - active, creationDate, lastModified, properties); + active, creationDate, lastModified, properties); } - /** - * {@inheritDoc} - * - * - * @return - */ @Override - public String toString() - { + public String toString() { String pwd = (password != null) - ? "(is set)" - : "(not set)"; + ? "(is set)" + : "(not set)"; //J- return MoreObjects.toStringHelper(this) - .add("name", name) - .add("displayName",displayName) - .add("mail", mail) - .add("password", pwd) - .add("type", type) - .add("active", active) - .add("creationDate", creationDate) - .add("lastModified", lastModified) - .add("properties", properties) - .toString(); + .add("name", name) + .add("displayName", displayName) + .add("mail", mail) + .add("password", pwd) + .add("type", type) + .add("active", active) + .add("creationDate", creationDate) + .add("lastModified", lastModified) + .add("properties", properties) + .toString(); //J+ } - //~--- get methods ---------------------------------------------------------- - - /** - * Method description - * - * - * @return - */ - public Long getCreationDate() - { - return creationDate; - } - - /** - * Method description - * - * - * @return - */ - public String getDisplayName() - { - return displayName; - } - - /** - * Method description - * - * - * @return - */ @Override - public String getId() - { - return name; - } - - /** - * Method description - * - * - * @return - */ - @Override - public Long getLastModified() - { - return lastModified; - } - - /** - * Method description - * - * - * @return - */ - public String getMail() - { - return mail; - } - - /** - * Method description - * - * - * @return - */ - @Override - public String getName() - { - return name; - } - - /** - * Method description - * - * - * @return - */ - public String getPassword() - { - return password; - } - - /** - * Method description - * - * - * @return - */ - @Override - public String getType() - { - return type; - } - - /** - * Returns false if the user is deactivated. - * - * - * @return false if the user is deactivated - * @since 1.16 - */ - public boolean isActive() - { - return active; - } - - /** - * Method description - * - * - * @return - */ - @Override - public boolean isValid() - { + public boolean isValid() { return ValidationUtil.isNameValid(name) && Util.isNotEmpty(displayName) - && Util.isNotEmpty(type) - && ((Util.isEmpty(mail)) || ValidationUtil.isMailAddressValid(mail)); + && Util.isNotEmpty(type) + && ((Util.isEmpty(mail)) || ValidationUtil.isMailAddressValid(mail)); } - //~--- set methods ---------------------------------------------------------- - - /** - * Activate or deactive this user. - * - * - * @param active false to deactivate the user. - * @since 1.6 - */ - public void setActive(boolean active) - { - this.active = active; + @Override + public String getId() { + return name; } - - /** - * Method description - * - * - * @param creationDate - */ - public void setCreationDate(Long creationDate) - { - this.creationDate = creationDate; - } - - /** - * Method description - * - * - * @param displayName - */ - public void setDisplayName(String displayName) - { - this.displayName = displayName; - } - - /** - * Method description - * - * - * @param lastModified - */ - public void setLastModified(Long lastModified) - { - this.lastModified = lastModified; - } - - /** - * Method description - * - * - * @param mail - */ - public void setMail(String mail) - { - this.mail = mail; - } - - /** - * Method description - * - * - * - * @param name - */ - public void setName(String name) - { - this.name = name; - } - - /** - * Method description - * - * - * @param password - */ - public void setPassword(String password) - { - this.password = password; - } - - /** - * Method description - * - * - * @param type - */ - public void setType(String type) - { - this.type = type; - } - - //~--- fields --------------------------------------------------------------- - - /** Field description */ - private boolean active = true; - - /** Field description */ - private Long creationDate; - - /** Field description */ - private String displayName; - - /** Field description */ - private Long lastModified; - - /** Field description */ - private String mail; - - /** Field description */ - private String name; - - /** Field description */ - private String password; - - /** Field description */ - private String type; } diff --git a/scm-ui/ui-types/src/User.ts b/scm-ui/ui-types/src/User.ts index 43ff64b9fa..14205ec9a1 100644 --- a/scm-ui/ui-types/src/User.ts +++ b/scm-ui/ui-types/src/User.ts @@ -39,5 +39,6 @@ export type User = { type?: string; creationDate?: string; lastModified?: string; + external?: boolean; _links: Links; }; diff --git a/scm-ui/ui-webapp/public/locales/de/users.json b/scm-ui/ui-webapp/public/locales/de/users.json index 0daa4b5c9a..feaf75441f 100644 --- a/scm-ui/ui-webapp/public/locales/de/users.json +++ b/scm-ui/ui-webapp/public/locales/de/users.json @@ -6,6 +6,7 @@ "password": "Passwort", "active": "Aktiv", "inactive": "Inaktiv", + "externalFlag": "Extern", "type": "Typ", "creationDate": "Erstellt", "lastModified": "Zuletzt bearbeitet" @@ -20,7 +21,8 @@ "displayNameHelpText": "Anzeigename des Benutzers", "mailHelpText": "E-Mail Adresse des Benutzers", "adminHelpText": "Ein Administrator kann Repositories, Gruppen und Benutzer erstellen, bearbeiten und löschen.", - "activeHelpText": "Aktivierung oder Deaktivierung eines Benutzers" + "activeHelpText": "Aktivierung oder Deaktivierung eines Benutzers", + "externalFlagHelpText": "Der Benutzer wird über ein Fremdsystem verwaltet." }, "users": { "title": "Benutzer", diff --git a/scm-ui/ui-webapp/public/locales/en/users.json b/scm-ui/ui-webapp/public/locales/en/users.json index 8effc6c589..661a7dd529 100644 --- a/scm-ui/ui-webapp/public/locales/en/users.json +++ b/scm-ui/ui-webapp/public/locales/en/users.json @@ -6,6 +6,7 @@ "password": "Password", "active": "Active", "inactive": "Inactive", + "externalFlag": "External", "type": "Type", "creationDate": "Creation Date", "lastModified": "Last Modified" @@ -20,7 +21,8 @@ "displayNameHelpText": "Display name of the user.", "mailHelpText": "Email address of the user.", "adminHelpText": "An administrator is able to create, modify and delete repositories, groups and users.", - "activeHelpText": "Activate or deactivate the user." + "activeHelpText": "Activate or deactivate the user.", + "externalFlagHelpText": "This user is managed by an external system." }, "users": { "title": "Users", diff --git a/scm-ui/ui-webapp/src/users/components/UserForm.tsx b/scm-ui/ui-webapp/src/users/components/UserForm.tsx index cd0856fa84..660d5d3d4f 100644 --- a/scm-ui/ui-webapp/src/users/components/UserForm.tsx +++ b/scm-ui/ui-webapp/src/users/components/UserForm.tsx @@ -60,6 +60,7 @@ class UserForm extends React.Component { mail: "", password: "", active: true, + external: false, _links: {} }, mailValidationError: false, @@ -80,14 +81,10 @@ class UserForm extends React.Component { } } - isFalsy(value) { - return !value; - } - createUserComponentsAreInvalid = () => { const user = this.state.user; if (!this.props.user) { - return this.state.nameValidationError || this.isFalsy(user.name) || !this.state.passwordValid; + return this.state.nameValidationError || !user.name || !this.state.passwordValid; } else { return false; } @@ -99,7 +96,8 @@ class UserForm extends React.Component { return ( this.props.user.displayName === user.displayName && this.props.user.mail === user.mail && - this.props.user.active === user.active + this.props.user.active === user.active && + this.props.user.external === user.external ); } else { return false; @@ -113,8 +111,8 @@ class UserForm extends React.Component { this.editUserComponentsAreUnchanged() || this.state.mailValidationError || this.state.displayNameValidationError || - this.isFalsy(user.displayName) || - this.isFalsy(user.mail) + !user.displayName || + !user.mail ); }; @@ -181,7 +179,7 @@ class UserForm extends React.Component { {passwordChangeField}
-
+
{ helpText={t("help.activeHelpText")} />
+
+ +
} /> @@ -232,7 +238,7 @@ class UserForm extends React.Component { ...this.state.user, password }, - passwordValid: !this.isFalsy(password) && passwordValid + passwordValid: !!password && passwordValid }); }; @@ -244,6 +250,15 @@ class UserForm extends React.Component { } }); }; + + handleExternalFlagChange = (external: boolean) => { + this.setState({ + user: { + ...this.state.user, + external + } + }); + }; } export default withTranslation("users")(UserForm); diff --git a/scm-ui/ui-webapp/src/users/components/table/Details.tsx b/scm-ui/ui-webapp/src/users/components/table/Details.tsx index 18df0cdf49..0ad3ae08d2 100644 --- a/scm-ui/ui-webapp/src/users/components/table/Details.tsx +++ b/scm-ui/ui-webapp/src/users/components/table/Details.tsx @@ -61,6 +61,12 @@ class Details extends React.Component { + + {t("user.externalFlag")} + + + + {t("user.type")} {user.type} diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserDto.java index 0e4e9b34c2..f4db619eb9 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/UserDto.java @@ -41,6 +41,7 @@ import java.time.Instant; @NoArgsConstructor @Getter @Setter public class UserDto extends HalRepresentation { private boolean active; + private boolean external; private Instant creationDate; @NotEmpty private String displayName;