Search in sources :

Example 6 with GroupController

use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.

the class FolderPermissions method disablePublicReadAccess.

public boolean disablePublicReadAccess() {
    authorization.expectWrite(userId, folder);
    GroupController groupController = new GroupController();
    Group publicGroup = groupController.createOrRetrievePublicGroup();
    permissionDAO.removePermission(null, folder, null, null, publicGroup, true, false);
    if (folder.isPropagatePermissions()) {
        for (Entry folderContent : folder.getContents()) {
            EntryPermissions entryPermissions = new EntryPermissions(Long.toString(folderContent.getId()), userId);
            entryPermissions.disablePublicReadAccess();
        }
    }
    return true;
}
Also used : GroupController(org.jbei.ice.lib.group.GroupController) EntryPermissions(org.jbei.ice.lib.entry.EntryPermissions)

Example 7 with GroupController

use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.

the class FolderPermissions method enablePublicReadAccess.

public boolean enablePublicReadAccess() {
    AccessPermission permission = new AccessPermission();
    permission.setType(AccessPermission.Type.READ_FOLDER);
    permission.setTypeId(folder.getId());
    permission.setArticle(AccessPermission.Article.GROUP);
    GroupController groupController = new GroupController();
    permission.setArticleId(groupController.createOrRetrievePublicGroup().getId());
    return createPermission(permission) != null;
}
Also used : GroupController(org.jbei.ice.lib.group.GroupController) AccessPermission(org.jbei.ice.lib.dto.access.AccessPermission)

Example 8 with GroupController

use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.

the class Folders method getAccountGroups.

private Set<Group> getAccountGroups(Account account) {
    Set<Group> accountGroups = new HashSet<>(account.getGroups());
    GroupController controller = new GroupController();
    Group everybodyGroup = controller.createOrRetrievePublicGroup();
    accountGroups.add(everybodyGroup);
    return accountGroups;
}
Also used : GroupController(org.jbei.ice.lib.group.GroupController)

Example 9 with GroupController

use of org.jbei.ice.lib.group.GroupController in project ice by JBEI.

the class FolderController method getPublicEntries.

/**
 * Retrieves entries that are made available publicly
 *
 * @param sort   order of retrieval for the entries
 * @param offset start of retrieval
 * @param limit  maximum number of entries to retrieve
 * @param asc    whether to retrieve the entries in ascending order
 * @return wrapper around the retrieved entries
 */
public FolderDetails getPublicEntries(ColumnField sort, int offset, int limit, boolean asc, List<String> fields) {
    Group publicGroup = new GroupController().createOrRetrievePublicGroup();
    Set<Group> groups = new HashSet<>();
    groups.add(publicGroup);
    EntryDAO entryDAO = DAOFactory.getEntryDAO();
    List<Long> results = entryDAO.retrieveVisibleEntries(null, groups, sort, asc, offset, limit, null);
    long visibleCount = entryDAO.visibleEntryCount(null, groups, null);
    FolderDetails details = new FolderDetails();
    details.setCount(visibleCount);
    for (Long id : results) {
        try {
            PartData info = ModelToInfoFactory.createTableView(id, fields);
            info.setPublicRead(true);
            details.getEntries().add(info);
        } catch (Exception e) {
            Logger.error(e);
        }
    }
    return details;
}
Also used : Group(org.jbei.ice.storage.model.Group) GroupController(org.jbei.ice.lib.group.GroupController) PartData(org.jbei.ice.lib.dto.entry.PartData) FolderDetails(org.jbei.ice.lib.dto.folder.FolderDetails) PermissionException(org.jbei.ice.lib.access.PermissionException) EntryDAO(org.jbei.ice.storage.hibernate.dao.EntryDAO)

Example 10 with GroupController

use of org.jbei.ice.lib.group.GroupController 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)

Aggregations

GroupController (org.jbei.ice.lib.group.GroupController)25 Group (org.jbei.ice.storage.model.Group)12 AccessPermission (org.jbei.ice.lib.dto.access.AccessPermission)8 PartData (org.jbei.ice.lib.dto.entry.PartData)8 HashSet (java.util.HashSet)6 Entry (org.jbei.ice.storage.model.Entry)6 ArrayList (java.util.ArrayList)5 FolderDetails (org.jbei.ice.lib.dto.folder.FolderDetails)4 Account (org.jbei.ice.storage.model.Account)4 CSVWriter (com.opencsv.CSVWriter)3 Path (java.nio.file.Path)3 AccountController (org.jbei.ice.lib.account.AccountController)3 EntryDAO (org.jbei.ice.storage.hibernate.dao.EntryDAO)3 ZipEntry (java.util.zip.ZipEntry)2 PermissionException (org.jbei.ice.lib.access.PermissionException)2 EntryFieldLabel (org.jbei.ice.lib.dto.entry.EntryFieldLabel)2 RebuildBlastIndexTask (org.jbei.ice.lib.search.blast.RebuildBlastIndexTask)2 ZipOutputStream (java.util.zip.ZipOutputStream)1 PermissionsController (org.jbei.ice.lib.access.PermissionsController)1 ConfigurationSettings (org.jbei.ice.lib.config.ConfigurationSettings)1