Skip to content

Commit

Permalink
Small enhancements
Browse files Browse the repository at this point in the history
  • Loading branch information
etorres committed Jan 11, 2016
1 parent a0fbcb7 commit 7ae6fa6
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 73 deletions.
6 changes: 6 additions & 0 deletions lvl-project/lvl-bundle/src/main/doc/tools/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

Add curator role to an existing user:

<code>
db.resource_owners.update({ "resourceOwner.user.userid" : "demo2" }, { $addToSet : { "resourceOwner.user.roles" : { $each : [ "curator" ] } } })
</code>
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ define([ 'app', 'tpl!apps/collection/pending/tpls/collection_pending', 'tpl!apps
status = '<i class="fa fa-archive fa-fw"></i> ' + formattedValue;
break;
case 'REOPENED':
status = 'fa-file-zip-o';
status = '<i class="fa fa-file fa-fw"></i> ' + formattedValue;
break;
default:
status = 'Unsubmitted';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ define([ 'app', 'entities/pending_citation', 'apps/curation/submitted_citations/
showSection : function() {
var view = new View.Content({
collection : new PendingCitationModel.PendingCitationPageableCollection({
oauth2_token : Lvl.config.authorizationToken()
oauth2_token : Lvl.config.authorizationToken(),
curator : true
})
});
view.on('pending:resolve:record', function(collectionId, item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ define([ 'app', 'tpl!apps/curation/submitted_citations/tpls/submitted_citations'
status = '<i class="fa fa-archive fa-fw"></i> ' + formattedValue;
break;
case 'REOPENED':
status = 'fa-file-zip-o';
status = '<i class="fa fa-file fa-fw"></i> ' + formattedValue;
break;
default:
status = 'Unsubmitted';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ define([ 'app', 'tpl!apps/curation/submitted_sequences/tpls/submitted_sequences'
status = '<i class="fa fa-archive fa-fw"></i> ' + formattedValue;
break;
case 'REOPENED':
status = 'fa-file-zip-o';
status = '<i class="fa fa-file fa-fw"></i> ' + formattedValue;
break;
default:
status = 'Unsubmitted';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ define([ 'app', 'tpl!apps/e-compendium/pending/tpls/e-compendium_pending', 'tpl!
status = '<i class="fa fa-archive fa-fw"></i> ' + formattedValue;
break;
case 'REOPENED':
status = 'fa-file-zip-o';
status = '<i class="fa fa-file fa-fw"></i> ' + formattedValue;
break;
default:
status = 'Unsubmitted';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ define([ 'app', 'tpl!apps/maps/show/tpls/maps-show', 'backbone.oauth2' ], functi
},
onDestroy : function() {
// unsubscribe from events
$(window).off('resize', this.resize);
$(window).off('resize', this.resize);
Lvl.vent.off('search:form:submitted');
this.stopListening();
$('#opts_map_types_heatmap')[0].removeEventListener();
$('#opts_map_types_vectormap')[0].removeEventListener();
$('#opts_layer_sandfly_seqs')[0].removeEventListener();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ define([ 'app', 'tpl!apps/statistics/sequences/tpls/statistics_sequences' ], fun
reset : true
});
},
onDestroy : function() {
// unsubscribe from events
Lvl.vent.off('search:form:submitted');
this.stopListening();
},
searchUnavailable : function(search) {
require([ 'common/growl' ], function(createGrowl) {
createGrowl('Operation unavailable', 'Search tool is not available in this section.', false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ define([ 'app', 'backbone.picky', 'backbone.paginator' ], function(Lvl) {
return Lvl.config.get('service.url') + '/pending/citations/~';
},
initialize : function(options) {
this.oauth2_token = options.oauth2_token
this.oauth2_token = options.oauth2_token;
this.queryParams.onlySubmitted = (options.curator === true);
},
state : {
pageSize : 100,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ public LeishmaniaPendings getLeishmaniaPendings(final @PathParam("namespace") St
final @QueryParam("onlySubmitted") @DefaultValue("false") boolean onlySubmitted,
final @Context UriInfo uriInfo, final @Context HttpServletRequest request, final @Context HttpHeaders headers) {
final String namespace2 = parseParam(namespace);
final String ownerid = OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
.requiresPermissions("sequences:pending:" + ns2permission(namespace2) + ":*:view")
.getPrincipal();
final OAuth2SecurityManager secMgr = OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
.requiresPermissions("sequences:pending:" + ns2permission(namespace2) + ":*:view");
final LeishmaniaPendings paginable = LeishmaniaPendings.start()
.namespace(namespace2)
.page(page)
Expand All @@ -138,7 +137,7 @@ public LeishmaniaPendings getLeishmaniaPendings(final @PathParam("namespace") St
final ImmutableMap<String, String> filter = parseQuery(q);
final Sorting sorting = parseSorting(sort, order);
final List<LeishmaniaPending> pendingSeqs = LEISHMANIA_PENDING_DAO.list(paginable.getPageFirstEntry(), per_page, filter, sorting,
ImmutableMap.of(DB_PREFIX + "sequence", false), count, ownerid, onlySubmitted);
ImmutableMap.of(DB_PREFIX + "sequence", false), count, onlySubmitted && secMgr.hasRole(DATA_CURATOR_ROLE) ? null : secMgr.getPrincipal(), onlySubmitted);
paginable.setElements(pendingSeqs);
paginable.getExcludedFields().add(DB_PREFIX + "sequence");
// set total count and return to the caller
Expand All @@ -156,11 +155,10 @@ public LeishmaniaPending getPendingSequence(final @PathParam("namespace") String
if (isBlank(id)) {
throw new WebApplicationException("Missing required parameters", Response.Status.BAD_REQUEST);
}
final String ownerid = OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
.requiresPermissions("sequences:pending:" + ns2permission(namespace2) + ":" + id2 + ":view")
.getPrincipal();
final OAuth2SecurityManager secMgr = OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
.requiresPermissions("sequences:pending:" + ns2permission(namespace2) + ":" + id2 + ":view");
// get from database
final LeishmaniaPending pendingSeq = LEISHMANIA_PENDING_DAO.find(id2, ownerid);
final LeishmaniaPending pendingSeq = LEISHMANIA_PENDING_DAO.find(id2, secMgr.hasRole(DATA_CURATOR_ROLE) ? null : secMgr.getPrincipal());
if (pendingSeq == null) {
throw new WebApplicationException("Element not found", Response.Status.NOT_FOUND);
}
Expand Down Expand Up @@ -211,32 +209,35 @@ public void updatePendingSequence(final @PathParam("namespace") String namespace
if (update == null) {
throw new WebApplicationException("Missing required parameters", BAD_REQUEST);
}
final String ownerid = OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
.requiresPermissions("sequences:pending:" + ns2permission(namespace2) + ":" + id2 + ":edit")
.getPrincipal();
final OAuth2SecurityManager secMgr = OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
.requiresPermissions("sequences:pending:" + ns2permission(namespace2) + ":" + id2 + ":edit");
// get from database
final LeishmaniaPending pendingSeq = LEISHMANIA_PENDING_DAO.find(id, ownerid);
final LeishmaniaPending pendingSeq = LEISHMANIA_PENDING_DAO.find(id, secMgr.hasRole(DATA_CURATOR_ROLE) ? null : secMgr.getPrincipal());
if (pendingSeq == null) {
throw new WebApplicationException("Element not found", Response.Status.NOT_FOUND);
}
// update
LEISHMANIA_PENDING_DAO.update(update);
// restore possible excluded fields
if (isBlank(trimToNull(update.getSequence()))) {
update.setSequence(pendingSeq.getSequence());
}
// notify users
if (update.getStatus() != null) {
if (isBlank(update.getAssignedTo())) {
NOTIFICATION_MANAGER.broadcast(Notification.builder()
.newId()
.priority(Priority.NORMAL)
.scope(DATA_CURATOR_ROLE)
.message(String.format("Sequence updated by user %s", ownerid))
.message(String.format("Sequence updated by %s", secMgr.getPrincipal()))
.action(new Action("leishmaniaPending", update.getId()))
.build());
} else {
NOTIFICATION_MANAGER.send(Notification.builder()
.newId()
.priority(Priority.NORMAL)
.addressee(update.getAssignedTo())
.message(String.format("Sequence updated by user %s", ownerid))
.message(String.format("Sequence updated by %s", secMgr.getPrincipal()))
.action(new Action("leishmaniaPending", update.getId()))
.build());
}
Expand All @@ -246,7 +247,7 @@ public void updatePendingSequence(final @PathParam("namespace") String namespace
.newId()
.priority(Priority.NORMAL)
.addressee(update.getNamespace())
.message(String.format("Sequence submission resolved"))
.message(String.format("Sequence submission resolved by %s", secMgr.getPrincipal()))
.action(new Action("leishmaniaPending", update.getId()))
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import static eu.eubrazilcc.lvl.storage.ResourceIdPattern.US_ASCII_PRINTABLE_PATTERN;
import static eu.eubrazilcc.lvl.storage.SampleKey.Builder.IOCL_PATTERN;
import static eu.eubrazilcc.lvl.storage.dao.LeishmaniaSampleDAO.LEISHMANIA_SAMPLE_DAO;
import static eu.eubrazilcc.lvl.storage.dao.LeishmaniaSampleDAO.ORIGINAL_SAMPLE_KEY;
import static java.util.Optional.ofNullable;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.apache.commons.lang3.StringUtils.isBlank;
Expand Down Expand Up @@ -130,9 +129,8 @@ public Samples getSamples(final @QueryParam("page") @DefaultValue("0") int page,
final MutableLong count = new MutableLong(0l);
final ImmutableMap<String, String> filter = parseQuery(q);
final Sorting sorting = parseSorting(sort, order);
final List<LeishmaniaSample> samples = LEISHMANIA_SAMPLE_DAO.list(paginable.getPageFirstEntry(), per_page, filter, sorting,
null, count);
/* ImmutableMap.of(ORIGINAL_SAMPLE_KEY, false), count); */
final List<LeishmaniaSample> samples = LEISHMANIA_SAMPLE_DAO.list(paginable.getPageFirstEntry(), per_page, filter, sorting, null, count);
/* ImmutableMap.of(ORIGINAL_SAMPLE_KEY, false), count); */
paginable.setElements(samples);
/* paginable.getExcludedFields().add(ORIGINAL_SAMPLE_KEY); */
// set additional output and return to the caller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ public PendingReferences getPendingReferences(final @PathParam("namespace") Stri
final @QueryParam("onlySubmitted") @DefaultValue("false") boolean onlySubmitted,
final @Context UriInfo uriInfo, final @Context HttpServletRequest request, final @Context HttpHeaders headers) {
final String namespace2 = parseParam(namespace);
final String ownerid = OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
.requiresPermissions("citations:pending:" + ns2permission(namespace2) + ":*:view")
.getPrincipal();
final OAuth2SecurityManager secMgr = OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
.requiresPermissions("citations:pending:" + ns2permission(namespace2) + ":*:view");
final PendingReferences paginable = PendingReferences.start()
.namespace(namespace2)
.page(page)
Expand All @@ -135,8 +134,8 @@ public PendingReferences getPendingReferences(final @PathParam("namespace") Stri
final MutableLong count = new MutableLong(0l);
final ImmutableMap<String, String> filter = parseQuery(q);
final Sorting sorting = parseSorting(sort, order);
final List<PendingReference> pendingRefs = PENDING_REFERENCE_DAO.list(paginable.getPageFirstEntry(), per_page, filter, sorting,
ImmutableMap.of(DB_PREFIX + "sequence", false), count, ownerid, onlySubmitted);
final List<PendingReference> pendingRefs = PENDING_REFERENCE_DAO.list(paginable.getPageFirstEntry(), per_page, filter, sorting, null, count,
onlySubmitted && secMgr.hasRole(DATA_CURATOR_ROLE) ? null : secMgr.getPrincipal(), onlySubmitted);
paginable.setElements(pendingRefs);
paginable.getExcludedFields().add(DB_PREFIX + "sequence");
// set total count and return to the caller
Expand All @@ -150,12 +149,11 @@ public PendingReferences getPendingReferences(final @PathParam("namespace") Stri
@Produces(APPLICATION_JSON)
public PendingReference getPendingReference(final @PathParam("namespace") String namespace, final @PathParam("id") String id, final @Context UriInfo uriInfo,
final @Context HttpServletRequest request, final @Context HttpHeaders headers) {
final String namespace2 = parseParam(namespace), id2 = parseParam(id);
final String ownerid = OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
.requiresPermissions("citations:pending:" + ns2permission(namespace2) + ":" + id2 + ":view")
.getPrincipal();
final String namespace2 = parseParam(namespace), id2 = parseParam(id);
final OAuth2SecurityManager secMgr = OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
.requiresPermissions("citations:pending:" + ns2permission(namespace2) + ":" + id2 + ":view");
// get from database
final PendingReference pendingRef = PENDING_REFERENCE_DAO.find(id2, ownerid);
final PendingReference pendingRef = PENDING_REFERENCE_DAO.find(id2, secMgr.hasRole(DATA_CURATOR_ROLE) ? null : secMgr.getPrincipal());
if (pendingRef == null) {
throw new WebApplicationException("Element not found", Response.Status.NOT_FOUND);
}
Expand Down Expand Up @@ -206,11 +204,10 @@ public void updatePendingReference(final @PathParam("namespace") String namespac
if (update == null || isBlank(trimToNull(update.getPubmedId()))) {
throw new WebApplicationException("Missing required parameters", BAD_REQUEST);
}
final String ownerid = OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
.requiresPermissions("citations:pending:" + ns2permission(namespace2) + ":" + id2 + ":edit")
.getPrincipal();
final OAuth2SecurityManager secMgr = OAuth2SecurityManager.login(request, null, headers, RESOURCE_NAME)
.requiresPermissions("citations:pending:" + ns2permission(namespace2) + ":" + id2 + ":edit");
// get from database
final PendingReference pendingRef = PENDING_REFERENCE_DAO.find(id2, ownerid);
final PendingReference pendingRef = PENDING_REFERENCE_DAO.find(id2, secMgr.hasRole(DATA_CURATOR_ROLE) ? null : secMgr.getPrincipal());
if (pendingRef == null) {
throw new WebApplicationException("Element not found", Response.Status.NOT_FOUND);
}
Expand All @@ -223,15 +220,15 @@ public void updatePendingReference(final @PathParam("namespace") String namespac
.newId()
.priority(Priority.NORMAL)
.scope(DATA_CURATOR_ROLE)
.message(String.format("Citation updated by user %s", ownerid))
.message(String.format("Citation updated by %s", secMgr.getPrincipal()))
.action(new Action("pendingReference", update.getId()))
.build());
} else {
NOTIFICATION_MANAGER.send(Notification.builder()
.newId()
.priority(Priority.NORMAL)
.addressee(update.getAssignedTo())
.message(String.format("Citation updated by user %s", ownerid))
.message(String.format("Citation updated by %s", secMgr.getPrincipal()))
.action(new Action("pendingReference", update.getId()))
.build());
}
Expand All @@ -241,7 +238,7 @@ public void updatePendingReference(final @PathParam("namespace") String namespac
.newId()
.priority(Priority.NORMAL)
.addressee(update.getNamespace())
.message(String.format("Citation submission resolved"))
.message(String.format("Citation submission resolved by %s", secMgr.getPrincipal()))
.action(new Action("pendingReference", update.getId()))
.build());
}
Expand Down
Loading

0 comments on commit 7ae6fa6

Please sign in to comment.