mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 08:55:44 +01:00
apply eslint and prettier rules
This commit is contained in:
@@ -1,11 +1,6 @@
|
||||
import React from "react";
|
||||
import { User } from "@scm-manager/ui-types";
|
||||
import {
|
||||
SubmitButton,
|
||||
Notification,
|
||||
ErrorNotification,
|
||||
PasswordConfirmation
|
||||
} from "@scm-manager/ui-components";
|
||||
import { SubmitButton, Notification, ErrorNotification, PasswordConfirmation } from "@scm-manager/ui-components";
|
||||
import { translate } from "react-i18next";
|
||||
import { setPassword } from "./setPassword";
|
||||
|
||||
|
||||
@@ -67,11 +67,7 @@ class UserForm extends React.Component<Props, State> {
|
||||
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 || this.isFalsy(user.name) || !this.state.passwordValid;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -131,9 +127,7 @@ class UserForm extends React.Component<Props, State> {
|
||||
</div>
|
||||
);
|
||||
|
||||
passwordChangeField = (
|
||||
<PasswordConfirmation passwordChanged={this.handlePasswordChange} />
|
||||
);
|
||||
passwordChangeField = <PasswordConfirmation passwordChanged={this.handlePasswordChange} />;
|
||||
} else {
|
||||
// edit existing user
|
||||
subtitle = <Subtitle subtitle={t("userForm.subtitle")} />;
|
||||
@@ -178,11 +172,7 @@ class UserForm extends React.Component<Props, State> {
|
||||
</div>
|
||||
<div className="columns">
|
||||
<div className="column">
|
||||
<SubmitButton
|
||||
disabled={!this.isValid()}
|
||||
loading={loading}
|
||||
label={t("userForm.button")}
|
||||
/>
|
||||
<SubmitButton disabled={!this.isValid()} loading={loading} label={t("userForm.button")} />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -202,9 +192,7 @@ class UserForm extends React.Component<Props, State> {
|
||||
|
||||
handleDisplayNameChange = (displayName: string) => {
|
||||
this.setState({
|
||||
displayNameValidationError: !userValidator.isDisplayNameValid(
|
||||
displayName
|
||||
),
|
||||
displayNameValidationError: !userValidator.isDisplayNameValid(displayName),
|
||||
user: {
|
||||
...this.state.user,
|
||||
displayName
|
||||
|
||||
@@ -9,9 +9,7 @@ it("should render nothing, if the password link is missing", () => {
|
||||
_links: {}
|
||||
};
|
||||
|
||||
const navLink = shallow(
|
||||
<ChangePasswordNavLink user={user} passwordUrl="/user/password" />
|
||||
);
|
||||
const navLink = shallow(<ChangePasswordNavLink user={user} passwordUrl="/user/password" />);
|
||||
expect(navLink.text()).toBe("");
|
||||
});
|
||||
|
||||
@@ -24,8 +22,6 @@ it("should render the navLink", () => {
|
||||
}
|
||||
};
|
||||
|
||||
const navLink = shallow(
|
||||
<ChangePasswordNavLink user={user} passwordUrl="/user/password" />
|
||||
);
|
||||
const navLink = shallow(<ChangePasswordNavLink user={user} passwordUrl="/user/password" />);
|
||||
expect(navLink.text()).not.toBe("");
|
||||
});
|
||||
|
||||
@@ -16,12 +16,7 @@ class ChangePasswordNavLink extends React.Component<Props> {
|
||||
if (!this.hasPermissionToSetPassword()) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<NavLink
|
||||
to={passwordUrl}
|
||||
label={t("singleUser.menu.setPasswordNavLink")}
|
||||
/>
|
||||
);
|
||||
return <NavLink to={passwordUrl} label={t("singleUser.menu.setPasswordNavLink")} />;
|
||||
}
|
||||
|
||||
hasPermissionToSetPassword = () => {
|
||||
|
||||
@@ -9,9 +9,7 @@ it("should render nothing, if the permissions link is missing", () => {
|
||||
_links: {}
|
||||
};
|
||||
|
||||
const navLink = shallow(
|
||||
<SetPermissionsNavLink user={user} permissionsUrl="/user/permissions" />
|
||||
);
|
||||
const navLink = shallow(<SetPermissionsNavLink user={user} permissionsUrl="/user/permissions" />);
|
||||
expect(navLink.text()).toBe("");
|
||||
});
|
||||
|
||||
@@ -24,8 +22,6 @@ it("should render the navLink", () => {
|
||||
}
|
||||
};
|
||||
|
||||
const navLink = shallow(
|
||||
<SetPermissionsNavLink user={user} permissionsUrl="/user/permissions" />
|
||||
);
|
||||
const navLink = shallow(<SetPermissionsNavLink user={user} permissionsUrl="/user/permissions" />);
|
||||
expect(navLink.text()).not.toBe("");
|
||||
});
|
||||
|
||||
@@ -16,12 +16,7 @@ class ChangePermissionNavLink extends React.Component<Props> {
|
||||
if (!this.hasPermissionToSetPermission()) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<NavLink
|
||||
to={permissionsUrl}
|
||||
label={t("singleUser.menu.setPermissionsNavLink")}
|
||||
/>
|
||||
);
|
||||
return <NavLink to={permissionsUrl} label={t("singleUser.menu.setPermissionsNavLink")} />;
|
||||
}
|
||||
|
||||
hasPermissionToSetPermission = () => {
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { apiClient } from "@scm-manager/ui-components";
|
||||
|
||||
export const CONTENT_TYPE_PASSWORD_OVERWRITE =
|
||||
"application/vnd.scmm-passwordOverwrite+json;v=2";
|
||||
export const CONTENT_TYPE_PASSWORD_OVERWRITE = "application/vnd.scmm-passwordOverwrite+json;v=2";
|
||||
|
||||
export function setPassword(url: string, password: string) {
|
||||
return apiClient
|
||||
|
||||
@@ -30,9 +30,7 @@ class UserRow extends React.Component<Props> {
|
||||
<td>
|
||||
{iconType} {this.renderLink(to, user.name)}
|
||||
</td>
|
||||
<td className="is-hidden-mobile">
|
||||
{this.renderLink(to, user.displayName)}
|
||||
</td>
|
||||
<td className="is-hidden-mobile">{this.renderLink(to, user.displayName)}</td>
|
||||
<td>
|
||||
<a href={`mailto:${user.mail}`}>{user.mail}</a>
|
||||
</td>
|
||||
|
||||
@@ -14,7 +14,7 @@ describe("test displayName validation", () => {
|
||||
"Zaphod Beeblebrox <zaphod.beeblebrox@hitchhiker.com>",
|
||||
"Marvin, der depressive Roboter"
|
||||
];
|
||||
for (let name of validNames) {
|
||||
for (const name of validNames) {
|
||||
expect(validator.isDisplayNameValid(name)).toBe(true);
|
||||
}
|
||||
});
|
||||
@@ -24,7 +24,7 @@ describe("test password validation", () => {
|
||||
it("should return false", () => {
|
||||
// invalid taken from ValidationUtilTest.java
|
||||
const invalid = ["", "abc", "aaabbbcccdddeeefffggghhhiiijjjkkk"];
|
||||
for (let password of invalid) {
|
||||
for (const password of invalid) {
|
||||
expect(validator.isPasswordValid(password)).toBe(false);
|
||||
}
|
||||
});
|
||||
@@ -32,7 +32,7 @@ describe("test password validation", () => {
|
||||
it("should return true", () => {
|
||||
// valid taken from ValidationUtilTest.java
|
||||
const valid = ["secret123", "mySuperSecretPassword"];
|
||||
for (let password of valid) {
|
||||
for (const password of valid) {
|
||||
expect(validator.isPasswordValid(password)).toBe(true);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,12 +3,7 @@ import { connect } from "react-redux";
|
||||
import UserForm from "../components/UserForm";
|
||||
import { User } from "@scm-manager/ui-types";
|
||||
import { History } from "history";
|
||||
import {
|
||||
createUser,
|
||||
createUserReset,
|
||||
isCreateUserPending,
|
||||
getCreateUserFailure
|
||||
} from "../modules/users";
|
||||
import { createUser, createUserReset, isCreateUserPending, getCreateUserFailure } from "../modules/users";
|
||||
import { Page } from "@scm-manager/ui-components";
|
||||
import { translate } from "react-i18next";
|
||||
import { getUsersLink } from "../../modules/indexResource";
|
||||
@@ -38,25 +33,15 @@ class CreateUser extends React.Component<Props> {
|
||||
};
|
||||
|
||||
createUser = (user: User) => {
|
||||
this.props.addUser(this.props.usersLink, user, () =>
|
||||
this.userCreated(user)
|
||||
);
|
||||
this.props.addUser(this.props.usersLink, user, () => this.userCreated(user));
|
||||
};
|
||||
|
||||
render() {
|
||||
const { t, loading, error } = this.props;
|
||||
|
||||
return (
|
||||
<Page
|
||||
title={t("createUser.title")}
|
||||
subtitle={t("createUser.subtitle")}
|
||||
error={error}
|
||||
showContentOnError={true}
|
||||
>
|
||||
<UserForm
|
||||
submitForm={user => this.createUser(user)}
|
||||
loading={loading}
|
||||
/>
|
||||
<Page title={t("createUser.title")} subtitle={t("createUser.subtitle")} error={error} showContentOnError={true}>
|
||||
<UserForm submitForm={user => this.createUser(user)} loading={loading} />
|
||||
</Page>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,8 @@
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import { User } from "@scm-manager/ui-types";
|
||||
import {
|
||||
Subtitle,
|
||||
DeleteButton,
|
||||
confirmAlert,
|
||||
ErrorNotification
|
||||
} from "@scm-manager/ui-components";
|
||||
import {
|
||||
deleteUser,
|
||||
getDeleteUserFailure,
|
||||
isDeleteUserPending
|
||||
} from "../modules/users";
|
||||
import { Subtitle, DeleteButton, confirmAlert, ErrorNotification } from "@scm-manager/ui-components";
|
||||
import { deleteUser, getDeleteUserFailure, isDeleteUserPending } from "../modules/users";
|
||||
import { connect } from "react-redux";
|
||||
import { withRouter } from "react-router-dom";
|
||||
import { History } from "history";
|
||||
@@ -77,11 +68,7 @@ class DeleteUser extends React.Component<Props> {
|
||||
<ErrorNotification error={error} />
|
||||
<div className="columns">
|
||||
<div className="column">
|
||||
<DeleteButton
|
||||
label={t("deleteUser.button")}
|
||||
action={action}
|
||||
loading={loading}
|
||||
/>
|
||||
<DeleteButton label={t("deleteUser.button")} action={action} loading={loading} />
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
|
||||
@@ -4,12 +4,7 @@ import { withRouter } from "react-router-dom";
|
||||
import UserForm from "../components/UserForm";
|
||||
import DeleteUser from "./DeleteUser";
|
||||
import { User } from "@scm-manager/ui-types";
|
||||
import {
|
||||
modifyUser,
|
||||
isModifyUserPending,
|
||||
getModifyUserFailure,
|
||||
modifyUserReset
|
||||
} from "../modules/users";
|
||||
import { modifyUser, isModifyUserPending, getModifyUserFailure, modifyUserReset } from "../modules/users";
|
||||
import { History } from "history";
|
||||
import { ErrorNotification } from "@scm-manager/ui-components";
|
||||
|
||||
@@ -45,11 +40,7 @@ class EditUser extends React.Component<Props> {
|
||||
return (
|
||||
<div>
|
||||
<ErrorNotification error={error} />
|
||||
<UserForm
|
||||
submitForm={user => this.modifyUser(user)}
|
||||
user={user}
|
||||
loading={loading}
|
||||
/>
|
||||
<UserForm submitForm={user => this.modifyUser(user)} user={user} loading={loading} />
|
||||
<hr />
|
||||
<DeleteUser user={user} />
|
||||
</div>
|
||||
|
||||
@@ -1,30 +1,13 @@
|
||||
import React from "react";
|
||||
import { connect } from "react-redux";
|
||||
import {
|
||||
Page,
|
||||
Loading,
|
||||
Navigation,
|
||||
SubNavigation,
|
||||
Section,
|
||||
NavLink,
|
||||
ErrorPage
|
||||
} from "@scm-manager/ui-components";
|
||||
import { Page, Loading, Navigation, SubNavigation, Section, NavLink, ErrorPage } from "@scm-manager/ui-components";
|
||||
import { Route } from "react-router-dom";
|
||||
import { Details } from "./../components/table";
|
||||
import EditUser from "./EditUser";
|
||||
import { User } from "@scm-manager/ui-types";
|
||||
import { History } from "history";
|
||||
import {
|
||||
fetchUserByName,
|
||||
getUserByName,
|
||||
isFetchUserPending,
|
||||
getFetchUserFailure
|
||||
} from "../modules/users";
|
||||
import {
|
||||
EditUserNavLink,
|
||||
SetPasswordNavLink,
|
||||
SetPermissionsNavLink
|
||||
} from "./../components/navLinks";
|
||||
import { fetchUserByName, getUserByName, isFetchUserPending, getFetchUserFailure } from "../modules/users";
|
||||
import { EditUserNavLink, SetPasswordNavLink, SetPermissionsNavLink } from "./../components/navLinks";
|
||||
import { translate } from "react-i18next";
|
||||
import { getUsersLink } from "../../modules/indexResource";
|
||||
import SetUserPassword from "../components/SetUserPassword";
|
||||
@@ -67,13 +50,7 @@ class SingleUser extends React.Component<Props> {
|
||||
const { t, loading, error, user } = this.props;
|
||||
|
||||
if (error) {
|
||||
return (
|
||||
<ErrorPage
|
||||
title={t("singleUser.errorTitle")}
|
||||
subtitle={t("singleUser.errorSubtitle")}
|
||||
error={error}
|
||||
/>
|
||||
);
|
||||
return <ErrorPage title={t("singleUser.errorTitle")} subtitle={t("singleUser.errorSubtitle")} error={error} />;
|
||||
}
|
||||
|
||||
if (!user || loading) {
|
||||
@@ -92,57 +69,23 @@ class SingleUser extends React.Component<Props> {
|
||||
<div className="columns">
|
||||
<div className="column is-three-quarters">
|
||||
<Route path={url} exact component={() => <Details user={user} />} />
|
||||
<Route
|
||||
path={`${url}/settings/general`}
|
||||
component={() => <EditUser user={user} />}
|
||||
/>
|
||||
<Route
|
||||
path={`${url}/settings/password`}
|
||||
component={() => <SetUserPassword user={user} />}
|
||||
/>
|
||||
<Route path={`${url}/settings/general`} component={() => <EditUser user={user} />} />
|
||||
<Route path={`${url}/settings/password`} component={() => <SetUserPassword user={user} />} />
|
||||
<Route
|
||||
path={`${url}/settings/permissions`}
|
||||
component={() => (
|
||||
<SetPermissions
|
||||
selectedPermissionsLink={user._links.permissions}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
<ExtensionPoint
|
||||
name="user.route"
|
||||
props={extensionProps}
|
||||
renderAll={true}
|
||||
component={() => <SetPermissions selectedPermissionsLink={user._links.permissions} />}
|
||||
/>
|
||||
<ExtensionPoint name="user.route" props={extensionProps} renderAll={true} />
|
||||
</div>
|
||||
<div className="column">
|
||||
<Navigation>
|
||||
<Section label={t("singleUser.menu.navigationLabel")}>
|
||||
<NavLink
|
||||
to={`${url}`}
|
||||
icon="fas fa-info-circle"
|
||||
label={t("singleUser.menu.informationNavLink")}
|
||||
/>
|
||||
<SubNavigation
|
||||
to={`${url}/settings/general`}
|
||||
label={t("singleUser.menu.settingsNavLink")}
|
||||
>
|
||||
<EditUserNavLink
|
||||
user={user}
|
||||
editUrl={`${url}/settings/general`}
|
||||
/>
|
||||
<SetPasswordNavLink
|
||||
user={user}
|
||||
passwordUrl={`${url}/settings/password`}
|
||||
/>
|
||||
<SetPermissionsNavLink
|
||||
user={user}
|
||||
permissionsUrl={`${url}/settings/permissions`}
|
||||
/>
|
||||
<ExtensionPoint
|
||||
name="user.setting"
|
||||
props={extensionProps}
|
||||
renderAll={true}
|
||||
/>
|
||||
<NavLink to={`${url}`} icon="fas fa-info-circle" label={t("singleUser.menu.informationNavLink")} />
|
||||
<SubNavigation to={`${url}/settings/general`} label={t("singleUser.menu.settingsNavLink")}>
|
||||
<EditUserNavLink user={user} editUrl={`${url}/settings/general`} />
|
||||
<SetPasswordNavLink user={user} passwordUrl={`${url}/settings/password`} />
|
||||
<SetPermissionsNavLink user={user} permissionsUrl={`${url}/settings/permissions`} />
|
||||
<ExtensionPoint name="user.setting" props={extensionProps} renderAll={true} />
|
||||
</SubNavigation>
|
||||
</Section>
|
||||
</Navigation>
|
||||
|
||||
@@ -44,30 +44,15 @@ type Props = {
|
||||
class Users extends React.Component<Props> {
|
||||
componentDidMount() {
|
||||
const { fetchUsersByPage, usersLink, page, location } = this.props;
|
||||
fetchUsersByPage(
|
||||
usersLink,
|
||||
page,
|
||||
urls.getQueryStringFromLocation(location)
|
||||
);
|
||||
fetchUsersByPage(usersLink, page, urls.getQueryStringFromLocation(location));
|
||||
}
|
||||
|
||||
componentDidUpdate = (prevProps: Props) => {
|
||||
const {
|
||||
loading,
|
||||
list,
|
||||
page,
|
||||
usersLink,
|
||||
location,
|
||||
fetchUsersByPage
|
||||
} = this.props;
|
||||
const { loading, list, page, usersLink, location, fetchUsersByPage } = this.props;
|
||||
if (list && page && !loading) {
|
||||
const statePage: number = list.page + 1;
|
||||
if (page !== statePage || prevProps.location.search !== location.search) {
|
||||
fetchUsersByPage(
|
||||
usersLink,
|
||||
page,
|
||||
urls.getQueryStringFromLocation(location)
|
||||
);
|
||||
fetchUsersByPage(usersLink, page, urls.getQueryStringFromLocation(location));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -75,20 +60,11 @@ class Users extends React.Component<Props> {
|
||||
render() {
|
||||
const { users, loading, error, canAddUsers, t } = this.props;
|
||||
return (
|
||||
<Page
|
||||
title={t("users.title")}
|
||||
subtitle={t("users.subtitle")}
|
||||
loading={loading || !users}
|
||||
error={error}
|
||||
>
|
||||
<Page title={t("users.title")} subtitle={t("users.subtitle")} loading={loading || !users} error={error}>
|
||||
{this.renderUserTable()}
|
||||
{this.renderCreateButton()}
|
||||
<PageActions>
|
||||
<OverviewPageActions
|
||||
showCreateButton={canAddUsers}
|
||||
link="users"
|
||||
label={t("users.createButton")}
|
||||
/>
|
||||
<OverviewPageActions showCreateButton={canAddUsers} link="users" label={t("users.createButton")} />
|
||||
</PageActions>
|
||||
</Page>
|
||||
);
|
||||
@@ -100,11 +76,7 @@ class Users extends React.Component<Props> {
|
||||
return (
|
||||
<>
|
||||
<UserTable users={users} />
|
||||
<LinkPaginator
|
||||
collection={list}
|
||||
page={page}
|
||||
filter={urls.getQueryStringFromLocation(location)}
|
||||
/>
|
||||
<LinkPaginator collection={list} page={page} filter={urls.getQueryStringFromLocation(location)} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -114,9 +86,7 @@ class Users extends React.Component<Props> {
|
||||
renderCreateButton() {
|
||||
const { canAddUsers, t } = this.props;
|
||||
if (canAddUsers) {
|
||||
return (
|
||||
<CreateButton label={t("users.createButton")} link="/users/create" />
|
||||
);
|
||||
return <CreateButton label={t("users.createButton")} link="/users/create" />;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -45,9 +45,7 @@ export function fetchUsers(link: string) {
|
||||
export function fetchUsersByPage(link: string, page: number, filter?: string) {
|
||||
// backend start counting by 0
|
||||
if (filter) {
|
||||
return fetchUsersByLink(
|
||||
`${link}?page=${page - 1}&q=${decodeURIComponent(filter)}`
|
||||
);
|
||||
return fetchUsersByLink(`${link}?page=${page - 1}&q=${decodeURIComponent(filter)}`);
|
||||
}
|
||||
return fetchUsersByLink(`${link}?page=${page - 1}`);
|
||||
}
|
||||
@@ -289,34 +287,30 @@ export function deleteUserFailure(user: User, error: Error): Action {
|
||||
};
|
||||
}
|
||||
|
||||
function extractUsersByNames(
|
||||
users: User[],
|
||||
userNames: string[],
|
||||
oldUsersByNames: object
|
||||
) {
|
||||
function extractUsersByNames(users: User[], userNames: string[], oldUsersByNames: object) {
|
||||
const usersByNames = {};
|
||||
|
||||
for (let user of users) {
|
||||
for (const user of users) {
|
||||
usersByNames[user.name] = user;
|
||||
}
|
||||
|
||||
for (let userName in oldUsersByNames) {
|
||||
for (const userName in oldUsersByNames) {
|
||||
usersByNames[userName] = oldUsersByNames[userName];
|
||||
}
|
||||
return usersByNames;
|
||||
}
|
||||
|
||||
function deleteUserInUsersByNames(users: {}, userName: string) {
|
||||
let newUsers = {};
|
||||
for (let username in users) {
|
||||
const newUsers = {};
|
||||
for (const username in users) {
|
||||
if (username !== userName) newUsers[username] = users[username];
|
||||
}
|
||||
return newUsers;
|
||||
}
|
||||
|
||||
function deleteUserInEntries(users: [], userName: string) {
|
||||
let newUsers = [];
|
||||
for (let user of users) {
|
||||
const newUsers = [];
|
||||
for (const user of users) {
|
||||
if (user !== userName) newUsers.push(user);
|
||||
}
|
||||
return newUsers;
|
||||
@@ -347,10 +341,7 @@ function listReducer(state: any = {}, action: any = {}) {
|
||||
|
||||
// Delete single user actions
|
||||
case DELETE_USER_SUCCESS:
|
||||
const newUserEntries = deleteUserInEntries(
|
||||
state.entries,
|
||||
action.payload.name
|
||||
);
|
||||
const newUserEntries = deleteUserInEntries(state.entries, action.payload.name);
|
||||
return {
|
||||
...state,
|
||||
entries: newUserEntries
|
||||
@@ -420,7 +411,7 @@ export function getUsersFromState(state: object) {
|
||||
}
|
||||
const userEntries: User[] = [];
|
||||
|
||||
for (let userName of userNames) {
|
||||
for (const userName of userNames) {
|
||||
userEntries.push(state.users.byNames[userName]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user