From a2021a15f250aebb05d44dea93b14b07cba562fb Mon Sep 17 00:00:00 2001 From: lorenzo-cavazzi Date: Thu, 7 Mar 2019 15:51:52 +0100 Subject: [PATCH] graph webhook support for private repos, warning messages refactoring --- src/api-client/graph.js | 2 +- src/model/RenkuModels.js | 2 + src/project/Project.js | 2 +- src/project/Project.present.js | 109 ++++++++++++++++---------- src/project/Project.state.js | 19 ++--- src/project/new/ProjectNew.present.js | 8 ++ 6 files changed, 88 insertions(+), 54 deletions(-) diff --git a/src/api-client/graph.js b/src/api-client/graph.js index 5fa813c275..c2815ed129 100644 --- a/src/api-client/graph.js +++ b/src/api-client/graph.js @@ -41,7 +41,7 @@ function addGraphMethods(client) { if (resp.status === 200 || resp.status === 201) { return true; } - else if (resp.status === 401) { + else if (resp.status === 404) { return false; } else { diff --git a/src/model/RenkuModels.js b/src/model/RenkuModels.js index 59ca5a8a13..eeca9d18f5 100644 --- a/src/model/RenkuModels.js +++ b/src/model/RenkuModels.js @@ -64,6 +64,8 @@ const projectSchema = new Schema({ external_url: {initial: '',}, path_with_namespace: {initial: null}, owner: {initial: null}, + graphWebhookStatus: {initial: null}, + graphWebhookCreated: {initial: null} } }, visibility: { diff --git a/src/project/Project.js b/src/project/Project.js index 5eb9259def..e44850d478 100644 --- a/src/project/Project.js +++ b/src/project/Project.js @@ -275,7 +275,7 @@ class View extends Component { stopNotebookServer: (serverName) => { this.stopNotebookServer(serverName); }, - onGraphWebhookCreate: (e) => { + createGraphWebhook: (e) => { e.preventDefault(); this.createGraphWebhook(); }, diff --git a/src/project/Project.present.js b/src/project/Project.present.js index c87d89713d..bb736683fb 100644 --- a/src/project/Project.present.js +++ b/src/project/Project.present.js @@ -77,6 +77,13 @@ function isRequestPending(props, request) { return requests[request] === SpecialPropVal.UPDATING; } +function webhookError(props) { + if (props == null || props === SpecialPropVal.UPDATING || props === true || props === false) { + return false; + } + return true; +} + class ImageBuildInfo extends Component { render() { const imageBuild = this.props.imageBuild || {status: 'success'}; @@ -137,67 +144,89 @@ class MergeRequestSuggestions extends Component { */ class KnowledgeGraphIntegrationWarningBanner extends Component { render() { - const errorKnowledgeGraph = this.props.core.graphWebhookError; - if (errorKnowledgeGraph) { - return( - - - - Some error occured with the Knowledge-graph integration. - - - + const status = this.props.core.graphWebhookStatus; + if (status === false) { + const isPrivate = this.props.visibility && this.props.visibility.level === "private" ? true : false; + return ( + ) } - - const doesUserHaveRights = this.props.core.graphWebhookPossible; - if (!doesUserHaveRights) return null; - const isProjectedIntegrated = this.props.core.graphWebhookAvailable; - const created = this.props.core.graphWebhookCreated; - if (isProjectedIntegrated && !created) return null; - const loading = this.props.core.graphWebhookLoading; - return ( - - - - - - ) + const error = webhookError(status); + if (error) { + return ( + + An error has occured while checking webhook state: " + {status.message}" +
Please try to reload the page. +
+ ) + } + return null; } } class KnowledgeGraphWarning extends Component { render() { - if (this.props.done) { + const webhook = this.props.webhook; + if (webhook === true) { return ( - Webhook successfully created. + Knowledge-graph integration successfully activated. ) } - return ( - - Knowledge-graph integration is not turned on. - - ) + else if (webhook === false || webhook === SpecialPropVal.UPDATING) { + const updating = webhook === SpecialPropVal.UPDATING ? true : false; + return ( + + Knowledge-graph integration is turned off. + + + ) + } + else { + let error; + if (webhookError(webhook)) { + error = `An error has occured with the Knowledge-graph integration: "${webhook.message}".`; + } + else { + error = "An unknown error has occured with the Knowledge-graph integration."; + } + return ( + + {error} +
Try again: +
+ ) + } + } +} + +class KnowledgeGraphPrivateWarning extends Component { + render() { + if (!this.props.isPrivate) return null; + return [ +
, + + WARNING! + Some metadata may become public even for private projects. This is not reversible. + + ] } } class KnowledgeGraphLink extends Component { render() { - if (this.props.loading) { + if (this.props.updating) { return ( - - Turning it on... - + Turning it on... ) } return ( - + ) } } diff --git a/src/project/Project.state.js b/src/project/Project.state.js index 30bfc3a435..199463d69d 100644 --- a/src/project/Project.state.js +++ b/src/project/Project.state.js @@ -37,30 +37,25 @@ class ProjectModel extends StateModel { } fetchGraphWebhookStatus(client, id) { - // temporary value to avoid fake warning. - this.set('core.graphWebhookAvailable', true); + this.set('core.graphWebhookCreated', false); + this.setUpdating({core: {graphWebhookStatus: true}}); return client.checkGraphWebhook(id) .then((resp) => { - this.set('core.graphWebhookAvailable', resp); + this.set('core.graphWebhookStatus', resp); }) .catch((err) => { - this.set('core.graphWebhookError', err); + this.set('core.graphWebhookStatus', err); }); } createGraphWebhook(client, id) { - this.set('core.graphWebhookLoading', true); + this.setUpdating({core: {graphWebhookCreated: true}}); return client.createGraphWebhook(id) .then((resp) => { - this.set('core.graphWebhookAvailable', resp); - this.set('core.graphWebhookLoading', false); - if (resp) { - // we need this to display a positive feedback when the webhook is created - this.set('core.graphWebhookCreated', true); - } + this.set('core.graphWebhookCreated', resp); }) .catch((err) => { - this.set('core.graphWebhookError', err); + this.set('core.graphWebhookCreated', err); }); } diff --git a/src/project/new/ProjectNew.present.js b/src/project/new/ProjectNew.present.js index be832454e5..4811b9d974 100644 --- a/src/project/new/ProjectNew.present.js +++ b/src/project/new/ProjectNew.present.js @@ -192,11 +192,19 @@ class DataVisibility extends Component { const options = visibilities.map(v => ) + let warningPrivate = null; + if (this.props.value === "private") { + warningPrivate = + Please be aware that some metadata may become public even for private projects + due to knowledge-graph integration. + ; + } return {options} + {warningPrivate} {vizExplanation} }