Skip to content

Commit

Permalink
Merge branch
Browse files Browse the repository at this point in the history
  • Loading branch information
hplahar committed Sep 15, 2015
2 parents 98e8ab4 + 48be3c8 commit ca3d0a1
Show file tree
Hide file tree
Showing 18 changed files with 190 additions and 142 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<groupId>org.jbei</groupId>
<artifactId>ice</artifactId>
<packaging>war</packaging>
<version>4.4.0</version>
<version>4.4.1</version>
<name>ice</name>
<description>Inventory of Composable Elements (ICE) for Synthetic Biology</description>
<repositories>
Expand Down
23 changes: 13 additions & 10 deletions src/main/java/org/jbei/ice/lib/account/AccountController.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.jbei.ice.lib.account;

import org.apache.commons.lang3.StringUtils;
import org.jbei.ice.lib.access.PermissionException;
import org.jbei.ice.lib.account.authentication.AuthenticationException;
import org.jbei.ice.lib.account.authentication.IAuthentication;
import org.jbei.ice.lib.account.authentication.LocalAuthentication;
Expand Down Expand Up @@ -53,7 +54,8 @@ public AccountController() {
public AccountTransfer updateAccount(final String requester, final long userId,
final AccountTransfer transfer) {
final Account account = dao.get(userId);
if (!account.getEmail().equalsIgnoreCase(requester) && !isAdministrator(requester)) {
boolean requesterIsAdmin = isAdministrator(requester);
if (!account.getEmail().equalsIgnoreCase(requester) && !requesterIsAdmin) {
return null;
}

Expand All @@ -74,7 +76,16 @@ public AccountTransfer updateAccount(final String requester, final long userId,
account.setInstitution(transfer.getInstitution());
}

return dao.update(account).toDataTransferObject();
if (transfer.getAccountType() != null) {
if (transfer.getAccountType() != account.getType() && !requesterIsAdmin)
throw new PermissionException("Only admins can change account type");

account.setType(transfer.getAccountType());
}

AccountTransfer result = dao.update(account).toDataTransferObject();
result.setAdmin(isAdministrator(account.getEmail()));
return result;
}

/**
Expand Down Expand Up @@ -357,14 +368,6 @@ public Account save(final Account account) {
return dao.create(account);
}

/**
* @param account
* @return {@code true} if an administrator account
*/
public boolean isAdministrator(final Account account) {
return isAdministrator(account.getEmail());
}

/**
* Check in the database if an account is a moderator.
*
Expand Down
63 changes: 23 additions & 40 deletions src/main/java/org/jbei/ice/services/rest/SampleResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class SampleResource extends RestResource {
private SampleService sampleService = new SampleService();

/**
* @param token
* @return Response with matching part sample
*/
@GET
Expand All @@ -46,24 +45,20 @@ public Response getSampleByToken(@PathParam("token") String token,
}

/**
* @param offset
* @param limit
* @param sort
* @param asc
* @param filter
* @param status
* @return Response with matching samples
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/requests")
public Response getRequests(@DefaultValue("0") @QueryParam("offset") final int offset,
public Response getRequests(
@HeaderParam(value = "X-ICE-Authentication-SessionId") String userAgentHeader,
@DefaultValue("0") @QueryParam("offset") final int offset,
@DefaultValue("15") @QueryParam("limit") final int limit,
@DefaultValue("requested") @QueryParam("sort") final String sort,
@DefaultValue("false") @QueryParam("asc") final boolean asc,
@QueryParam("filter") final String filter,
@QueryParam("status") final SampleRequestStatus status) {
final String userId = getUserId();
final String userId = getUserId(userAgentHeader);
Logger.info(userId + ": retrieving sample requests");
final UserSamples samples = requestRetriever.getRequests(userId, offset, limit, sort, asc,
status, filter);
Expand All @@ -74,14 +69,12 @@ public Response getRequests(@DefaultValue("0") @QueryParam("offset") final int o
* Sets the status of sample requests. Must have admin privs to set the sample for others This
* is intended for requesting samples
*
* @param status
* @param requestIds
* @return Response success or failure
*/
@PUT
@Path("/requests")
public Response setRequestStatus(@QueryParam("status") final SampleRequestStatus status,
final ArrayList<Long> requestIds) {
final ArrayList<Long> requestIds) {
final String userId = getUserId();
try {
if (requestIds == null || requestIds.isEmpty()) {
Expand All @@ -102,71 +95,61 @@ public Response setRequestStatus(@QueryParam("status") final SampleRequestStatus
}
}

/**
* @param requestId
* @return Response with the removed sample
*/
@DELETE
@Path("/requests/{id}")
public Response deleteSampleRequest(@PathParam("id") final long requestId) {
final String userId = getUserId();
public Response deleteSampleRequest(@HeaderParam(value = "X-ICE-Authentication-SessionId") String sessionId,
@PathParam("id") final long requestId) {
final String userId = getUserId(sessionId);
return respond(Response.Status.OK, requestRetriever.removeSampleFromCart(userId, requestId));
}

/**
* @param requestId
* @param status
* @return Response with the updated sample request
*/
@PUT
@Path("/requests/{id}")
public Response updateSampleRequest(@PathParam("id") final long requestId,
@QueryParam("status") final SampleRequestStatus status) {
final String userId = getUserId();
public Response updateSampleRequest(@HeaderParam(value = "X-ICE-Authentication-SessionId") String sessionId,
@PathParam("id") final long requestId,
@QueryParam("status") final SampleRequestStatus status) {
final String userId = getUserId(sessionId);
final SampleRequest request = requestRetriever.updateStatus(userId, requestId, status);
return respond(Response.Status.OK, request);
}

/**
* @param offset
* @param limit
* @param sort
* @param asc
* @param uid
* @param status
* @return response with the matching sample requests
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/requests/{userId}")
public Response getUserRequests(@DefaultValue("0") @QueryParam("offset") final int offset,
@DefaultValue("15") @QueryParam("limit") final int limit,
@DefaultValue("requested") @QueryParam("sort") final String sort,
@DefaultValue("false") @QueryParam("asc") final boolean asc,
@PathParam("userId") final long uid,
@DefaultValue("IN_CART") @QueryParam("status") final SampleRequestStatus status) {
final String userId = getUserId();
public Response getUserRequests(@HeaderParam(value = "X-ICE-Authentication-SessionId") String sessionId,
@DefaultValue("0") @QueryParam("offset") final int offset,
@DefaultValue("15") @QueryParam("limit") final int limit,
@DefaultValue("requested") @QueryParam("sort") final String sort,
@DefaultValue("false") @QueryParam("asc") final boolean asc,
@PathParam("userId") final long uid,
@DefaultValue("IN_CART") @QueryParam("status") final SampleRequestStatus status) {
final String userId = getUserId(sessionId);
Logger.info(userId + ": retrieving sample requests for user");
final UserSamples userSamples = requestRetriever.getUserSamples(userId, status, offset,
limit, sort, asc);
return super.respond(Response.Status.OK, userSamples);
}

/**
* @param request
* @return Response with the added sample requests
*/
@POST
@Produces(MediaType.APPLICATION_JSON)
@Path("/requests")
public ArrayList<SampleRequest> addRequest(final SampleRequest request) {
final String userId = getUserId();
public ArrayList<SampleRequest> addRequest(@HeaderParam(value = "X-ICE-Authentication-SessionId") String sessionId,
final SampleRequest request) {
final String userId = getUserId(sessionId);
log(userId, "add sample request to cart for " + request.getPartData().getId());
return requestRetriever.placeSampleInCart(userId, request);
}

/**
* @param type
* @return Response with the current sample requests
*/
@GET
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/org/jbei/ice/servlet/FileDownloadServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void getSBOLVisualType(String userId, String entryId, HttpServletRespons
if (uri != null) {
try {
IOUtils.copy(uri.toURL().openStream(),
new FileOutputStream(tmpDir + File.separatorChar + hash + ".png"));
new FileOutputStream(tmpDir + File.separatorChar + hash + ".png"));
fileId = hash + ".png";
} catch (IOException e) {
Logger.error(e);
Expand All @@ -76,6 +76,9 @@ private void getSBOLVisualType(String userId, String entryId, HttpServletRespons
}

response.setContentType("image/png");
if (fileId == null)
return;

File file = Paths.get(tmpDir, fileId).toFile();
if (file.exists() && file.canRead()) {
response.setContentLength((int) file.length());
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
</encoder>
</appender>

<logger name="org.jbei.ice" level="DEBUG"/>
<logger name="org.jbei.auth" level="DEBUG" additivity="false">
<logger name="org.jbei.ice" level="INFO"/>
<logger name="org.jbei.auth" level="INFO" additivity="false">
<appender-ref ref="STDOUT"/>
</logger>

Expand Down
12 changes: 6 additions & 6 deletions src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
<script src="scripts/lib/angular/angular-touch.min.js"></script>

<script src="scripts/lib/angular-ui/angular-ui-router.min-0.2.15.js"></script>
<script src="scripts/lib/angular-ui/ui-bootstrap-tpls-0.13.4.min.js"></script>
<script src="scripts/lib/angular-ui/ui-bootstrap-tpls-0.13.3.min.js"></script>

<script src="scripts/lib/angular-file-upload/angular-file-upload.min.js"></script>

<script src="scripts/lib/handsontable-0.16.1/handsontable.full.min.js"></script>
<script src="scripts/lib/handsontable-0.16.1/pikaday.js"></script>
<link rel="stylesheet" href="scripts/lib/handsontable-0.16.1/pikaday.css">
<link rel="stylesheet" media="screen" href="scripts/lib/handsontable-0.16.1/handsontable.full.min.css">
<script src="scripts/lib/handsontable-0.18.0/handsontable.full.min.js"></script>
<script src="scripts/lib/handsontable-0.18.0/pikaday.js"></script>
<link rel="stylesheet" href="scripts/lib/handsontable-0.18.0/pikaday.css">
<link rel="stylesheet" media="screen" href="scripts/lib/handsontable-0.18.0/handsontable.full.min.css">

<script src="scripts/lib/momentjs/moment.min.js"></script>
<script src="scripts/lib/angular-moment/angular-moment.min.js"></script>
Expand Down Expand Up @@ -90,7 +90,7 @@
</div>
<div class="text-right">
&copy;&nbsp;<a href="https://github.com/JBEI/ice">JBEI ICE Registry</a> <span
class="label label-primary">v4.4.0</span><br>
class="label label-primary">v4.4.1</span><br>
All rights reserved. <br>
<a href="https://github.com/JBEI/ice/issues/new">Submit an Issue</a>&nbsp; <span class="text-muted">|</span> &nbsp;<a
href="http://public-registry.jbei.org/manual">Help</a>
Expand Down
23 changes: 21 additions & 2 deletions src/main/webapp/scripts/admin/adminController.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,15 @@ angular.module('ice.admin.controller', [])

var samples = Samples($cookieStore.get("sessionId"));
$scope.maxSize = 5;
$scope.params = {sort: 'requested', asc: false, currentPage: 1, status: 'ALL'};
$scope.params = {sort: 'requested', asc: false, currentPage: 1, status: undefined};

$scope.requestSamples = function () {
$scope.loadingPage = true;
samples.requests($scope.params, function (result) {
var params = angular.copy($scope.params);
if (params.status == 'ALL')
params.status = undefined;

samples.requests(params, function (result) {
$scope.sampleRequests = result;
$scope.loadingPage = false;
$scope.indexStart = ($scope.currentPage - 1) * 15;
Expand Down Expand Up @@ -340,5 +344,20 @@ angular.module('ice.admin.controller', [])
}, function (error) {

})
};

$scope.setUserAccountType = function (userItem, accountType) {
if (!accountType)
accountType = 'NORMAL';

var userCopy = angular.copy(userItem);
userCopy.accountType = accountType;

user.update({userId: userItem.id}, userCopy, function (result) {
userItem.accountType = result.accountType;
userItem.isAdmin = result.isAdmin;
}, function (error) {
console.log(error);
});
}
});
36 changes: 20 additions & 16 deletions src/main/webapp/scripts/admin/users.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,8 @@
</div>
</form>
</div>

<div class="pad_top">
<table cellspacing="0" class="table table-hover font-95em"
ng-class="{'opacity_4':loadingPage}">
<table cellspacing="0" class="table table-hover font-95em" ng-class="{'opacity_4':loadingPage}">
<thead>
<tr data-ng-show='!userList'>
<td colspan="10">Loading...</td>
Expand All @@ -82,21 +80,27 @@
</tr>
</thead>
<tbody>
<tr data-ng-repeat="user in userList.users">
<td class="no_wrap">{{user.firstName}} {{user.lastName}} (<a ng-href="profile/{{user.id}}">{{user.email}}</a>)
</td>
<td style="width:160px; white-space:nowrap" ng-if="user.isAdmin">
<small class="label label-danger"
style="font-size: 12px; position: relative; top: -4px">{{user.accountType |
capitalize}}
</small>
<tr data-ng-repeat="userItem in userList.users">
<td class="no_wrap">{{userItem.firstName}} {{userItem.lastName}} (<a ng-href="profile/{{userItem.id}}">{{userItem.email}}</a>)
</td>
<td style="width:160px; white-space:nowrap" ng-if="!user.isAdmin">{{user.accountType ||
"Normal" | capitalize}}
<td style="width:160px; white-space:nowrap">
<!-- Single button -->
<div class="btn-group" dropdown>
<button type="button" class="btn btn-xs dropdown-toggle" dropdown-toggle
ng-class="{'btn-warning':userItem.isAdmin, 'btn-default':!userItem.isAdmin}">
{{userItem.accountType |capitalize}} <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li ng-if="userItem.accountType != 'ADMIN'"
ng-click="setUserAccountType(userItem, 'ADMIN')"><a href="#">Admin</a></li>
<li ng-if="userItem.accountType != 'NORMAL'"
ng-click="setUserAccountType(userItem, 'NORMAL')"><a href="#">Regular</a></li>
</ul>
</div>
</td>
<td style="width:90px; white-space:nowrap">{{user.userEntryCount | number}}</td>
<td style="width:160px; white-space:nowrap">{{user.registerDate | date:'MMM d, yyyy'}}</td>
<td style="width:160px; white-space:nowrap"><span ng-show="user.lastLogin">{{user.lastLogin | date:'MMM d, yyyy'}}</span>
<td style="width:90px; white-space:nowrap">{{userItem.userEntryCount | number}}</td>
<td style="width:160px; white-space:nowrap">{{userItem.registerDate | date:'MMM d, yyyy'}}</td>
<td style="width:160px; white-space:nowrap"><span ng-show="userItem.lastLogin">{{userItem.lastLogin | date:'MMM d, yyyy'}}</span>
</td>
</tr>
</tbody>
Expand Down

Large diffs are not rendered by default.

This file was deleted.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main/webapp/scripts/upload/import.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ <h4>
</span>

<span style="font-weight: normal; color: #ccc">&nbsp;|&nbsp;</span>

<div class="dropdown display-inline" dropdown>
<span class="opacity_hover edit_icon font-90em dropdown-toggle" dropdown-toggle>
<i style="font-size: 14px; color: #555" class="fa fa-link"></i> Link To
Expand Down Expand Up @@ -74,6 +73,7 @@ <h4>
<span ng-if="bulkUpload.status=='BULK_EDIT'">Done</span>
</button>
<button ng-if="bulkUpload.status==undefined || bulkUpload.status=='IN_PROGRESS'"
ng-disabled="!bulkUpload||!bulkUpload.entryIdData||!bulkUpload.entryIdData.length"
type="button" class="btn btn-xs btn-default" ng-click="confirmResetFormModal()">
Reset
</button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<div class="modal-footer">
<button class="btn btn-default btn-sm" ng-click="cancel()">Cancel</button>
<button ng-if="!modalClose && !processing" type="button" ng-click="reset()" class="btn btn-sm btn-primary"
ng-disabled="!importUploader.getNotUploadedItems().length">Reset</button>
<button ng-if="!modalClose && !processing" type="button"
ng-click="resetBulkUpload()" class="btn btn-sm btn-primary">Reset
</button>
</div>
Loading

0 comments on commit ca3d0a1

Please sign in to comment.