Search in sources :

Example 31 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.

the class Permission method toDataTransferObject.

@Override
public AccessPermission toDataTransferObject() {
    AccessPermission access = new AccessPermission();
    access.setId(id);
    if (group != null) {
        access.setArticle(AccessPermission.Article.GROUP);
        access.setArticleId(group.getId());
        access.setGroup(group.toDataTransferObject());
        access.setDisplay(group.getLabel());
    } else if (account != null) {
        access.setArticle(AccessPermission.Article.ACCOUNT);
        access.setArticleId(account.getId());
        access.setAccount(account.toDataTransferObject());
        access.setDisplay(getAccount().getFullName());
    }
    AccessPermission.Type type = null;
    long id = 0;
    if (entry != null) {
        type = isCanWrite() ? AccessPermission.Type.WRITE_ENTRY : AccessPermission.Type.READ_ENTRY;
        id = getEntry().getId();
    } else if (getFolder() != null) {
        type = isCanWrite() ? AccessPermission.Type.WRITE_FOLDER : AccessPermission.Type.READ_FOLDER;
        id = getFolder().getId();
    } else if (upload != null) {
        type = isCanWrite() ? AccessPermission.Type.WRITE_UPLOAD : AccessPermission.Type.READ_UPLOAD;
        id = upload.getId();
    }
    access.setType(type);
    access.setTypeId(id);
    return access;
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Example 32 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.

the class BulkUploadControllerTest method testAddPermission.

@Test
public void testAddPermission() throws Exception {
    Account account = AccountCreator.createTestAccount("testAddPermission", 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("testAddPermission2", 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);
    controller.addPermission(account.getEmail(), id, permission);
    List<AccessPermission> permissions = controller.getUploadPermissions(account.getEmail(), id);
    Assert.assertNotNull(permissions);
    Assert.assertTrue(permissions.size() == 1);
    AccessPermission returnedPermission = permissions.get(0);
    Assert.assertEquals(returnedPermission.getArticle(), AccessPermission.Article.ACCOUNT);
    Assert.assertEquals(returnedPermission.getArticleId(), accountFriend.getId());
    Assert.assertEquals(returnedPermission.getType(), AccessPermission.Type.READ_UPLOAD);
    Assert.assertEquals(returnedPermission.getTypeId(), id);
}
Also used : Account(org.jbei.ice.storage.model.Account) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) Test(org.junit.Test)

Example 33 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.

the class EntryController method update.

public void update(String userId, Entry entry) {
    if (entry == null) {
        return;
    }
    authorization.expectWrite(userId, entry);
    entry.setModificationTime(Calendar.getInstance().getTime());
    if (entry.getVisibility() == null)
        entry.setVisibility(Visibility.OK.getValue());
    entry = dao.update(entry);
    // check pi email
    String piEmail = entry.getPrincipalInvestigatorEmail();
    if (StringUtils.isNotEmpty(piEmail)) {
        Account pi = DAOFactory.getAccountDAO().getByEmail(piEmail);
        if (pi != null) {
            // add write permission for the PI (method also checks to see if permission already exists)
            AccessPermission accessPermission = new AccessPermission();
            accessPermission.setArticle(AccessPermission.Article.ACCOUNT);
            accessPermission.setArticleId(pi.getId());
            accessPermission.setType(AccessPermission.Type.WRITE_ENTRY);
            accessPermission.setTypeId(entry.getId());
            permissionsController.addPermission(userId, accessPermission);
        }
    }
}
Also used : AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Example 34 with AccessPermission

use of org.jbei.ice.lib.dto.access.AccessPermission in project ice by JBEI.

the class RemoteAccessTest method testAdd.

@Test
public void testAdd() throws Exception {
    Account account = AccountCreator.createTestAccount("RemoteAccessTest.testAdd", false);
    RemoteAccess remoteAccess = new RemoteAccess();
    RemotePartner partner = new RemotePartner();
    partner.setUrl("registry.jbei.org");
    partner = DAOFactory.getRemotePartnerDAO().create(partner);
    // create permission to share with this user
    AccessPermission permission = new AccessPermission();
    AccountTransfer accountTransfer = new AccountTransfer();
    accountTransfer.setEmail("I wanna share from far away");
    permission.setAccount(accountTransfer);
    permission.setDisplay("Folder Name");
    permission.setUserId(account.getEmail());
    permission.setType(AccessPermission.Type.READ_FOLDER);
    permission.setSecret("supersekrit");
    remoteAccess.add(partner.toDataTransferObject(), permission);
    Collections collections = new Collections(account.getEmail());
    List<FolderDetails> subFolders = collections.getSubFolders(CollectionType.SHARED);
    Assert.assertEquals(1, subFolders.size());
}
Also used : Account(org.jbei.ice.storage.model.Account) RemotePartner(org.jbei.ice.storage.model.RemotePartner) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) Collections(org.jbei.ice.lib.folder.collection.Collections) AccountTransfer(org.jbei.ice.lib.account.AccountTransfer) Test(org.junit.Test)

Aggregations

AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)34 Account (org.jbei.ice.storage.model.Account)8 Test (org.junit.Test)6 PermissionsController (org.jbei.ice.lib.access.PermissionsController)5 AccountTransfer (org.jbei.ice.lib.account.AccountTransfer)5 ArrayList (java.util.ArrayList)4 GroupController (org.jbei.ice.lib.group.GroupController)4 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)3 Group (org.jbei.ice.storage.model.Group)3 Permission (org.jbei.ice.storage.model.Permission)3 Date (java.util.Date)1 PartData (org.jbei.ice.lib.dto.entry.PartData)1 FolderAuthorization (org.jbei.ice.lib.dto.folder.FolderAuthorization)1 RegistryPartner (org.jbei.ice.lib.dto.web.RegistryPartner)1 EntryPermissionTask (org.jbei.ice.lib.entry.EntryPermissionTask)1 Collections (org.jbei.ice.lib.folder.collection.Collections)1 Folder (org.jbei.ice.storage.model.Folder)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