mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-18 03:01:05 +01:00
refactoring
This commit is contained in:
@@ -12,7 +12,7 @@ export function withEndingSlash(url: string) {
|
|||||||
return url + "/";
|
return url + "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
export function concat(base: string, ...parts: string) {
|
export function concat(base: string, ...parts: string[]) {
|
||||||
let url = base;
|
let url = base;
|
||||||
for ( let p of parts) {
|
for ( let p of parts) {
|
||||||
url = withEndingSlash(url) + p;
|
url = withEndingSlash(url) + p;
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import type { Links } from "./hal";
|
import type { Links } from "./hal";
|
||||||
|
|
||||||
export type Permission = {
|
export type Permission = PermissionCreateEntry & {
|
||||||
name: string,
|
_links: Links
|
||||||
type: string,
|
|
||||||
groupPermission: boolean,
|
|
||||||
_links?: Links
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type PermissionEntry = {
|
export type PermissionCreateEntry = {
|
||||||
name: string,
|
name: string,
|
||||||
type: string,
|
type: string,
|
||||||
groupPermission: boolean
|
groupPermission: boolean
|
||||||
|
|||||||
@@ -17,4 +17,4 @@ export type { Tag } from "./Tags";
|
|||||||
|
|
||||||
export type { Config } from "./Config";
|
export type { Config } from "./Config";
|
||||||
|
|
||||||
export type { Permission, PermissionEntry, PermissionCollection } from "./RepositoryPermissions";
|
export type { Permission, PermissionCreateEntry, PermissionCollection } from "./RepositoryPermissions";
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import React from "react";
|
import * as React from "react";
|
||||||
import { binder } from "@scm-manager/ui-extensions";
|
import { binder } from "@scm-manager/ui-extensions";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
//@flow
|
//@flow
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import type { Changeset, Repository } from "../../../../../scm-ui-components/packages/ui-types/src/index";
|
import type {
|
||||||
|
Changeset,
|
||||||
|
Repository
|
||||||
|
} from "../../../../../scm-ui-components/packages/ui-types/src/index";
|
||||||
import { Interpolate, translate } from "react-i18next";
|
import { Interpolate, translate } from "react-i18next";
|
||||||
import injectSheet from "react-jss";
|
import injectSheet from "react-jss";
|
||||||
import ChangesetTag from "./ChangesetTag";
|
import ChangesetTag from "./ChangesetTag";
|
||||||
@@ -11,6 +14,7 @@ import AvatarWrapper from "./AvatarWrapper";
|
|||||||
import AvatarImage from "./AvatarImage";
|
import AvatarImage from "./AvatarImage";
|
||||||
import classNames from "classnames";
|
import classNames from "classnames";
|
||||||
import ChangesetId from "./ChangesetId";
|
import ChangesetId from "./ChangesetId";
|
||||||
|
import type { Tag } from "@scm-manager/ui-types";
|
||||||
|
|
||||||
const styles = {
|
const styles = {
|
||||||
spacing: {
|
spacing: {
|
||||||
@@ -27,7 +31,7 @@ type Props = {
|
|||||||
|
|
||||||
class ChangesetDetails extends React.Component<Props> {
|
class ChangesetDetails extends React.Component<Props> {
|
||||||
render() {
|
render() {
|
||||||
const { changeset, repository, t, classes } = this.props;
|
const { changeset, repository, classes } = this.props;
|
||||||
|
|
||||||
const description = parseDescription(changeset.description);
|
const description = parseDescription(changeset.description);
|
||||||
|
|
||||||
|
|||||||
@@ -415,7 +415,7 @@ describe("changesets", () => {
|
|||||||
{
|
{
|
||||||
"foo/bar": {
|
"foo/bar": {
|
||||||
byId: {
|
byId: {
|
||||||
["id2"]: {
|
"id2": {
|
||||||
id: "id2",
|
id: "id2",
|
||||||
author: { mail: "mail@author.com", name: "author" }
|
author: { mail: "mail@author.com", name: "author" }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import { Checkbox, InputField, SubmitButton } from "@scm-manager/ui-components";
|
|||||||
import TypeSelector from "./TypeSelector";
|
import TypeSelector from "./TypeSelector";
|
||||||
import type {
|
import type {
|
||||||
PermissionCollection,
|
PermissionCollection,
|
||||||
PermissionEntry
|
PermissionCreateEntry
|
||||||
} from "@scm-manager/ui-types";
|
} from "@scm-manager/ui-types";
|
||||||
import * as validator from "./permissionValidation";
|
import * as validator from "./permissionValidation";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
t: string => string,
|
t: string => string,
|
||||||
createPermission: (permission: PermissionEntry) => void,
|
createPermission: (permission: PermissionCreateEntry) => void,
|
||||||
loading: boolean,
|
loading: boolean,
|
||||||
currentPermissions: PermissionCollection
|
currentPermissions: PermissionCollection
|
||||||
};
|
};
|
||||||
@@ -65,7 +65,7 @@ class CreatePermissionForm extends React.Component<Props, State> {
|
|||||||
<SubmitButton
|
<SubmitButton
|
||||||
label={t("permission.add-permission.submit-button")}
|
label={t("permission.add-permission.submit-button")}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
disabled={!this.state.valid || this.state.name == ""}
|
disabled={!this.state.valid || this.state.name === ""}
|
||||||
/>
|
/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,21 +1,30 @@
|
|||||||
// @flow
|
// @flow
|
||||||
import { validation } from "@scm-manager/ui-components";
|
import { validation } from "@scm-manager/ui-components";
|
||||||
import type {
|
import type { PermissionCollection } from "@scm-manager/ui-types";
|
||||||
PermissionCollection,
|
|
||||||
} from "@scm-manager/ui-types";
|
|
||||||
const isNameValid = validation.isNameValid;
|
const isNameValid = validation.isNameValid;
|
||||||
|
|
||||||
export { isNameValid };
|
export { isNameValid };
|
||||||
|
|
||||||
export const isPermissionValid = (name: string, groupPermission: boolean, permissions: PermissionCollection) => {
|
export const isPermissionValid = (
|
||||||
return isNameValid(name) && !currentPermissionIncludeName(name, groupPermission, permissions);
|
name: string,
|
||||||
|
groupPermission: boolean,
|
||||||
|
permissions: PermissionCollection
|
||||||
|
) => {
|
||||||
|
return (
|
||||||
|
isNameValid(name) &&
|
||||||
|
!currentPermissionIncludeName(name, groupPermission, permissions)
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const currentPermissionIncludeName = (name: string, groupPermission: boolean, permissions: PermissionCollection) => {
|
const currentPermissionIncludeName = (
|
||||||
|
name: string,
|
||||||
|
groupPermission: boolean,
|
||||||
|
permissions: PermissionCollection
|
||||||
|
) => {
|
||||||
for (let i = 0; i < permissions.length; i++) {
|
for (let i = 0; i < permissions.length; i++) {
|
||||||
if (
|
if (
|
||||||
permissions[i].name === name &&
|
permissions[i].name === name &&
|
||||||
permissions[i].groupPermission == groupPermission
|
permissions[i].groupPermission === groupPermission
|
||||||
)
|
)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ describe("permission validation", () => {
|
|||||||
{
|
{
|
||||||
name: "PermissionName",
|
name: "PermissionName",
|
||||||
groupPermission: true,
|
groupPermission: true,
|
||||||
type: "READ"
|
type: "READ",
|
||||||
|
_links: {}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
const name = "PermissionName";
|
const name = "PermissionName";
|
||||||
@@ -33,7 +34,8 @@ describe("permission validation", () => {
|
|||||||
{
|
{
|
||||||
name: "PermissionName",
|
name: "PermissionName",
|
||||||
groupPermission: false,
|
groupPermission: false,
|
||||||
type: "READ"
|
type: "READ",
|
||||||
|
_links: {}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
const name = "PermissionName";
|
const name = "PermissionName";
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import { Loading, ErrorPage } from "@scm-manager/ui-components";
|
|||||||
import type {
|
import type {
|
||||||
Permission,
|
Permission,
|
||||||
PermissionCollection,
|
PermissionCollection,
|
||||||
PermissionEntry
|
PermissionCreateEntry
|
||||||
} from "@scm-manager/ui-types";
|
} from "@scm-manager/ui-types";
|
||||||
import SinglePermission from "./SinglePermission";
|
import SinglePermission from "./SinglePermission";
|
||||||
import CreatePermissionForm from "../components/CreatePermissionForm";
|
import CreatePermissionForm from "../components/CreatePermissionForm";
|
||||||
@@ -39,7 +39,7 @@ type Props = {
|
|||||||
//dispatch functions
|
//dispatch functions
|
||||||
fetchPermissions: (namespace: string, repoName: string) => void,
|
fetchPermissions: (namespace: string, repoName: string) => void,
|
||||||
createPermission: (
|
createPermission: (
|
||||||
permission: PermissionEntry,
|
permission: PermissionCreateEntry,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
repoName: string,
|
repoName: string,
|
||||||
callback?: () => void
|
callback?: () => void
|
||||||
@@ -176,7 +176,7 @@ const mapDispatchToProps = dispatch => {
|
|||||||
dispatch(fetchPermissions(namespace, repoName));
|
dispatch(fetchPermissions(namespace, repoName));
|
||||||
},
|
},
|
||||||
createPermission: (
|
createPermission: (
|
||||||
permission: PermissionEntry,
|
permission: PermissionCreateEntry,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
repoName: string,
|
repoName: string,
|
||||||
callback?: () => void
|
callback?: () => void
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import type { Action } from "@scm-manager/ui-components";
|
|||||||
import type {
|
import type {
|
||||||
PermissionCollection,
|
PermissionCollection,
|
||||||
Permission,
|
Permission,
|
||||||
PermissionEntry
|
PermissionCreateEntry
|
||||||
} from "@scm-manager/ui-types";
|
} from "@scm-manager/ui-types";
|
||||||
import { isPending } from "../../../modules/pending";
|
import { isPending } from "../../../modules/pending";
|
||||||
import { getFailure } from "../../../modules/failure";
|
import { getFailure } from "../../../modules/failure";
|
||||||
@@ -219,7 +219,7 @@ export function modifyPermissionReset(namespace: string, repoName: string) {
|
|||||||
|
|
||||||
// create permission
|
// create permission
|
||||||
export function createPermission(
|
export function createPermission(
|
||||||
permission: PermissionEntry,
|
permission: PermissionCreateEntry,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
repoName: string,
|
repoName: string,
|
||||||
callback?: () => void
|
callback?: () => void
|
||||||
@@ -260,7 +260,7 @@ export function createPermission(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createPermissionPending(
|
export function createPermissionPending(
|
||||||
permission: PermissionEntry,
|
permission: PermissionCreateEntry,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
repoName: string
|
repoName: string
|
||||||
): Action {
|
): Action {
|
||||||
@@ -272,7 +272,7 @@ export function createPermissionPending(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function createPermissionSuccess(
|
export function createPermissionSuccess(
|
||||||
permission: PermissionEntry,
|
permission: PermissionCreateEntry,
|
||||||
namespace: string,
|
namespace: string,
|
||||||
repoName: string
|
repoName: string
|
||||||
): Action {
|
): Action {
|
||||||
|
|||||||
@@ -640,7 +640,7 @@ describe("permissions selectors", () => {
|
|||||||
it("should return true, when createPermission is true", () => {
|
it("should return true, when createPermission is true", () => {
|
||||||
const state = {
|
const state = {
|
||||||
permissions: {
|
permissions: {
|
||||||
["hitchhiker/puzzle42"]: {
|
"hitchhiker/puzzle42": {
|
||||||
createPermission: true
|
createPermission: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -651,7 +651,7 @@ describe("permissions selectors", () => {
|
|||||||
it("should return false, when createPermission is false", () => {
|
it("should return false, when createPermission is false", () => {
|
||||||
const state = {
|
const state = {
|
||||||
permissions: {
|
permissions: {
|
||||||
["hitchhiker/puzzle42"]: {
|
"hitchhiker/puzzle42": {
|
||||||
createPermission: false
|
createPermission: false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user