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

fix(client): restore projects data used by datasets #1656

Merged
merged 2 commits into from
Jan 25, 2022
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
8 changes: 7 additions & 1 deletion client/src/api-client/project.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,13 @@ function addProjectMethods(client) {
namespace {
fullPath
}
path
path,
httpUrlToRepo,
userPermissions {
adminProject,
pushCode,
removeProject
}
}
}
}`;
Expand Down
8 changes: 7 additions & 1 deletion client/src/dataset/Dataset.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export default function ShowDataset(props) {

const [datasetKg, setDatasetKg] = useState();
const [datasetFiles, setDatasetFiles] = useState();
const [fetchedKg, setFetchedKg] = useState(false);

const dataset = useMemo(() =>
mapDataset(props.datasets ?
props.datasets.find(dataset => dataset.name === props.datasetId)
Expand Down Expand Up @@ -79,9 +81,12 @@ export default function ShowDataset(props) {
const id = props.insideProject ? dataset.identifier : props.identifier;
props.client.fetchDatasetFromKG(id)
.then((datasetInfo) => {
if (!unmounted && datasetKg === undefined && datasetInfo !== undefined)
if (!unmounted && datasetKg === undefined && datasetInfo !== undefined) {
setFetchedKg(true);
setDatasetKg(datasetInfo);
}
}).catch(error => {
setFetchedKg(true);
if (!unmounted && error.case === API_ERRORS.notFoundError)
setFetchError({ code: 404, message: "dataset not found or missing permissions" });
else if (!unmounted && error.case === API_ERRORS.internalServerError)
Expand All @@ -98,6 +103,7 @@ export default function ShowDataset(props) {
dataset={dataset}
datasets={props.datasets}
fetchError={fetchError}
fetchedKg={fetchedKg}
fileContentUrl={props.fileContentUrl}
history={props.history}
httpProjectUrl={props.httpProjectUrl}
Expand Down
2 changes: 1 addition & 1 deletion client/src/dataset/Dataset.present.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ export default function DatasetView(props) {
: null
}
{
dataset.insideKg === false && props.projectInsideKg === true ?
props.fetchedKg === true && dataset.insideKg === false && props.projectInsideKg === true ?
<WarnAlert className="not-in-kg-warning">
<strong>This dataset is not in the Knowledge Graph;</strong> this means that some
operations on it are not possible.
Expand Down
6 changes: 4 additions & 2 deletions client/src/dataset/addtoproject/DatasetAdd.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,12 @@ function AddDataset(props) {

const projectOptions = handlers.getFormDraftFieldProperty("project", ["options"]);

const selectedProject = projectOptions.find((project)=>
const selectedProject = projectOptions.find((project) =>
project.value === mappedInputs.project);

props.client.checkMigration(props.httpProjectUrl).then((response) => {
// TODO: is this what we want? Should we check that both the target and the source are up-to-date?
const target = selectedProject.value; // It was props.httpProjectUrl, but it's not always set
props.client.checkMigration(target).then((response) => {
if (response && response.error !== undefined) {
handlers.setSubmitLoader({ value: false, text: "" });
handlers.setServerErrors(response.error.reason);
Expand Down
26 changes: 20 additions & 6 deletions client/src/project/shared/Projects.state.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
* Projects controller code.
*/

import { ACCESS_LEVELS } from "../../api-client";


class ProjectsCoordinator {
constructor(client, model) {
this.client = client;
Expand All @@ -31,11 +34,22 @@ class ProjectsCoordinator {

_starredProjectMetadata(project) {
let accessLevel = 0;
if (project.permissions && project.permissions.project_access)
accessLevel = Math.max(accessLevel, project.permissions.project_access.access_level);

if (project.permissions && project.permissions.group_access)
accessLevel = Math.max(accessLevel, project.permissions.group_access.access_level);
// check permissions from v4 API
if (project?.permissions) {
if (project?.permissions?.project_access)
accessLevel = Math.max(accessLevel, project.permissions.project_access.access_level);
if (project?.permissions?.group_access)
accessLevel = Math.max(accessLevel, project.permissions.group_access.access_level);
}
// check permissions from GraphQL -- // ? REF: https://docs.gitlab.com/ee/user/permissions.html
else if (project?.userPermissions) {
if (project.userPermissions.removeProject)
accessLevel = Math.max(accessLevel, ACCESS_LEVELS.OWNER);
else if (project.userPermissions.adminProject)
accessLevel = Math.max(accessLevel, ACCESS_LEVELS.MAINTAINER);
else if (project.userPermissions.pushCode)
accessLevel = Math.max(accessLevel, ACCESS_LEVELS.DEVELOPER);
}

// Project id can be a number e.g. 1234 or a string with the format: gid://gitlab/Project/1234
const projectFullId = typeof (project.id) === "number" ? [] : project.id.split("/");
Expand All @@ -51,7 +65,7 @@ class ProjectsCoordinator {
owner: project.owner,
last_activity_at: project.last_activity_at,
access_level: accessLevel,
http_url_to_repo: project.http_url_to_repo,
http_url_to_repo: project.http_url_to_repo ? project.http_url_to_repo : project.httpUrlToRepo,
namespace: project.namespace,
path: project.path,
avatar_url: project.avatar_url
Expand Down