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

DDF-4429 Fixed shared workspace deletion reminder #4202

Merged
merged 4 commits into from
Jan 30, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 0 additions & 6 deletions ui/packages/catalog-ui-search/src/main/webapp/js/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,4 @@ module.exports = new (Backbone.Model.extend({
getCurrentQuery: function() {
return this.get('content').getCurrentQuery()
},
setWorkspaceRestrictions: function(workspaceId, restrictions) {
const metacard = this.getWorkspaceById(workspaceId)
restrictions.forEach(function(restriction) {
metacard.attributes[restriction.attribute] = restriction.values
})
},
}))()
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import { Restrictions, Access, Security, Entry } from '../../utils/security'
const user = require('component/singletons/user-instance')
const common = require('js/Common')
const announcement = require('component/announcement')
const store = require('../../../js/store.js')

type Props = {
id: number
Expand Down Expand Up @@ -120,9 +119,6 @@ export class Sharing extends React.Component<Props, State> {
if (res.status !== 200) {
throw new Error()
}

store.setWorkspaceRestrictions(this.props.id, attributes)

return res.json()
})
.then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import { hot } from 'react-hot-loader'
import withListenTo, { WithBackboneProps } from '../backbone-container'
import { Sharing } from '../sharing'
import { Security, Restrictions } from '../../utils/security'
import fetch from '../../utils/fetch'
const user = require('../../../component/singletons/user-instance.js')
const store = require('../../../js/store.js')
const lightboxInstance = require('../../../component/lightbox/lightbox.view.instance.js')
const wreqr = require('../../../js/wreqr.js')
const LoadingView = require('../../../component/loading/loading.view.js')
const ConfirmationView = require('../../../component/confirmation/confirmation.view.js')
const announcement = require('component/announcement')

type Props = {
workspace: any
Expand Down Expand Up @@ -142,28 +144,48 @@ class WorkspaceInteractions extends React.Component<Props, State> {
})
}
deletionPrompt = () => {
const workspace = store.getWorkspaceById(this.props.workspace.id)
const security = new Security(Restrictions.from(workspace))
fetch(`/search/catalog/internal/metacard/${this.props.workspace.id}`)
.then(response => {
if (response.status === 200) {
return response.json()
}

if (!security.isShared()) {
this.deleteWorkspace()
} else {
const self = this
this.props.listenTo(
ConfirmationView.generateConfirmation({
prompt:
'Are you sure you want to delete this workspace? It has been shared with other users.',
no: 'Cancel',
yes: 'Delete',
}),
'change:choice',
function(confirmation: any) {
if (confirmation.get('choice')) {
self.deleteWorkspace()
}
}.bind(this)
)
}
throw new Error()
})
.then(data => {
const metacard = data.metacards[0]
const security = new Security(Restrictions.from(metacard))

if (!security.isShared()) {
this.deleteWorkspace()
} else {
const self = this
this.props.listenTo(
ConfirmationView.generateConfirmation({
prompt:
'Are you sure you want to delete this workspace? It has been shared with other users.',
no: 'Cancel',
yes: 'Delete',
}),
'change:choice',
function(confirmation: any) {
if (confirmation.get('choice')) {
self.deleteWorkspace()
}
}.bind(this)
)
}
})
.catch(function() {
announcement.announce(
{
title: 'Error',
message: 'Deletion failed',
type: 'error',
},
1500
)
})
}
saveWorkspace = () => {
this.props.workspace.save()
Expand Down