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

Feature: Remove Collaboration #488

Merged
merged 10 commits into from
Aug 28, 2020
33 changes: 25 additions & 8 deletions src/client/components/pages/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
*/

import * as bootstrap from 'react-bootstrap';
import {ENTITY_TYPE_ICONS, genEntityIconHTMLElement} from '../../helpers/entity';
import AddEntityToCollectionModal from './parts/add-entity-to-collection-modal';
import AuthorTable from './entities/author-table';
import DeleteOrRemoveCollaborationModal from './parts/delete-or-remove-collaboration-modal';
Expand Down Expand Up @@ -233,16 +232,23 @@ class CollectionPage extends React.Component {
onToggleRow: this.toggleRow,
selectedEntities: this.state.selectedEntities,
showAdd: false,
showCheckboxes: this.props.isCollaborator || this.props.isOwner
showCheckboxes: this.props.isOwner || this.props.isCollaborator
};
return (
<div>
<DeleteOrRemoveCollaborationModal
collaboratorId={this.props.userId}
collection={this.props.collection}
delete={this.props.isOwner}
MonkeyDo marked this conversation as resolved.
Show resolved Hide resolved
show={this.state.showModal}
onCloseModal={this.handleCloseModal}
show={this.state.showDeleteModal}
onCloseModal={this.handleCloseDeleteModal}
/>
<AddEntityToCollectionModal
closeModalAndShowMessage={this.closeAddEntityModalShowMessageAndRefreshTable}
collectionId={this.props.collection.id}
collectionType={this.props.collection.entityType}
show={this.state.showAddEntityModal}
onCloseModal={this.handleCloseAddEntityModal}
/>
<Row className="entity-display-background">
<Col className="entity-display-image-box text-center" md={2}>
Expand All @@ -259,7 +265,19 @@ class CollectionPage extends React.Component {
{messageComponent}
<div className="margin-top-1 text-left">
{
(this.props.isOwner || this.props.isCollaborator) && this.props.entities.length ?
this.props.isCollaborator || this.props.isOwner ?
<Button
bsSize="small"
bsStyle="success"
title={`Add ${this.props.collection.entityType}`}
onClick={this.handleShowAddEntityModal}
>
<FontAwesomeIcon icon="plus"/>
&nbsp;Add {_.lowerCase(this.props.collection.entityType)}
</Button> : null
}
{
(this.props.isCollaborator || this.props.isOwner) && this.state.entities.length ?
<Button
bsSize="small"
bsStyle="danger"
Expand Down Expand Up @@ -300,9 +318,9 @@ class CollectionPage extends React.Component {
bsSize="small"
bsStyle="warning"
title="Remove yourself as a collaborator"
onClick={this.handleShowModal}
onClick={this.handleShowDeleteModal}
>
<FontAwesomeIcon icon="times-circle"/>&nbsp;Remove collaboration
<FontAwesomeIcon icon="times-circle"/>&nbsp;Stop collaboration
</Button> : null
}
</div>
Expand Down Expand Up @@ -331,7 +349,6 @@ CollectionPage.propTypes = {
isCollaborator: PropTypes.bool,
isOwner: PropTypes.bool,
nextEnabled: PropTypes.bool.isRequired,
showCheckboxes: PropTypes.bool,
size: PropTypes.number,
userId: PropTypes.number.isRequired
MonkeyDo marked this conversation as resolved.
Show resolved Hide resolved
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,21 @@ class DeleteOrRemoveCollaborationModal extends React.Component {
}
else {
this.postUrl = `/collection/${collection.id}/collaborator/remove/${this.props.collaboratorId}`;
modalTitle = 'Remove collaboration';
modalTitle = 'Remove yourself as a collaborator';
modalBody = (
<Alert bsStyle="warning">
<h4>
<FontAwesomeIcon icon="exclamation-triangle"/>&nbsp;
You’re about to remove yourself as a collaborator of Collection: {collection.name}.
</h4>
<p>
Are you sure you want to do this ? You won’t be able to undo this.
Are you sure you want to process ? You won’t be able to undo this.
MonkeyDo marked this conversation as resolved.
Show resolved Hide resolved
</p>
</Alert>
);
submitButton = (
<Button bsStyle="warning" onClick={this.handleSubmit}>
<FontAwesomeIcon icon="times-circle"/> Remove collaboration
<FontAwesomeIcon icon="times-circle"/> Stop collaboration
</Button>
);
}
Expand Down
9 changes: 5 additions & 4 deletions src/server/routes/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import * as auth from '../helpers/auth';
import * as error from '../../common/helpers/error';
import * as handler from '../helpers/handler';
import * as middleware from '../helpers/middleware';
import * as propHelpers from '../../client/helpers/props';
import * as search from '../helpers/search';
Expand Down Expand Up @@ -284,14 +285,14 @@ router.post('/:collectionId/add', auth.isAuthenticated, auth.isCollectionOwnerOr
}
});

router.post('/:collectionId/collaborator/remove/:editorId', auth.isAuthenticated, async (req, res, next) => {
router.post('/:collectionId/collaborator/remove/:collaboratorId', auth.isAuthenticated, async (req, res, next) => {
try {
const {collection} = res.locals;
const collaboratorId = parseInt(req.params.editorId, 10);
const collaboratorId = parseInt(req.params.collaboratorId, 10);
if (parseInt(req.user.id, 10) !== collaboratorId ||
!collection.collaborators.filter(collaborator => collaborator.id === collaboratorId).length) {
!collection.collaborators.find(collaborator => collaborator.id === collaboratorId)) {
throw new error.PermissionDeniedError(
'You do not have permission to edit this collection', req
'You do not have permission to edit this collection’s collaborators', req
);
}
const {UserCollection, UserCollectionCollaborator} = req.app.locals.orm;
Expand Down
5 changes: 0 additions & 5 deletions src/server/routes/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,6 @@ router.get('/reindex', auth.isAuthenticated, (req, res) => {
// TODO: This is hacky, and we should replace it once we switch to SOLR.
const trustedUsers = ['Leftmost Cat', 'LordSputnik', 'Monkey', 'iliekcomputers'];

const NO_MATCH = -1;
if (trustedUsers.indexOf(req.user.name) === NO_MATCH) {
throw new error.PermissionDeniedError(null, req);
}

MonkeyDo marked this conversation as resolved.
Show resolved Hide resolved
resolve();
})
.then(() => search.generateIndex(orm))
Expand Down