Search in sources :

Example 6 with PermissionsController

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));
}
Also used : Plasmid(org.jbei.ice.storage.model.Plasmid) Account(org.jbei.ice.storage.model.Account) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) Strain(org.jbei.ice.storage.model.Strain) PermissionsController(org.jbei.ice.lib.access.PermissionsController) Test(org.junit.Test)

Example 7 with PermissionsController

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());
}
Also used : Account(org.jbei.ice.storage.model.Account) GroupController(org.jbei.ice.lib.group.GroupController) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) PermissionsController(org.jbei.ice.lib.access.PermissionsController) Test(org.junit.Test)

Example 8 with PermissionsController

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;
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) PermissionsController(org.jbei.ice.lib.access.PermissionsController)

Aggregations

PermissionsController (org.jbei.ice.lib.access.PermissionsController)8 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)5 Account (org.jbei.ice.storage.model.Account)3 Test (org.junit.Test)2 Date (java.util.Date)1 PartData (org.jbei.ice.lib.dto.entry.PartData)1 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)1 WebEntries (org.jbei.ice.lib.dto.web.WebEntries)1 HasEntry (org.jbei.ice.lib.entry.HasEntry)1 GroupController (org.jbei.ice.lib.group.GroupController)1 Entry (org.jbei.ice.storage.model.Entry)1 Folder (org.jbei.ice.storage.model.Folder)1 Group (org.jbei.ice.storage.model.Group)1 Plasmid (org.jbei.ice.storage.model.Plasmid)1 RemotePartner (org.jbei.ice.storage.model.RemotePartner)1 Strain (org.jbei.ice.storage.model.Strain)1