Search in sources :

Example 31 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetDatasetFromRoleAssignmentSuccess.

@Test
public void testGetDatasetFromRoleAssignmentSuccess() {
    DataverseRole aRole = null;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(42);
    RoleAssignee anAssignee = privateUrlUser;
    DvObject dataset = new Dataset();
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    assertNotNull(PrivateUrlUtil.getDatasetFromRoleAssignment(ra));
    assertEquals("#42", ra.getAssigneeIdentifier());
}
Also used : DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 32 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class PrivateUrlUtilTest method testGetPrivateUrlRedirectDataSuccess.

@Test
public void testGetPrivateUrlRedirectDataSuccess() {
    DataverseRole aRole = null;
    long datasetId = 42;
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(datasetId);
    RoleAssignee anAssignee = privateUrlUser;
    Dataset dataset = new Dataset();
    dataset.setProtocol("doi");
    dataset.setAuthority("10.5072/FK2");
    dataset.setIdentifier("3L33T");
    dataset.setId(datasetId);
    String privateUrlToken = null;
    RoleAssignment ra = new RoleAssignment(aRole, anAssignee, dataset, privateUrlToken);
    PrivateUrlRedirectData privateUrlRedirectData = PrivateUrlUtil.getPrivateUrlRedirectData(ra);
    assertNotNull(privateUrlRedirectData);
    assertEquals("/dataset.xhtml?persistentId=doi:10.5072/FK2/3L33T&version=DRAFT", privateUrlRedirectData.getDraftDatasetPageToBeRedirectedTo());
    assertEquals(privateUrlUser.getIdentifier(), privateUrlRedirectData.getPrivateUrlUser().getIdentifier());
}
Also used : Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Test(org.junit.Test)

Example 33 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class DeletePrivateUrlCommandTest method setUp.

@Before
public void setUp() {
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public PrivateUrlServiceBean privateUrl() {
            return new PrivateUrlServiceBean() {

                @Override
                public PrivateUrl getPrivateUrlFromDatasetId(long datasetId) {
                    if (datasetId == noPrivateUrlToDelete) {
                        return null;
                    } else if (datasetId == hasPrivateUrlToDelete) {
                        Dataset dataset = new Dataset();
                        dataset.setId(hasPrivateUrlToDelete);
                        String token = null;
                        PrivateUrlUser privateUrlUser = new PrivateUrlUser(datasetId);
                        RoleAssignment roleAssignment = new RoleAssignment(null, privateUrlUser, dataset, token);
                        return new PrivateUrl(roleAssignment, dataset, "FIXME");
                    } else {
                        return null;
                    }
                }
            };
        }

        @Override
        public DataverseRoleServiceBean roles() {
            return new DataverseRoleServiceBean() {

                @Override
                public List<RoleAssignment> directRoleAssignments(RoleAssignee roas, DvObject dvo) {
                    RoleAssignment roleAssignment = new RoleAssignment();
                    List<RoleAssignment> list = new ArrayList<>();
                    list.add(roleAssignment);
                    return list;
                }

                @Override
                public void revoke(RoleAssignment ra) {
                // no-op
                }
            };
        }
    });
}
Also used : DataverseRoleServiceBean(edu.harvard.iq.dataverse.DataverseRoleServiceBean) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) ArrayList(java.util.ArrayList) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) PrivateUrlServiceBean(edu.harvard.iq.dataverse.privateurl.PrivateUrlServiceBean) RoleAssignee(edu.harvard.iq.dataverse.authorization.RoleAssignee) Before(org.junit.Before)

Example 34 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class SubmitDatasetForReviewCommandTest method setUp.

@Before
public void setUp() {
    dataset = new Dataset();
    HttpServletRequest aHttpServletRequest = null;
    dataverseRequest = new DataverseRequest(MocksFactory.makeAuthenticatedUser("First", "Last"), aHttpServletRequest);
    testEngine = new TestDataverseEngine(new TestCommandContext() {

        @Override
        public AuthenticationServiceBean authentication() {
            return new AuthenticationServiceBean() {

                @Override
                public AuthenticatedUser getAuthenticatedUser(String id) {
                    return MocksFactory.makeAuthenticatedUser("First", "Last");
                }
            };
        }

        @Override
        public IndexServiceBean index() {
            return new IndexServiceBean() {

                @Override
                public Future<String> indexDataset(Dataset dataset, boolean doNormalSolrDocCleanUp) {
                    return null;
                }
            };
        }

        @Override
        public EntityManager em() {
            return new TestEntityManager() {

                @Override
                public <T> T merge(T entity) {
                    return entity;
                }

                @Override
                public void flush() {
                // nothing to do here
                }
            };
        }

        @Override
        public DatasetServiceBean datasets() {
            return new DatasetServiceBean() {

                {
                    em = new NoOpTestEntityManager();
                }

                @Override
                public DatasetVersionUser getDatasetVersionUser(DatasetVersion version, User user) {
                    return null;
                }

                @Override
                public DatasetLock addDatasetLock(Long datasetId, DatasetLock.Reason reason, Long userId, String info) {
                    return null;
                }
            };
        }

        @Override
        public DataverseRoleServiceBean roles() {
            return new DataverseRoleServiceBean() {

                @Override
                public DataverseRole findBuiltinRoleByAlias(String alias) {
                    return new DataverseRole();
                }

                @Override
                public RoleAssignment save(RoleAssignment assignment) {
                    // no-op
                    return assignment;
                }
            };
        }

        @Override
        public PermissionServiceBean permissions() {
            return new PermissionServiceBean() {

                @Override
                public List<AuthenticatedUser> getUsersWithPermissionOn(Permission permission, DvObject dvo) {
                    // We only need permissions for notifications, which we are testing in InReviewWorkflowIT.
                    return Collections.emptyList();
                }
            };
        }
    });
}
Also used : DataverseRoleServiceBean(edu.harvard.iq.dataverse.DataverseRoleServiceBean) TestCommandContext(edu.harvard.iq.dataverse.engine.TestCommandContext) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) User(edu.harvard.iq.dataverse.authorization.users.User) DatasetVersionUser(edu.harvard.iq.dataverse.DatasetVersionUser) PermissionServiceBean(edu.harvard.iq.dataverse.PermissionServiceBean) DvObject(edu.harvard.iq.dataverse.DvObject) Dataset(edu.harvard.iq.dataverse.Dataset) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) TestEntityManager(edu.harvard.iq.dataverse.engine.TestEntityManager) NoOpTestEntityManager(edu.harvard.iq.dataverse.engine.NoOpTestEntityManager) NoOpTestEntityManager(edu.harvard.iq.dataverse.engine.NoOpTestEntityManager) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) AuthenticationServiceBean(edu.harvard.iq.dataverse.authorization.AuthenticationServiceBean) TestDataverseEngine(edu.harvard.iq.dataverse.engine.TestDataverseEngine) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) HttpServletRequest(javax.servlet.http.HttpServletRequest) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) DatasetServiceBean(edu.harvard.iq.dataverse.DatasetServiceBean) Permission(edu.harvard.iq.dataverse.authorization.Permission) IndexServiceBean(edu.harvard.iq.dataverse.search.IndexServiceBean) Before(org.junit.Before)

