use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.
the class BulkUploadResource method addPermission.
/**
* Add upload permission
*
* @param id unique identifier for the upload
* @param accessPermission model object for permissions applied to upload
* @return Response with the added permission
*/
@POST
@Path("/{id}/permissions")
public Response addPermission(@PathParam("id") long id, AccessPermission accessPermission) {
String userId = requireUserId();
AccessPermission permission = controller.addPermission(userId, id, accessPermission);
return super.respond(permission);
}
use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.
the class EntryLinksTest method testAddLink.
@Test
public void testAddLink() throws Exception {
Account account = AccountCreator.createTestAccount("testAddLink", false);
String userId = account.getEmail();
Account differentAccount = AccountCreator.createTestAccount("testAddLink2", false);
//create strain and plasmid
Strain strain = TestEntryCreator.createTestStrain(account);
Plasmid plasmid = TestEntryCreator.createTestPlasmid(differentAccount);
// give each account read permissions
AccessPermission accessPermission = new AccessPermission(AccessPermission.Article.ACCOUNT, account.getId(), AccessPermission.Type.READ_ENTRY, plasmid.getId(), "");
PermissionsController permissionsController = new PermissionsController();
Assert.assertNotNull(permissionsController.addPermission(differentAccount.getEmail(), accessPermission));
accessPermission = new AccessPermission(AccessPermission.Article.ACCOUNT, differentAccount.getId(), AccessPermission.Type.READ_ENTRY, strain.getId(), "");
Assert.assertNotNull(permissionsController.addPermission(account.getEmail(), accessPermission));
// add plasmid links to strain
EntryLinks entryLinks = new EntryLinks(userId, Long.toString(strain.getId()));
// attempt to add as a parent (expected to fail)
Assert.assertFalse(entryLinks.addLink(plasmid.toDataTransferObject(), LinkType.PARENT));
// now add as a child
Assert.assertTrue(entryLinks.addLink(plasmid.toDataTransferObject(), LinkType.CHILD));
// add second plasmid
Plasmid plasmid2 = TestEntryCreator.createTestPlasmid(account);
Assert.assertTrue(entryLinks.addLink(plasmid2.toDataTransferObject(), LinkType.CHILD));
}
use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.
the class BulkUploadControllerTest method testDeletePermission.
@Test
public void testDeletePermission() throws Exception {
Account account = AccountCreator.createTestAccount("testDeletePermission", false);
BulkUploadInfo info = new BulkUploadInfo();
info.setAccount(account.toDataTransferObject());
info.setType(EntryType.PART.toString());
BulkUploadInfo uploadInfo = controller.create(account.getEmail(), info);
Assert.assertNotNull(uploadInfo);
Account accountFriend = AccountCreator.createTestAccount("testDeletePermission2", false);
long id = uploadInfo.getId();
AccessPermission permission = new AccessPermission();
permission.setArticle(AccessPermission.Article.ACCOUNT);
permission.setArticleId(accountFriend.getId());
permission.setType(AccessPermission.Type.READ_UPLOAD);
permission.setTypeId(id);
permission = controller.addPermission(account.getEmail(), id, permission);
List<AccessPermission> permissions = controller.getUploadPermissions(account.getEmail(), id);
Assert.assertNotNull(permissions);
Assert.assertTrue(permissions.size() == 1);
//delete
AccessPermission returnedPermission = permissions.get(0);
Assert.assertTrue(controller.deletePermission(account.getEmail(), id, returnedPermission.getId()));
permissions = controller.getUploadPermissions(account.getEmail(), id);
Assert.assertTrue(permissions.isEmpty());
// check that the permission record has been deleted
Assert.assertNull(DAOFactory.getPermissionDAO().get(permission.getId()));
}
use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.
the class RemoteShareModel method toDataTransferObject.
@Override
public AccessPermission toDataTransferObject() {
AccessPermission accessPermission = new AccessPermission();
accessPermission.setArticle(AccessPermission.Article.REMOTE);
// for remote access permissions, the article id is the actual permission
accessPermission.setArticleId(this.permission.getId());
accessPermission.setId(this.id);
accessPermission.setType(this.permission.isCanWrite() ? AccessPermission.Type.WRITE_FOLDER : AccessPermission.Type.READ_FOLDER);
AccountTransfer accountTransfer = new AccountTransfer();
accountTransfer.setEmail(this.client.getEmail());
accessPermission.setPartner(this.client.getRemotePartner().toDataTransferObject());
accessPermission.setDisplay(accountTransfer.getEmail());
return accessPermission;
}
use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.
the class FolderControllerTest method testGetPublicFolders.
@Test
public void testGetPublicFolders() throws Exception {
Account account = AccountCreator.createTestAccount("testGetPublicFolders", false);
Assert.assertNotNull(account);
String userId = account.getEmail();
FolderDetails details = new FolderDetails();
details.setName("test1");
details = controller.createPersonalFolder(userId, details);
Assert.assertNotNull(details);
PermissionsController permissionsController = new PermissionsController();
AccessPermission accessPermission = new AccessPermission();
accessPermission.setArticle(AccessPermission.Article.GROUP);
long publicGroupId = new GroupController().createOrRetrievePublicGroup().getId();
accessPermission.setArticleId(publicGroupId);
accessPermission.setType(AccessPermission.Type.READ_FOLDER);
accessPermission.setTypeId(details.getId());
permissionsController.addPermission(userId, accessPermission);
ArrayList<FolderDetails> results = controller.getPublicFolders();
Assert.assertFalse(results.isEmpty());
Assert.assertEquals(details.getName(), results.get(0).getName());
}
Aggregations