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

Swik 907 delete deck and transfer ownership #1073

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
ca07914
[SWIK-907_delete_deck_and_transfer_ownership] Started to work on feat…
TBoonX Oct 26, 2018
c45ab8a
[SWIK-907_delete_deck_and_transfer_ownership] Add of remove deck acti…
TBoonX Oct 29, 2018
c8a8c19
[SWIK-907_delete_deck_and_transfer_ownership] Did the transfer owners…
TBoonX Oct 29, 2018
0f6ef0a
Add some API calls code for new deck service delete/change owner APIs
kprist Oct 30, 2018
1f41092
[SWIK-907_delete_deck_and_transfer_ownership] First improvements
TBoonX Oct 30, 2018
d6b9e11
Merge branch 'master' of github.com:slidewiki/slidewiki-platform into…
TBoonX Oct 30, 2018
359ea46
[SWIK-907_delete_deck_and_transfer_ownership] SHowing delete buton in…
TBoonX Oct 30, 2018
191ea37
[SWIK-907_delete_deck_and_transfer_ownership] Fixed indentation
TBoonX Oct 30, 2018
a4a8c10
Merge branch 'master' of github.com:slidewiki/slidewiki-platform into…
TBoonX Oct 30, 2018
45e4c90
[SWIK-907_delete_deck_and_transfer_ownership] Removed removeDeck acti…
TBoonX Oct 30, 2018
ffe23a2
Fix some delete subdeck flows and messages
kprist Oct 31, 2018
8373c39
Merge branch 'master' into SWIK-907_delete_deck_and_transfer_ownership
kprist Nov 13, 2018
f10d4a6
Simplify subdeck remove flow: don't provide option to delete
kprist Nov 13, 2018
e6b695d
Move deck delete button to the right; add checks after it's clicked
kprist Nov 13, 2018
2941b4f
Include "Delete" button in Transfer Ownership; close modal on delete
kprist Nov 13, 2018
4710dc6
Merge branch 'master' into SWIK-907_delete_deck_and_transfer_ownership
abijames Nov 22, 2018
41bdb71
[SWIK-907_delete_deck_and_transfer_ownership] Changed texts like Abi …
TBoonX Nov 23, 2018
7782915
Update delete deck buttons; add trash icon to delete, make "OK" green
kprist Nov 29, 2018
9ae3f31
Make indication of user to transfer deck to more visible; use keyboard
kprist Nov 29, 2018
9902fe8
Fix linting errors
kprist Nov 29, 2018
9d059c1
Improve how checking for deck usage before deleting works
kprist Nov 29, 2018
2afa9d5
[SWIK-907_delete_deck_and_transfer_ownership] Tooltip of deck deletio…
TBoonX Nov 30, 2018
bfa4b0c
Fix fork origin info when origin was deleted or its owner has changed
kprist Nov 30, 2018
ef58f77
Merge branch 'master' into SWIK-907_delete_deck_and_transfer_ownership
kprist Feb 26, 2019
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
25 changes: 15 additions & 10 deletions actions/deckedit/deckDeletion.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import log from '../log/clog';

import hideTransferOwnershipModal from './hideTransferOwnershipModal';

import UserProfileStore from '../../stores/UserProfileStore';

