Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply correct visibility limitations on fork #2299

Merged
merged 2 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/src/project/Project.present.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ class ForkProjectModal extends Component {
client={this.props.client}
forkedId={this.props.id}
forkedTitle={this.props.title}
projectVisibility={this.props.projectVisibility}
toggleModal={this.toggleFunction}
/>
);
Expand Down Expand Up @@ -1007,6 +1008,7 @@ function ProjectCollaborationFork(props) {
client={props.client}
forkedId={props.metadata.id}
forkedTitle={props.metadata.title}
projectVisibility={props.metadata.visibility}
toggleModal={null}
/>
</Col>
Expand Down
4 changes: 2 additions & 2 deletions client/src/project/new/ProjectNew.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function addForkNotification(notifications, url, info, startingLocation, success


function ForkProject(props) {
const { client, forkedId, forkedTitle, toggleModal } = props;
const { client, forkedId, forkedTitle, projectVisibility, toggleModal } = props;
const namespaces = useGetNamespaces(true);
const { projectsMember, isFetchingProjects } = useGetUserProjects();

Expand All @@ -107,7 +107,7 @@ function ForkProject(props) {
const [forkVisibilityError, setForkVisibilityError] = useState(null);
const [forkUrl, setForkUrl] = useState(null);

const { availableVisibilities, isFetchingVisibilities } = useGetVisibilities(fullNamespace);
const { availableVisibilities, isFetchingVisibilities } = useGetVisibilities(fullNamespace, projectVisibility);
const { logged, data: { username } = null } = useSelector( (state) => state.stateModel.user);

const history = useHistory();
Expand Down
14 changes: 8 additions & 6 deletions client/src/utils/customHooks/UseGetVisibilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,18 @@ import { useGetGroupByPathQuery } from "../../features/projects/ProjectApi";
* UseGetVisibilities.ts
* hook to get visibilities and fetch groups if the namespace is of type group
*/
function useGetVisibilities(namespace: any) {
const { data, isFetching, isLoading } =
useGetGroupByPathQuery(namespace?.full_path, { skip: !namespace || namespace?.kind !== "group" });
function useGetVisibilities(namespace: any, bound: string | undefined) {
const { data, isFetching, isLoading } = useGetGroupByPathQuery(namespace?.full_path, {
skip: !namespace || namespace?.kind !== "group",
});
const [availableVisibilities, setAvailableVisibilities] = useState<any>(null);

useEffect(() => {
if (isFetching || isLoading || !namespace)
return;
if (isFetching || isLoading || !namespace) return;

let options: string[] = [];
if (bound) options.push(bound);

if (namespace?.kind === "user") {
options.push("public");
setAvailableVisibilities(computeVisibilities(options));
Expand All @@ -44,7 +46,7 @@ function useGetVisibilities(namespace: any) {
options.push(data.visibility);
setAvailableVisibilities(computeVisibilities(options));
}
}, [isFetching, isLoading, data, namespace]);
}, [bound, isFetching, isLoading, data, namespace]);

return { availableVisibilities, isFetchingVisibilities: isFetching };
}
Expand Down
24 changes: 24 additions & 0 deletions tests/cypress/e2e/local/project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,36 @@ describe("display a project", () => {
});
});

describe("fork a project", () => {
const fixtures = new Fixtures(cy);
fixtures.useMockedData = true;
beforeEach(() => {
fixtures.config().versions().userTest();
fixtures.projects().landingUserProjects();
fixtures.projectLockStatus().projectMigrationUpToDate();
fixtures.namespaces();
cy.visit("/projects/e2e/local-test-project");
});

it("displays fork modal correctly", () => {
fixtures.projectTest(undefined, { visibility: "private" });
cy.wait("@getProject");
cy.get("#fork-project").click();
cy.wait("@getNamespaces");
cy.get_cy("visibility-private").should("be.enabled");
cy.get_cy("visibility-internal").should("be.disabled");
cy.get_cy("visibility-public").should("be.disabled");

});
});

describe("display migration information", () => {
const fixtures = new Fixtures(cy);

beforeEach(() => {
fixtures.config().versions().userTest();
fixtures.projects().landingUserProjects().projectTest();
fixtures.namespaces();
cy.visit("/projects/e2e/local-test-project");
});

Expand Down
18 changes: 12 additions & 6 deletions tests/cypress/support/renkulab-fixtures/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,21 @@ function Projects<T extends FixturesConstructor>(Parent: T) {
readmeName: "getReadme",
validationName: "getValidation",
coreVersion: 8
},
overrides = {
visibility: "public"
}
) {
const { projectName } = names;
cy.intercept(
"/ui-server/api/projects/e2e%2Flocal-test-project?statistics=true&doNotTrack=*",
{
fixture: "project/test-project.json"
}
).as(projectName);
const { visibility } = overrides;
cy.fixture("project/test-project.json").then((project) => {
project["visibility"] = visibility;
cy.intercept(
"/ui-server/api/projects/e2e%2Flocal-test-project?statistics=true&doNotTrack=*",
project
).as(projectName);
});

return this.projectTestContents(names);
}

Expand Down