mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-12 16:35:45 +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)) {
|
||||
return (
|
||||
<>
|
||||
@@ -125,11 +131,7 @@ class RepositoryConfig extends React.Component<Props, State> {
|
||||
selectedBranch={this.state.selectedBranchName}
|
||||
disabled={disabled}
|
||||
/>
|
||||
<SubmitButton
|
||||
label={t("scm-git-plugin.repo-config.submit")}
|
||||
loading={submitPending}
|
||||
disabled={!this.state.selectedBranchName || disabled}
|
||||
/>
|
||||
{ submitButton }
|
||||
</form>
|
||||
<hr />
|
||||
</>
|
||||
|
||||
@@ -14,7 +14,8 @@ type Props = {
|
||||
value?: string,
|
||||
autofocus?: boolean,
|
||||
onChange: (value: string, name?: string) => void,
|
||||
helpText?: string
|
||||
helpText?: string,
|
||||
disabled?: boolean
|
||||
};
|
||||
|
||||
class Textarea extends React.Component<Props> {
|
||||
@@ -31,7 +32,7 @@ class Textarea extends React.Component<Props> {
|
||||
};
|
||||
|
||||
render() {
|
||||
const { placeholder, value, label, helpText } = this.props;
|
||||
const { placeholder, value, label, helpText, disabled } = this.props;
|
||||
|
||||
return (
|
||||
<div className="field">
|
||||
@@ -45,6 +46,7 @@ class Textarea extends React.Component<Props> {
|
||||
placeholder={placeholder}
|
||||
onChange={this.handleInput}
|
||||
value={value}
|
||||
disabled={!!disabled}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -71,7 +71,8 @@ class RepositoryForm extends React.Component<Props, State> {
|
||||
this.state.nameValidationError ||
|
||||
this.state.contactValidationError ||
|
||||
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;
|
||||
};
|
||||
|
||||
isModifiable = () => {
|
||||
return !!this.props.repository && !!this.props.repository._links.update;
|
||||
};
|
||||
|
||||
render() {
|
||||
const { loading, t } = this.props;
|
||||
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;
|
||||
if (this.props.repository) {
|
||||
// edit existing repo
|
||||
@@ -108,6 +123,7 @@ class RepositoryForm extends React.Component<Props, State> {
|
||||
validationError={this.state.contactValidationError}
|
||||
errorMessage={t("validation.contact-invalid")}
|
||||
helpText={t("help.contactHelpText")}
|
||||
disabled={disabled}
|
||||
/>
|
||||
|
||||
<Textarea
|
||||
@@ -115,12 +131,9 @@ class RepositoryForm extends React.Component<Props, State> {
|
||||
onChange={this.handleDescriptionChange}
|
||||
value={repository ? repository.description : ""}
|
||||
helpText={t("help.descriptionHelpText")}
|
||||
disabled={disabled}
|
||||
/>
|
||||
<SubmitButton
|
||||
disabled={!this.isValid()}
|
||||
loading={loading}
|
||||
label={t("repositoryForm.submit")}
|
||||
/>
|
||||
{submitButton}
|
||||
</form>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user