mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-13 00:45:44 +01:00
Fix repo config for user without permission
Disable fields and remove submit buttons when user has not permission, aka no config links.
This commit is contained in:
@@ -112,6 +112,12 @@ class RepositoryConfig extends React.Component<Props, State> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const submitButton = disabled? null: <SubmitButton
|
||||||
|
label={t("scm-git-plugin.repo-config.submit")}
|
||||||
|
loading={submitPending}
|
||||||
|
disabled={!this.state.selectedBranchName}
|
||||||
|
/>;
|
||||||
|
|
||||||
if (!(loadingBranches || loadingDefaultBranch)) {
|
if (!(loadingBranches || loadingDefaultBranch)) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -125,11 +131,7 @@ class RepositoryConfig extends React.Component<Props, State> {
|
|||||||
selectedBranch={this.state.selectedBranchName}
|
selectedBranch={this.state.selectedBranchName}
|
||||||
disabled={disabled}
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
<SubmitButton
|
{ submitButton }
|
||||||
label={t("scm-git-plugin.repo-config.submit")}
|
|
||||||
loading={submitPending}
|
|
||||||
disabled={!this.state.selectedBranchName || disabled}
|
|
||||||
/>
|
|
||||||
</form>
|
</form>
|
||||||
<hr />
|
<hr />
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ type Props = {
|
|||||||
value?: string,
|
value?: string,
|
||||||
autofocus?: boolean,
|
autofocus?: boolean,
|
||||||
onChange: (value: string, name?: string) => void,
|
onChange: (value: string, name?: string) => void,
|
||||||
helpText?: string
|
helpText?: string,
|
||||||
|
disabled?: boolean
|
||||||
};
|
};
|
||||||
|
|
||||||
class Textarea extends React.Component<Props> {
|
class Textarea extends React.Component<Props> {
|
||||||
@@ -31,7 +32,7 @@ class Textarea extends React.Component<Props> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { placeholder, value, label, helpText } = this.props;
|
const { placeholder, value, label, helpText, disabled } = this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="field">
|
<div className="field">
|
||||||
@@ -45,6 +46,7 @@ class Textarea extends React.Component<Props> {
|
|||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
onChange={this.handleInput}
|
onChange={this.handleInput}
|
||||||
value={value}
|
value={value}
|
||||||
|
disabled={!!disabled}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -71,7 +71,8 @@ class RepositoryForm extends React.Component<Props, State> {
|
|||||||
this.state.nameValidationError ||
|
this.state.nameValidationError ||
|
||||||
this.state.contactValidationError ||
|
this.state.contactValidationError ||
|
||||||
this.isFalsy(repository.name) ||
|
this.isFalsy(repository.name) ||
|
||||||
(namespaceStrategy === CUSTOM_NAMESPACE_STRATEGY && this.isFalsy(repository.namespace))
|
(namespaceStrategy === CUSTOM_NAMESPACE_STRATEGY &&
|
||||||
|
this.isFalsy(repository.namespace))
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -86,10 +87,24 @@ class RepositoryForm extends React.Component<Props, State> {
|
|||||||
return !this.props.repository;
|
return !this.props.repository;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
isModifiable = () => {
|
||||||
|
return !!this.props.repository && !!this.props.repository._links.update;
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { loading, t } = this.props;
|
const { loading, t } = this.props;
|
||||||
const repository = this.state.repository;
|
const repository = this.state.repository;
|
||||||
|
|
||||||
|
const disabled = !this.isModifiable() && !this.isCreateMode();
|
||||||
|
|
||||||
|
const submitButton = disabled ? null : (
|
||||||
|
<SubmitButton
|
||||||
|
disabled={!this.isValid()}
|
||||||
|
loading={loading}
|
||||||
|
label={t("repositoryForm.submit")}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
|
||||||
let subtitle = null;
|
let subtitle = null;
|
||||||
if (this.props.repository) {
|
if (this.props.repository) {
|
||||||
// edit existing repo
|
// edit existing repo
|
||||||
@@ -108,6 +123,7 @@ class RepositoryForm extends React.Component<Props, State> {
|
|||||||
validationError={this.state.contactValidationError}
|
validationError={this.state.contactValidationError}
|
||||||
errorMessage={t("validation.contact-invalid")}
|
errorMessage={t("validation.contact-invalid")}
|
||||||
helpText={t("help.contactHelpText")}
|
helpText={t("help.contactHelpText")}
|
||||||
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Textarea
|
<Textarea
|
||||||
@@ -115,12 +131,9 @@ class RepositoryForm extends React.Component<Props, State> {
|
|||||||
onChange={this.handleDescriptionChange}
|
onChange={this.handleDescriptionChange}
|
||||||
value={repository ? repository.description : ""}
|
value={repository ? repository.description : ""}
|
||||||
helpText={t("help.descriptionHelpText")}
|
helpText={t("help.descriptionHelpText")}
|
||||||
|
disabled={disabled}
|
||||||
/>
|
/>
|
||||||
<SubmitButton
|
{submitButton}
|
||||||
disabled={!this.isValid()}
|
|
||||||
loading={loading}
|
|
||||||
label={t("repositoryForm.submit")}
|
|
||||||
/>
|
|
||||||
</form>
|
</form>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user