export default function deckDeletion(context, payload, done) {
log.info(context);
context.dispatch('START_DELETE_DECK');

payload.jwt = context.getStore(UserProfileStore).jwt;
context.executeAction(hideTransferOwnershipModal, {} , () => {
context.dispatch('START_DELETE_DECK');

payload.jwt = context.getStore(UserProfileStore).jwt;

context.service.delete('deck.delete', payload, { timeout: 20 * 1000 }, (err, res) => {
if (err) {
context.dispatch('DELETE_DECK_ERROR', err);
}
else {
context.dispatch('DELETE_DECK_SUCCESS', res);
}
done();
context.service.delete('deck.delete', payload, { timeout: 20 * 1000 }, (err, res) => {
if (err) {
context.dispatch('DELETE_DECK_ERROR', err);
}
else {
context.dispatch('DELETE_DECK_SUCCESS', res);
}
done();
});
});
}
13 changes: 9 additions & 4 deletions actions/deckedit/loadEditors.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const log = require('../log/clog');
import log from '../log/clog';
import UserProfileStore from '../../stores/UserProfileStore';

export default function loadEditors(context, payload, done) {
log.info(context);
context.dispatch('START_TRANSFER_OWNERSHIP');

let userid = context.getStore(UserProfileStore).userid;
const groupids = payload.groups.map((group) => parseInt(group.id, 10));

if (groupids.length < 1) {
Expand All @@ -20,15 +23,17 @@ export default function loadEditors(context, payload, done) {
ret.push(group.creator);
return ret.concat(group.members);
}, []));
//remove duplicates

// purge duplicates and current user
users = users.reduce((ret, user) => {
let found = ret.find((u) => ((u.id || u.userid) === (user.id || user.userid)));
if (!found) {
if (!found && (user.id || user.userid) !== userid) {
ret.push(user);
}
return ret;
}, []);
console.log('got all editors', users);

// console.log('got all editors', users);
context.dispatch('LOAD_EDITORS_LIST_SUCCESS', users);
}
done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class DeckPropertiesEditor extends React.Component {
})
.then(() => {
this.context.executeAction(navigateAction, {
url: '/'
url: '/user/' + this.context.getUser().username
});
})
.catch(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { FormattedMessage, defineMessages } from 'react-intl';
import UserPicture from '../../../../common/UserPicture';
import hideTransferOwnershipModal from '../../../../../actions/deckedit/hideTransferOwnershipModal';
import transferOwnership from '../../../../../actions/deckedit/transferOwnership';
import deckDeletion from '../../../../../actions/deckedit/deckDeletion';

class TransferOwnership extends React.Component {
constructor(props) {
Expand All @@ -20,8 +21,8 @@ class TransferOwnership extends React.Component {
defaultMessage: 'Transfer Ownership'
},
close: {
id: 'TransferOwnership.close',
defaultMessage: 'Close'
id: 'TransferOwnership.cancel',
defaultMessage: 'Cancel'
},
unknownCountry: {
id: 'TransferOwnership.unknownCountry',
Expand All @@ -38,7 +39,11 @@ class TransferOwnership extends React.Component {
continue: {
id: 'TransferOwnership.continue',
defaultMessage: 'Transfer ownership'
}
},
delete: {
id: 'TransferOwnership.delete',
defaultMessage: 'Delete'
},
});

this.state = {
Expand All @@ -47,19 +52,27 @@ class TransferOwnership extends React.Component {
}

handleClose() {
$('#app').attr('aria-hidden','false');
this.context.executeAction(hideTransferOwnershipModal, {});
$('#app').attr('aria-hidden','false');
this.context.executeAction(hideTransferOwnershipModal, {});
}

unmountTrap() {
this.handleClose();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@TBoonX I'm not sure about this. Could you review this piece of code ?

// TODO commented this out as it appeared to cause trouble with flux and cascading updates,
// and it was impossible to get the transfer success dialog up
// this.handleClose();
$('#app').attr('aria-hidden','false');
}

handleContinue() {
$('#app').attr('aria-hidden','false');
this.context.executeAction(transferOwnership, {deckid: this.props.deckid, userid: this.state.selectedUser});
}

handleDelete() {
$('#app').attr('aria-hidden','false');
this.context.executeAction(deckDeletion, { id: this.props.deckid });
}

render() {
let editors = [];

Expand Down Expand Up @@ -109,22 +122,27 @@ class TransferOwnership extends React.Component {
<Modal.Header as="h1" content={this.context.intl.formatMessage(this.messages.modalHeading)} id='transferownershipmodal_header'/>
<Modal.Content id='transferownershipmodal_content' tabIndex="0">
<Container>
<Segment color="blue" textAlign="center" padded>
<Segment attached="bottom" textAlign="left">
<h3 className="header" ></h3>
<p>There are {this.props.users.length} users which have edit rights to the deck. Select one to transfer the ownership as precondition for deleting the deck.</p>
<Segment color="blue">
<Segment basic>
<p>There are {this.props.users.length} users which have edit rights to this deck. You can make one of them the new deck owner, or delete the deck altogether.
</p>
<Menu size='small' vertical style={{width: '100%'}}>
{editors}
</Menu>
</Segment>
<Modal.Actions>
<Button onClick={ this.handleContinue.bind(this) } role="button" tabIndex="0" aria-label={this.context.intl.formatMessage(this.messages.continue)} disabled={this.state.selectedUser === ''} positive>
{this.context.intl.formatMessage(this.messages.continue)}
</Button>
<Button onClick={ this.handleClose } role="button" tabIndex="0" aria-label={this.context.intl.formatMessage(this.messages.close)}>
{this.context.intl.formatMessage(this.messages.close)}
</Button>
</Modal.Actions>
<Segment basic textAlign="center">
<Modal.Actions>
<Button onClick={ this.handleContinue.bind(this) } role="button" tabIndex="0" aria-label={this.context.intl.formatMessage(this.messages.continue)} disabled={this.state.selectedUser === ''} positive>
{this.context.intl.formatMessage(this.messages.continue)}
</Button>
<Button onClick={ this.handleDelete.bind(this) } role="button" tabIndex="0" aria-label={this.context.intl.formatMessage(this.messages.delete)} negative>
{this.context.intl.formatMessage(this.messages.delete)}
</Button>
<Button onClick={ this.handleClose } role="button" tabIndex="0" aria-label={this.context.intl.formatMessage(this.messages.close)}>
{this.context.intl.formatMessage(this.messages.close)}
</Button>
</Modal.Actions>
</Segment>
</Segment>
</Container>
</Modal.Content>
Expand Down
4 changes: 3 additions & 1 deletion services/deck.js
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,12 @@ export default {
delete: (req, resource, params, config, callback) => {
req.reqId = req.reqId ? req.reqId : -1;
log.info({Id: req.reqId, Service: __filename.split('/').pop(), Resource: resource, Operation: 'delete', Method: req.method});

let deckId = parseInt(params.id);
if (resource === 'deck.delete') {
rp({
method: 'DELETE',
uri: Microservices.deck.uri + '/deck/' + params.id,
uri: Microservices.deck.uri + '/deck/' + deckId,
headers: { '----jwt----': params.jwt },
json: true
})
Expand Down