Skip to content

Commit

Permalink
graph webhook support for private repos, warning messages refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo-cavazzi committed Mar 7, 2019
1 parent 6a82c24 commit a2021a1
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 54 deletions.
2 changes: 1 addition & 1 deletion src/api-client/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/model/RenkuModels.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion src/project/Project.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ class View extends Component {
stopNotebookServer: (serverName) => {
this.stopNotebookServer(serverName);
},
onGraphWebhookCreate: (e) => {
createGraphWebhook: (e) => {
e.preventDefault();
this.createGraphWebhook();
},
Expand Down
109 changes: 69 additions & 40 deletions src/project/Project.present.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'};
Expand Down Expand Up @@ -137,67 +144,89 @@ class MergeRequestSuggestions extends Component {
*/
class KnowledgeGraphIntegrationWarningBanner extends Component {
render() {
const errorKnowledgeGraph = this.props.core.graphWebhookError;
if (errorKnowledgeGraph) {
return(
<Row>
<Col xs={12} md={12}>
<UncontrolledAlert color="danger">
Some error occured with the Knowledge-graph integration.
</UncontrolledAlert>
</Col>
</Row>
const status = this.props.core.graphWebhookStatus;
if (status === false) {
const isPrivate = this.props.visibility && this.props.visibility.level === "private" ? true : false;
return (
<KnowledgeGraphWarning
webhook={this.props.core.graphWebhookCreated}
create={this.props.createGraphWebhook}
isPrivate={isPrivate} />
)
}

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 (
<Row>
<Col xs={12} md={12}>
<KnowledgeGraphWarning
createWebhook={ this.props.onGraphWebhookCreate }
loading={ loading }
done={ isProjectedIntegrated }
/>
</Col>
</Row>
)
const error = webhookError(status);
if (error) {
return (
<UncontrolledAlert color="warning">
An error has occured while checking webhook state: &quot;
<span className="font-italic">{status.message}</span>&quot;
<br />Please try to reload the page.
</UncontrolledAlert>
)
}
return null;
}
}

class KnowledgeGraphWarning extends Component {
render() {
if (this.props.done) {
const webhook = this.props.webhook;
if (webhook === true) {
return (
<UncontrolledAlert color="success">
Webhook successfully created.
Knowledge-graph integration successfully activated.
</UncontrolledAlert>
)
}
return (
<UncontrolledAlert color="warning">
Knowledge-graph integration is not turned on. <KnowledgeGraphLink {...this.props}/>
</UncontrolledAlert>
)
else if (webhook === false || webhook === SpecialPropVal.UPDATING) {
const updating = webhook === SpecialPropVal.UPDATING ? true : false;
return (
<UncontrolledAlert color="warning">
Knowledge-graph integration is turned off. <KnowledgeGraphLink {...this.props} updating={updating} />
<KnowledgeGraphPrivateWarning {...this.props} />
</UncontrolledAlert>
)
}
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 (
<UncontrolledAlert color="danger">
{error}
<br />Try again: <KnowledgeGraphLink {...this.props} />
</UncontrolledAlert>
)
}
}
}

class KnowledgeGraphPrivateWarning extends Component {
render() {
if (!this.props.isPrivate) return null;
return [
<br key="wrapword" />,
<span key="warning" className="font-italic">
<span className="font-weight-bold">WARNING! </span>
Some metadata may become public even for private projects. This is not reversible.
</span>
]
}
}

class KnowledgeGraphLink extends Component {
render() {
if (this.props.loading) {
if (this.props.updating) {
return (
<span>
Turning it on... <Loader size="12" inline="true" />
</span>
<span>Turning it on... <Loader size="12" inline="true" /></span>
)
}
return (
<Button color="link alert-link" onClick={this.props.createWebhook}>Turn it on now.</Button>
<Button color="link alert-link" onClick={this.props.create}>Turn it on now.</Button>
)
}
}
Expand Down
19 changes: 7 additions & 12 deletions src/project/Project.state.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
}

Expand Down
8 changes: 8 additions & 0 deletions src/project/new/ProjectNew.present.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,19 @@ class DataVisibility extends Component {
const options = visibilities.map(v =>
<option key={v.value} value={v.value}>{v.name}</option>
)
let warningPrivate = null;
if (this.props.value === "private") {
warningPrivate = <FormText color="danger">
Please be aware that some metadata may become public even for private projects
due to knowledge-graph integration.
</FormText>;
}
return <FormGroup>
<Label>Visibility</Label>
<Input type="select" placeholder="visibility" value={this.props.value} onChange={this.props.onChange}>
{options}
</Input>
{warningPrivate}
<FormText color="muted">{vizExplanation}</FormText>
</FormGroup>
}
Expand Down

0 comments on commit a2021a1

Please sign in to comment.