mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
Merge with 2.0.0-m3
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
// @flow
|
||||
import * as React from "react";
|
||||
import { withRouter } from "react-router-dom";
|
||||
import { withContextPath } from "./urls";
|
||||
|
||||
/**
|
||||
* Adds anchor links to markdown headings.
|
||||
*
|
||||
* @see <a href="https://github.com/rexxars/react-markdown/issues/69">Headings are missing anchors / ids</a>
|
||||
*/
|
||||
|
||||
type Props = {
|
||||
children: React.Node,
|
||||
level: number,
|
||||
location: any
|
||||
};
|
||||
|
||||
function flatten(text: string, child: any) {
|
||||
return typeof child === "string"
|
||||
? text + child
|
||||
: React.Children.toArray(child.props.children).reduce(flatten, text);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns heading text into a anchor id
|
||||
*
|
||||
* @VisibleForTesting
|
||||
*/
|
||||
export function headingToAnchorId(heading: string) {
|
||||
return heading.toLowerCase().replace(/\W/g, "-");
|
||||
}
|
||||
|
||||
function MarkdownHeadingRenderer(props: Props) {
|
||||
const children = React.Children.toArray(props.children);
|
||||
const heading = children.reduce(flatten, "");
|
||||
const anchorId = headingToAnchorId(heading);
|
||||
const headingElement = React.createElement("h" + props.level, {}, props.children);
|
||||
const href = withContextPath(props.location.pathname + "#" + anchorId);
|
||||
|
||||
return (
|
||||
<a id={`${anchorId}`} className="anchor" href={href}>
|
||||
{headingElement}
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
export default withRouter(MarkdownHeadingRenderer);
|
||||
@@ -0,0 +1,18 @@
|
||||
// @flow
|
||||
import React from "react";
|
||||
import { headingToAnchorId } from "./MarkdownHeadingRenderer";
|
||||
|
||||
describe("headingToAnchorId tests", () => {
|
||||
|
||||
it("should lower case the text", () => {
|
||||
expect(headingToAnchorId("Hello")).toBe("hello");
|
||||
expect(headingToAnchorId("HeLlO")).toBe("hello");
|
||||
expect(headingToAnchorId("HELLO")).toBe("hello");
|
||||
});
|
||||
|
||||
it("should replace spaces with hyphen", () => {
|
||||
expect(headingToAnchorId("awesome stuff")).toBe("awesome-stuff");
|
||||
expect(headingToAnchorId("a b c d e f")).toBe("a-b-c-d-e-f");
|
||||
});
|
||||
|
||||
});
|
||||
@@ -3,17 +3,49 @@ import React from "react";
|
||||
import SyntaxHighlighter from "./SyntaxHighlighter";
|
||||
import Markdown from "react-markdown/with-html";
|
||||
import {binder} from "@scm-manager/ui-extensions";
|
||||
import MarkdownHeadingRenderer from "./MarkdownHeadingRenderer";
|
||||
import { withRouter } from "react-router-dom";
|
||||
|
||||
|
||||
type Props = {
|
||||
content: string,
|
||||
renderContext?: Object,
|
||||
renderers?: Object,
|
||||
enableAnchorHeadings: boolean,
|
||||
|
||||
// context props
|
||||
location: any
|
||||
};
|
||||
|
||||
class MarkdownView extends React.Component<Props> {
|
||||
|
||||
static defaultProps = {
|
||||
enableAnchorHeadings: false
|
||||
};
|
||||
|
||||
contentRef: ?HTMLDivElement;
|
||||
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
// we have to use componentDidUpdate, because we have to wait until all
|
||||
// children are rendered and componentDidMount is called before the
|
||||
// markdown content was rendered.
|
||||
const hash = this.props.location.hash;
|
||||
if (this.contentRef && hash) {
|
||||
// we query only child elements, to avoid strange scrolling with multiple
|
||||
// markdown elements on one page.
|
||||
const element = this.contentRef.querySelector(hash);
|
||||
if (element && element.scrollIntoView) {
|
||||
element.scrollIntoView();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const {content, renderers, renderContext} = this.props;
|
||||
const {content, renderers, renderContext, enableAnchorHeadings} = this.props;
|
||||
|
||||
const rendererFactory = binder.getExtension("markdown-renderer-factory");
|
||||
let rendererList = renderers;
|
||||
@@ -26,11 +58,16 @@ class MarkdownView extends React.Component<Props> {
|
||||
rendererList = {};
|
||||
}
|
||||
|
||||
if (enableAnchorHeadings) {
|
||||
rendererList.heading = MarkdownHeadingRenderer;
|
||||
}
|
||||
|
||||
if (!rendererList.code){
|
||||
rendererList.code = SyntaxHighlighter;
|
||||
}
|
||||
|
||||
return (
|
||||
<div ref={el => (this.contentRef = el)}>
|
||||
<Markdown
|
||||
className="content"
|
||||
skipHtml={true}
|
||||
@@ -38,8 +75,9 @@ class MarkdownView extends React.Component<Props> {
|
||||
source={content}
|
||||
renderers={rendererList}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default MarkdownView;
|
||||
export default withRouter(MarkdownView);
|
||||
|
||||
@@ -9,30 +9,26 @@
|
||||
"repositoryRole": {
|
||||
"navLink": "Berechtigungsrollen",
|
||||
"title": "Berechtigungsrollen",
|
||||
"errorTitle": "Fehler",
|
||||
"errorSubtitle": "Unbekannter Berechtigungsrollen Fehler",
|
||||
"createSubtitle": "Berechtigungsrolle erstellen",
|
||||
"editSubtitle": "Berechtigungsrolle bearbeiten",
|
||||
"overview": {
|
||||
"title": "Übersicht aller verfügbaren Berechtigungsrollen",
|
||||
"noPermissionRoles": "Keine Berechtigungsrollen gefunden.",
|
||||
"system": "System",
|
||||
"createButton": "Berechtigungsrolle erstellen",
|
||||
"createButton": "Berechtigungsrolle erstellen"
|
||||
},
|
||||
"editButton": "Bearbeiten",
|
||||
"name": "Name",
|
||||
"type": "Typ",
|
||||
"verbs": "Berechtigungen",
|
||||
"button": {
|
||||
"edit": "Bearbeiten"
|
||||
},
|
||||
"create": {
|
||||
"name": "Name"
|
||||
},
|
||||
"edit": "Berechtigungsrolle bearbeiten",
|
||||
"system": "System",
|
||||
"form": {
|
||||
"subtitle": "Berechtigungsrolle bearbeiten",
|
||||
"name": "Name",
|
||||
"permissions": "Berechtigungen",
|
||||
"submit": "Speichern"
|
||||
}
|
||||
},
|
||||
"role": {
|
||||
"name": "Name",
|
||||
"system": "System"
|
||||
},
|
||||
"deleteRole" : {
|
||||
"button": "Löschen",
|
||||
"subtitle": "Berechtigungsrolle löschen",
|
||||
|
||||
@@ -9,30 +9,26 @@
|
||||
"repositoryRole": {
|
||||
"navLink": "Permission Roles",
|
||||
"title": "Permission Roles",
|
||||
"errorTitle": "Error",
|
||||
"errorSubtitle": "Unknown Permission Role Error",
|
||||
"createSubtitle": "Create Permission Role",
|
||||
"editSubtitle": "Edit Permission Role",
|
||||
"overview": {
|
||||
"title": "Overview of all permission roles",
|
||||
"noPermissionRoles": "No permission roles found.",
|
||||
"system": "System",
|
||||
"createButton": "Create Permission Role",
|
||||
"createButton": "Create Permission Role"
|
||||
},
|
||||
"editButton": "Edit",
|
||||
"name": "Name",
|
||||
"type": "Type",
|
||||
"verbs": "Permissions",
|
||||
"edit": "Edit Permission Role",
|
||||
"button": {
|
||||
"edit": "Edit"
|
||||
},
|
||||
"create": {
|
||||
"name": "Name"
|
||||
},
|
||||
"system": "System",
|
||||
"form": {
|
||||
"subtitle": "Edit Permission Role",
|
||||
"name": "Name",
|
||||
"permissions": "Permissions",
|
||||
"submit": "Save"
|
||||
}
|
||||
},
|
||||
"role": {
|
||||
"name": "Name",
|
||||
"system": "System"
|
||||
},
|
||||
"deleteRole": {
|
||||
"button": "Delete",
|
||||
"subtitle": "Delete Permission Role",
|
||||
|
||||
@@ -74,7 +74,6 @@ class Config extends React.Component<Props> {
|
||||
path={`${url}/roles/create`}
|
||||
render={() => (
|
||||
<CreateRepositoryRole
|
||||
disabled={false}
|
||||
history={this.props.history}
|
||||
/>
|
||||
)}
|
||||
@@ -104,6 +103,7 @@ class Config extends React.Component<Props> {
|
||||
to={`${url}/roles/`}
|
||||
label={t("repositoryRole.navLink")}
|
||||
activeWhenMatch={this.matchesRoles}
|
||||
activeOnlyWhenExact={false}
|
||||
/>
|
||||
<ExtensionPoint
|
||||
name="config.navigation"
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
//@flow
|
||||
import React from "react";
|
||||
import type { RepositoryRole } from "@scm-manager/ui-types";
|
||||
import { translate } from "react-i18next";
|
||||
import { compose } from "redux";
|
||||
import injectSheet from "react-jss";
|
||||
import { translate } from "react-i18next";
|
||||
import type { RepositoryRole } from "@scm-manager/ui-types";
|
||||
|
||||
type Props = {
|
||||
role: RepositoryRole,
|
||||
|
||||
// context props
|
||||
classes: any,
|
||||
t: string => string
|
||||
};
|
||||
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
import React from "react";
|
||||
import { translate } from "react-i18next";
|
||||
import type { RepositoryRole } from "@scm-manager/ui-types";
|
||||
import ExtensionPoint from "@scm-manager/ui-extensions/lib/ExtensionPoint";
|
||||
import { ExtensionPoint } from "@scm-manager/ui-extensions";
|
||||
import PermissionRoleDetailsTable from "./PermissionRoleDetailsTable";
|
||||
import { Button, Subtitle } from "@scm-manager/ui-components";
|
||||
import { Button } from "@scm-manager/ui-components";
|
||||
|
||||
type Props = {
|
||||
role: RepositoryRole,
|
||||
@@ -20,7 +20,7 @@ class PermissionRoleDetails extends React.Component<Props> {
|
||||
if (!!this.props.role._links.update) {
|
||||
return (
|
||||
<Button
|
||||
label={t("repositoryRole.button.edit")}
|
||||
label={t("repositoryRole.editButton")}
|
||||
link={`${url}/edit`}
|
||||
color="primary"
|
||||
/>
|
||||
@@ -33,18 +33,16 @@ class PermissionRoleDetails extends React.Component<Props> {
|
||||
const { role } = this.props;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<>
|
||||
<PermissionRoleDetailsTable role={role} />
|
||||
<hr />
|
||||
{this.renderEditButton()}
|
||||
<div className="content">
|
||||
<ExtensionPoint
|
||||
name="repositoryRole.role-details.information"
|
||||
renderAll={true}
|
||||
props={{ role }}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import AvailableVerbs from "./AvailableVerbs";
|
||||
|
||||
type Props = {
|
||||
role: RepositoryRole,
|
||||
|
||||
// context props
|
||||
t: string => string
|
||||
};
|
||||
|
||||
@@ -8,6 +8,7 @@ type Props = {
|
||||
baseUrl: string,
|
||||
roles: RepositoryRole[],
|
||||
|
||||
// context props
|
||||
t: string => string
|
||||
};
|
||||
|
||||
@@ -18,7 +19,7 @@ class PermissionRoleTable extends React.Component<Props> {
|
||||
<table className="card-table table is-hoverable is-fullwidth">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{t("repositoryRole.form.name")}</th>
|
||||
<th>{t("repositoryRole.name")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
||||
@@ -6,6 +6,8 @@ import { translate } from "react-i18next";
|
||||
|
||||
type Props = {
|
||||
system?: boolean,
|
||||
|
||||
// context props
|
||||
classes: any,
|
||||
t: string => string
|
||||
};
|
||||
@@ -24,7 +26,7 @@ class SystemRoleTag extends React.Component<Props> {
|
||||
if (system) {
|
||||
return (
|
||||
<span className={classNames("tag is-dark", classes.tag)}>
|
||||
{t("role.system")}
|
||||
{t("repositoryRole.system")}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import React from "react";
|
||||
import RepositoryRoleForm from "./RepositoryRoleForm";
|
||||
import { connect } from "react-redux";
|
||||
import { translate } from "react-i18next";
|
||||
import { ErrorNotification, Title } from "@scm-manager/ui-components";
|
||||
import {ErrorNotification, Subtitle, Title} from "@scm-manager/ui-components";
|
||||
import {
|
||||
createRole,
|
||||
getCreateRoleFailure,
|
||||
@@ -15,11 +15,12 @@ import {
|
||||
getRepositoryRolesLink,
|
||||
getRepositoryVerbsLink
|
||||
} from "../../../modules/indexResource";
|
||||
import type {History} from "history";
|
||||
|
||||
type Props = {
|
||||
disabled: boolean,
|
||||
repositoryRolesLink: string,
|
||||
error?: Error,
|
||||
history: History,
|
||||
|
||||
//dispatch function
|
||||
addRole: (link: string, role: RepositoryRole, callback?: () => void) => void,
|
||||
@@ -50,8 +51,8 @@ class CreateRepositoryRole extends React.Component<Props> {
|
||||
return (
|
||||
<>
|
||||
<Title title={t("repositoryRole.title")} />
|
||||
<Subtitle subtitle={t("repositoryRole.createSubtitle")} />
|
||||
<RepositoryRoleForm
|
||||
disabled={this.props.disabled}
|
||||
submitForm={role => this.createRepositoryRole(role)}
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -8,8 +8,9 @@ import {
|
||||
isModifyRolePending,
|
||||
modifyRole
|
||||
} from "../modules/roles";
|
||||
import { ErrorNotification } from "@scm-manager/ui-components";
|
||||
import { ErrorNotification, Subtitle } from "@scm-manager/ui-components";
|
||||
import type { RepositoryRole } from "@scm-manager/ui-types";
|
||||
import type { History } from "history";
|
||||
import DeleteRepositoryRole from "./DeleteRepositoryRole";
|
||||
|
||||
type Props = {
|
||||
@@ -18,26 +19,25 @@ type Props = {
|
||||
repositoryRolesLink: string,
|
||||
error?: Error,
|
||||
|
||||
// context objects
|
||||
t: string => string,
|
||||
history: History,
|
||||
|
||||
//dispatch function
|
||||
updateRole: (
|
||||
link: string,
|
||||
role: RepositoryRole,
|
||||
callback?: () => void
|
||||
) => void
|
||||
updateRole: (role: RepositoryRole, callback?: () => void) => void
|
||||
};
|
||||
|
||||
class EditRepositoryRole extends React.Component<Props> {
|
||||
repositoryRoleUpdated = (role: RepositoryRole) => {
|
||||
const { history } = this.props;
|
||||
history.push("/config/roles/");
|
||||
repositoryRoleUpdated = () => {
|
||||
this.props.history.push("/config/roles/");
|
||||
};
|
||||
|
||||
updateRepositoryRole = (role: RepositoryRole) => {
|
||||
this.props.updateRole(role, () => this.repositoryRoleUpdated(role));
|
||||
this.props.updateRole(role, this.repositoryRoleUpdated);
|
||||
};
|
||||
|
||||
render() {
|
||||
const { error } = this.props;
|
||||
const { error, t } = this.props;
|
||||
|
||||
if (error) {
|
||||
return <ErrorNotification error={error} />;
|
||||
@@ -45,8 +45,8 @@ class EditRepositoryRole extends React.Component<Props> {
|
||||
|
||||
return (
|
||||
<>
|
||||
<Subtitle subtitle={t("repositoryRole.editSubtitle")} />
|
||||
<RepositoryRoleForm
|
||||
nameDisabled={true}
|
||||
role={this.props.role}
|
||||
submitForm={role => this.updateRepositoryRole(role)}
|
||||
/>
|
||||
@@ -58,7 +58,7 @@ class EditRepositoryRole extends React.Component<Props> {
|
||||
}
|
||||
|
||||
const mapStateToProps = (state, ownProps) => {
|
||||
const loading = isModifyRolePending(state);
|
||||
const loading = isModifyRolePending(state, ownProps.role.name);
|
||||
const error = getModifyRoleFailure(state, ownProps.role.name);
|
||||
|
||||
return {
|
||||
|
||||
@@ -19,7 +19,6 @@ import {
|
||||
type Props = {
|
||||
role?: RepositoryRole,
|
||||
loading?: boolean,
|
||||
nameDisabled: boolean,
|
||||
availableVerbs: string[],
|
||||
verbsLink: string,
|
||||
submitForm: RepositoryRole => void,
|
||||
@@ -103,7 +102,7 @@ class RepositoryRoleForm extends React.Component<Props, State> {
|
||||
};
|
||||
|
||||
render() {
|
||||
const { loading, availableVerbs, nameDisabled, t } = this.props;
|
||||
const { loading, availableVerbs, t } = this.props;
|
||||
const { role } = this.state;
|
||||
|
||||
const verbSelectBoxes = !availableVerbs
|
||||
@@ -119,28 +118,25 @@ class RepositoryRoleForm extends React.Component<Props, State> {
|
||||
|
||||
return (
|
||||
<form onSubmit={this.submit}>
|
||||
<div className="columns">
|
||||
<div className="column">
|
||||
<InputField
|
||||
name="name"
|
||||
label={t("repositoryRole.create.name")}
|
||||
label={t("repositoryRole.form.name")}
|
||||
onChange={this.handleNameChange}
|
||||
value={role.name ? role.name : ""}
|
||||
disabled={nameDisabled}
|
||||
disabled={!!this.props.role}
|
||||
/>
|
||||
<div className="field">
|
||||
<label className="label">
|
||||
{t("repositoryRole.form.permissions")}
|
||||
</label>
|
||||
{verbSelectBoxes}
|
||||
</div>
|
||||
</div>
|
||||
<>{verbSelectBoxes}</>
|
||||
<hr />
|
||||
<div className="columns">
|
||||
<div className="column">
|
||||
<SubmitButton
|
||||
loading={loading}
|
||||
label={t("repositoryRole.form.submit")}
|
||||
disabled={!this.isValid()}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { History } from "history";
|
||||
import type { RepositoryRole, PagedCollection } from "@scm-manager/ui-types";
|
||||
import {
|
||||
Title,
|
||||
Subtitle,
|
||||
Loading,
|
||||
Notification,
|
||||
LinkPaginator,
|
||||
@@ -22,7 +23,8 @@ import {
|
||||
getFetchRolesFailure
|
||||
} from "../modules/roles";
|
||||
import PermissionRoleTable from "../components/PermissionRoleTable";
|
||||
import { getRolesLink } from "../../../modules/indexResource";
|
||||
import { getRepositoryRolesLink } from "../../../modules/indexResource";
|
||||
|
||||
type Props = {
|
||||
baseUrl: string,
|
||||
roles: RepositoryRole[],
|
||||
@@ -36,6 +38,7 @@ type Props = {
|
||||
// context objects
|
||||
t: string => string,
|
||||
history: History,
|
||||
location: any,
|
||||
|
||||
// dispatch functions
|
||||
fetchRolesByPage: (link: string, page: number) => void
|
||||
@@ -61,8 +64,7 @@ class RepositoryRoles extends React.Component<Props> {
|
||||
if (page !== statePage || prevProps.location.search !== location.search) {
|
||||
fetchRolesByPage(
|
||||
rolesLink,
|
||||
page,
|
||||
urls.getQueryStringFromLocation(location)
|
||||
page
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -76,11 +78,12 @@ class RepositoryRoles extends React.Component<Props> {
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<>
|
||||
<Title title={t("repositoryRole.title")} />
|
||||
<Subtitle subtitle={t("repositoryRole.overview.title")} />
|
||||
{this.renderPermissionsTable()}
|
||||
{this.renderCreateButton()}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -96,7 +99,7 @@ class RepositoryRoles extends React.Component<Props> {
|
||||
}
|
||||
return (
|
||||
<Notification type="info">
|
||||
{t("repositoryRole.noPermissionRoles")}
|
||||
{t("repositoryRole.overview.noPermissionRoles")}
|
||||
</Notification>
|
||||
);
|
||||
}
|
||||
@@ -106,7 +109,7 @@ class RepositoryRoles extends React.Component<Props> {
|
||||
if (canAddRoles) {
|
||||
return (
|
||||
<CreateButton
|
||||
label={t("repositoryRole.createButton")}
|
||||
label={t("repositoryRole.overview.createButton")}
|
||||
link={`${baseUrl}/create`}
|
||||
/>
|
||||
);
|
||||
@@ -123,7 +126,7 @@ const mapStateToProps = (state, ownProps) => {
|
||||
const page = urls.getPageFromMatch(match);
|
||||
const canAddRoles = isPermittedToCreateRoles(state);
|
||||
const list = selectListAsCollection(state);
|
||||
const rolesLink = getRolesLink(state);
|
||||
const rolesLink = getRepositoryRolesLink(state);
|
||||
|
||||
return {
|
||||
roles,
|
||||
|
||||
@@ -81,8 +81,6 @@ class SingleRepositoryRole extends React.Component<Props> {
|
||||
return (
|
||||
<>
|
||||
<Title title={t("repositoryRole.title")} />
|
||||
<div className="columns">
|
||||
<div className="column is-three-quarters">
|
||||
<Route
|
||||
path={`${url}/info`}
|
||||
component={() => <PermissionRoleDetail role={role} url={url} />}
|
||||
@@ -99,8 +97,6 @@ class SingleRepositoryRole extends React.Component<Props> {
|
||||
props={extensionProps}
|
||||
renderAll={true}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -159,10 +159,6 @@ export function getSvnConfigLink(state: Object) {
|
||||
return getLink(state, "svnConfig");
|
||||
}
|
||||
|
||||
export function getRolesLink(state: Object) {
|
||||
return getLink(state, "repositoryRoles");
|
||||
}
|
||||
|
||||
export function getUserAutoCompleteLink(state: Object): string {
|
||||
const link = getLinkCollection(state, "autocomplete").find(
|
||||
i => i.name === "users"
|
||||
|
||||
@@ -7,12 +7,15 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class PermissionListDto extends HalRepresentation {
|
||||
|
||||
@NotNull
|
||||
private String[] permissions;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -8,6 +8,7 @@ import sonia.scm.security.PermissionDescriptor;
|
||||
import sonia.scm.web.VndMediaType;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.validation.Valid;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.PUT;
|
||||
@@ -69,7 +70,7 @@ public class UserPermissionResource {
|
||||
@ResponseCode(code = 500, condition = "internal server error")
|
||||
})
|
||||
@TypeHint(TypeHint.NO_CONTENT.class)
|
||||
public Response overwritePermissions(@PathParam("id") String id, PermissionListDto newPermissions) {
|
||||
public Response overwritePermissions(@PathParam("id") String id, @Valid PermissionListDto newPermissions) {
|
||||
Collection<PermissionDescriptor> permissionDescriptors = Arrays.stream(newPermissions.getPermissions())
|
||||
.map(PermissionDescriptor::new)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
@@ -50,6 +50,7 @@ import sonia.scm.plugin.DefaultPluginLoader;
|
||||
import sonia.scm.plugin.Plugin;
|
||||
import sonia.scm.plugin.PluginException;
|
||||
import sonia.scm.plugin.PluginLoadException;
|
||||
import sonia.scm.plugin.PluginLoader;
|
||||
import sonia.scm.plugin.PluginWrapper;
|
||||
import sonia.scm.plugin.PluginsInternal;
|
||||
import sonia.scm.plugin.SmpArchive;
|
||||
@@ -137,6 +138,19 @@ public class BootstrapContextListener implements ServletContextListener {
|
||||
|
||||
File pluginDirectory = getPluginDirectory();
|
||||
|
||||
createContextListener(pluginDirectory);
|
||||
|
||||
contextListener.contextInitialized(sce);
|
||||
|
||||
// register for restart events
|
||||
if (!registered && (SCMContext.getContext().getStage() == Stage.DEVELOPMENT)) {
|
||||
logger.info("register for restart events");
|
||||
ScmEventBus.getInstance().register(this);
|
||||
registered = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void createContextListener(File pluginDirectory) {
|
||||
try {
|
||||
if (!isCorePluginExtractionDisabled()) {
|
||||
extractCorePlugins(context, pluginDirectory);
|
||||
@@ -148,22 +162,9 @@ public class BootstrapContextListener implements ServletContextListener {
|
||||
|
||||
Set<PluginWrapper> plugins = PluginsInternal.collectPlugins(cl, pluginDirectory.toPath());
|
||||
|
||||
DefaultPluginLoader pluginLoader = new DefaultPluginLoader(context, cl, plugins);
|
||||
PluginLoader pluginLoader = new DefaultPluginLoader(context, cl, plugins);
|
||||
|
||||
Module scmContextListenerModule = new ScmContextListenerModule();
|
||||
BootstrapModule bootstrapModule = new BootstrapModule(pluginLoader);
|
||||
ScmInitializerModule scmInitializerModule = new ScmInitializerModule();
|
||||
EagerSingletonModule eagerSingletonModule = new EagerSingletonModule();
|
||||
ScmEventBusModule scmEventBusModule = new ScmEventBusModule();
|
||||
|
||||
Injector bootstrapInjector =
|
||||
Guice.createInjector(
|
||||
bootstrapModule,
|
||||
scmContextListenerModule,
|
||||
scmEventBusModule,
|
||||
scmInitializerModule,
|
||||
eagerSingletonModule
|
||||
);
|
||||
Injector bootstrapInjector = createBootstrapInjector(pluginLoader);
|
||||
|
||||
processUpdates(pluginLoader, bootstrapInjector);
|
||||
|
||||
@@ -171,19 +172,25 @@ public class BootstrapContextListener implements ServletContextListener {
|
||||
} catch (IOException ex) {
|
||||
throw new PluginLoadException("could not load plugins", ex);
|
||||
}
|
||||
|
||||
contextListener.contextInitialized(sce);
|
||||
|
||||
// register for restart events
|
||||
if (!registered
|
||||
&& (SCMContext.getContext().getStage() == Stage.DEVELOPMENT)) {
|
||||
logger.info("register for restart events");
|
||||
ScmEventBus.getInstance().register(this);
|
||||
registered = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void processUpdates(DefaultPluginLoader pluginLoader, Injector bootstrapInjector) {
|
||||
private Injector createBootstrapInjector(PluginLoader pluginLoader) {
|
||||
Module scmContextListenerModule = new ScmContextListenerModule();
|
||||
BootstrapModule bootstrapModule = new BootstrapModule(pluginLoader);
|
||||
ScmInitializerModule scmInitializerModule = new ScmInitializerModule();
|
||||
EagerSingletonModule eagerSingletonModule = new EagerSingletonModule();
|
||||
ScmEventBusModule scmEventBusModule = new ScmEventBusModule();
|
||||
|
||||
return Guice.createInjector(
|
||||
bootstrapModule,
|
||||
scmContextListenerModule,
|
||||
scmEventBusModule,
|
||||
scmInitializerModule,
|
||||
eagerSingletonModule
|
||||
);
|
||||
}
|
||||
|
||||
private void processUpdates(PluginLoader pluginLoader, Injector bootstrapInjector) {
|
||||
Injector updateInjector = bootstrapInjector.createChildInjector(new UpdateStepModule(pluginLoader));
|
||||
|
||||
UpdateEngine updateEngine = updateInjector.getInstance(UpdateEngine.class);
|
||||
@@ -403,7 +410,6 @@ public class BootstrapContextListener implements ServletContextListener {
|
||||
private static class ScmContextListenerModule extends AbstractModule {
|
||||
@Override
|
||||
protected void configure() {
|
||||
|
||||
install(new FactoryModuleBuilder().build(ScmContextListener.Factory.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import sonia.scm.SCMContext;
|
||||
import sonia.scm.SCMContextProvider;
|
||||
import sonia.scm.io.DefaultFileSystem;
|
||||
import sonia.scm.io.FileSystem;
|
||||
import sonia.scm.plugin.DefaultPluginLoader;
|
||||
import sonia.scm.plugin.PluginLoader;
|
||||
import sonia.scm.repository.RepositoryLocationResolver;
|
||||
import sonia.scm.repository.xml.PathBasedRepositoryLocationResolver;
|
||||
@@ -33,7 +32,7 @@ public class BootstrapModule extends AbstractModule {
|
||||
private final ClassOverrides overrides;
|
||||
private final PluginLoader pluginLoader;
|
||||
|
||||
BootstrapModule(DefaultPluginLoader pluginLoader) {
|
||||
BootstrapModule(PluginLoader pluginLoader) {
|
||||
this.overrides = ClassOverrides.findOverrides(pluginLoader.getUberClassLoader());
|
||||
this.pluginLoader = pluginLoader;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user