Example 35 with RoleAssignment

use of edu.harvard.iq.dataverse.RoleAssignment in project dataverse by IQSS.

the class CreateDataverseCommandTest method testCustomOptions.

@Test
public void testCustomOptions() throws CommandException {
    Dataverse dv = makeDataverse();
    Timestamp creation = timestamp(1990, 12, 12);
    AuthenticatedUser creator = makeAuthenticatedUser("Joe", "Walsh");
    dv.setCreateDate(creation);
    dv.setId(null);
    dv.setCreator(creator);
    dv.setDefaultContributorRole(null);
    dv.setOwner(makeDataverse());
    dv.setDataverseType(Dataverse.DataverseType.JOURNALS);
    dv.setDefaultContributorRole(roles.findBuiltinRoleByAlias(DataverseRole.MANAGER));
    final DataverseRequest request = makeRequest();
    List<DatasetFieldType> expectedFacets = Arrays.asList(makeDatasetFieldType(), makeDatasetFieldType(), makeDatasetFieldType());
    List<DataverseFieldTypeInputLevel> dftils = Arrays.asList(makeDataverseFieldTypeInputLevel(makeDatasetFieldType()), makeDataverseFieldTypeInputLevel(makeDatasetFieldType()), makeDataverseFieldTypeInputLevel(makeDatasetFieldType()));
    CreateDataverseCommand sut = new CreateDataverseCommand(dv, request, new LinkedList(expectedFacets), new LinkedList(dftils));
    Dataverse result = engine.submit(sut);
    assertEquals(creation, result.getCreateDate());
    assertNotNull(result.getId());
    assertEquals(creator, result.getCreator());
    assertEquals(Dataverse.DataverseType.JOURNALS, result.getDataverseType());
    assertEquals(roles.findBuiltinRoleByAlias(DataverseRole.MANAGER), result.getDefaultContributorRole());
    // Assert that the creator is admin.
    final RoleAssignment roleAssignment = roles.directRoleAssignments(dv).get(0);
    assertEquals(roles.findBuiltinRoleByAlias(DataverseRole.ADMIN), roleAssignment.getRole());
    assertEquals(dv, roleAssignment.getDefinitionPoint());
    assertEquals(roleAssignment.getAssigneeIdentifier(), request.getUser().getIdentifier());
    assertTrue(result.isPermissionRoot());
    assertTrue(result.isThemeRoot());
    assertTrue(indexCalled);
    assertTrue(facetsDeleted);
    int i = 0;
    for (DataverseFacet df : createdFacets) {
        assertEquals(i, df.getDisplayOrder());
        assertEquals(result, df.getDataverse());
        assertEquals(expectedFacets.get(i), df.getDatasetFieldType());
        i++;
    }
    assertTrue(dftilsDeleted);
    for (DataverseFieldTypeInputLevel dftil : createdDftils) {
        assertEquals(result, dftil.getDataverse());
    }
}
Also used : RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DataverseFieldTypeInputLevel(edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel) Dataverse(edu.harvard.iq.dataverse.Dataverse) Timestamp(java.sql.Timestamp) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser) DatasetFieldType(edu.harvard.iq.dataverse.DatasetFieldType) LinkedList(java.util.LinkedList) DataverseFacet(edu.harvard.iq.dataverse.DataverseFacet) DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) Test(org.junit.Test)

Aggregations

RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)38 DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)23 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)22 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)19 Test (org.junit.Test)19 Dataset (edu.harvard.iq.dataverse.Dataset)16 DvObject (edu.harvard.iq.dataverse.DvObject)14 Dataverse (edu.harvard.iq.dataverse.Dataverse)8 ArrayList (java.util.ArrayList)8 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)7 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)7 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)6 PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)5 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)4 User (edu.harvard.iq.dataverse.authorization.users.User)4 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)4 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)4 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)4 Before (org.junit.Before)4 DataverseFieldTypeInputLevel (edu.harvard.iq.dataverse.DataverseFieldTypeInputLevel)3