Commit 5d2d5a71 authored by Samantha Ming's avatar Samantha Ming

Adjust fork form visibility logic

Dynamically creating the allowed visibility logic.
This will make it easier to support issues:
- https://gitlab.com/gitlab-org/gitlab/-/issues/329575
- https://gitlab.com/gitlab-org/gitlab/-/issues/331620
parent 733f5040
...@@ -26,10 +26,10 @@ const PRIVATE_VISIBILITY = 'private'; ...@@ -26,10 +26,10 @@ const PRIVATE_VISIBILITY = 'private';
const INTERNAL_VISIBILITY = 'internal'; const INTERNAL_VISIBILITY = 'internal';
const PUBLIC_VISIBILITY = 'public'; const PUBLIC_VISIBILITY = 'public';
const ALLOWED_VISIBILITY = { const VISIBILITY_LEVEL = {
private: [PRIVATE_VISIBILITY], [PRIVATE_VISIBILITY]: 0,
internal: [INTERNAL_VISIBILITY, PRIVATE_VISIBILITY], [INTERNAL_VISIBILITY]: 10,
public: [INTERNAL_VISIBILITY, PRIVATE_VISIBILITY, PUBLIC_VISIBILITY], [PUBLIC_VISIBILITY]: 20,
}; };
const initFormField = ({ value, required = true, skipValidation = false }) => ({ const initFormField = ({ value, required = true, skipValidation = false }) => ({
...@@ -124,14 +124,23 @@ export default { ...@@ -124,14 +124,23 @@ export default {
projectUrl() { projectUrl() {
return `${gon.gitlab_url}/`; return `${gon.gitlab_url}/`;
}, },
projectAllowedVisibility() { projectVisibilityLevel() {
return ALLOWED_VISIBILITY[this.projectVisibility]; return VISIBILITY_LEVEL[this.projectVisibility];
}, },
namespaceAllowedVisibility() { namespaceVisibilityLevel() {
return ( const visibility = this.form.fields.namespace.value?.visibility || PUBLIC_VISIBILITY;
ALLOWED_VISIBILITY[this.form.fields.namespace.value?.visibility] || return VISIBILITY_LEVEL[visibility];
ALLOWED_VISIBILITY[PUBLIC_VISIBILITY] },
); visibilityLevelCap() {
return Math.min(this.projectVisibilityLevel, this.namespaceVisibilityLevel);
},
allowedVisibilityLevels() {
return Object.entries(VISIBILITY_LEVEL).reduce((levels, [levelName, levelValue]) => {
if (levelValue <= this.visibilityLevelCap) {
levels.push(levelName);
}
return levels;
}, []);
}, },
visibilityLevels() { visibilityLevels() {
return [ return [
...@@ -179,11 +188,8 @@ export default { ...@@ -179,11 +188,8 @@ export default {
const { data } = await axios.get(this.endpoint); const { data } = await axios.get(this.endpoint);
this.namespaces = data.namespaces; this.namespaces = data.namespaces;
}, },
isVisibilityLevelDisabled(visibilityLevel) { isVisibilityLevelDisabled(visibility) {
return !( return !this.allowedVisibilityLevels.includes(visibility);
this.projectAllowedVisibility.includes(visibilityLevel) &&
this.namespaceAllowedVisibility.includes(visibilityLevel)
);
}, },
async onSubmit() { async onSubmit() {
this.form.showValidation = true; this.form.showValidation = true;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment