use of org.jbei.ice.lib.access.PermissionsController 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.access.PermissionsController 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());
}
use of org.jbei.ice.lib.access.PermissionsController in project ice by JBEI.
the class BulkUploadController method approveBulkImport.
public boolean approveBulkImport(String userId, long id) {
// only admins allowed
if (!accountController.isAdministrator(userId)) {
Logger.warn("Only administrators can approve bulk imports");
return false;
}
// retrieve bulk upload in question (at this point it is owned by system)
BulkUpload bulkUpload = dao.get(id);
if (bulkUpload == null) {
Logger.error("Could not retrieve bulk upload with id \"" + id + "\" for approval");
return false;
}
// get permissions for bulk upload and set it to the individual entries
PermissionsController permissionsController = new PermissionsController();
ArrayList<AccessPermission> permissions = new ArrayList<>();
for (Permission permission : bulkUpload.getPermissions()) {
AccessPermission accessPermission = permission.toDataTransferObject();
// read or write access
if (accessPermission.getType() == AccessPermission.Type.READ_UPLOAD)
accessPermission.setType(AccessPermission.Type.READ_ENTRY);
else
accessPermission.setType(AccessPermission.Type.WRITE_ENTRY);
permissions.add(accessPermission);
}
// TODO : this needs to go into a task that auto updates
for (Entry entry : bulkUpload.getContents()) {
entry.setVisibility(Visibility.OK.getValue());
Set<Entry> linked = entry.getLinkedEntries();
Entry plasmid = null;
if (linked != null && !linked.isEmpty()) {
plasmid = (Entry) linked.toArray()[0];
plasmid.setVisibility(Visibility.OK.getValue());
}
// set permissions
for (AccessPermission accessPermission : permissions) {
accessPermission.setTypeId(entry.getId());
permissionsController.addPermission(userId, accessPermission);
if (plasmid != null) {
accessPermission.setTypeId(plasmid.getId());
permissionsController.addPermission(userId, accessPermission);
}
}
entryController.update(userId, entry);
if (plasmid != null)
entryController.update(userId, plasmid);
}
// when done approving, delete the bulk upload record but not the entries associated with it.
bulkUpload.getContents().clear();
dao.delete(bulkUpload);
return true;
}
Aggregations