Search in sources :

Example 41 with DataverseRole

use of edu.harvard.iq.dataverse.authorization.DataverseRole 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 42 with DataverseRole

use of edu.harvard.iq.dataverse.authorization.DataverseRole in project dataverse by IQSS.

the class CreateRoleCommandTest method testGuestUsersCantAddRoles.

@Test(expected = IllegalCommandException.class)
public void testGuestUsersCantAddRoles() throws CommandException {
    DataverseRole dvr = new DataverseRole();
    dvr.setAlias("roleTest");
    dvr.setName("Tester Role");
    dvr.addPermission(Permission.AddDataset);
    Dataverse dv = MocksFactory.makeDataverse();
    dvr.setOwner(dv);
    CreateRoleCommand sut = new CreateRoleCommand(dvr, new DataverseRequest(GuestUser.get(), IpAddress.valueOf("89.17.33.33")), dv);
    engine.submit(sut);
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) Dataverse(edu.harvard.iq.dataverse.Dataverse) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole) Test(org.junit.Test)

Example 43 with DataverseRole

use of edu.harvard.iq.dataverse.authorization.DataverseRole in project dataverse by IQSS.

the class MocksFactory method makeRole.

public static DataverseRole makeRole(String name) {
    DataverseRole dvr = new DataverseRole();
    dvr.setId(nextId());
    dvr.setAlias(name);
    dvr.setName(name);
    dvr.setDescription(name + "  " + name + " " + name);
    dvr.addPermission(Permission.ManageDatasetPermissions);
    dvr.addPermission(Permission.EditDataset);
    dvr.addPermission(Permission.PublishDataset);
    dvr.addPermission(Permission.ViewUnpublishedDataset);
    return dvr;
}
Also used : DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Example 44 with DataverseRole

use of edu.harvard.iq.dataverse.authorization.DataverseRole in project dataverse by IQSS.

the class CreatePrivateUrlCommand method execute.

@Override
public PrivateUrl execute(CommandContext ctxt) throws CommandException {
    logger.fine("Executing CreatePrivateUrlCommand...");
    if (dataset == null) {
        /**
         * @todo Internationalize this.
         */
        String message = "Can't create Private URL. Dataset is null.";
        logger.info(message);
        throw new IllegalCommandException(message, this);
    }
    PrivateUrl existing = ctxt.privateUrl().getPrivateUrlFromDatasetId(dataset.getId());
    if (existing != null) {
        /**
         * @todo Internationalize this.
         */
        String message = "Private URL already exists for dataset id " + dataset.getId() + ".";
        logger.info(message);
        throw new IllegalCommandException(message, this);
    }
    DatasetVersion latestVersion = dataset.getLatestVersion();
    if (!latestVersion.isDraft()) {
        /**
         * @todo Internationalize this.
         */
        String message = "Can't create Private URL because the latest version of dataset id " + dataset.getId() + " is not a draft.";
        logger.info(message);
        throw new IllegalCommandException(message, this);
    }
    PrivateUrlUser privateUrlUser = new PrivateUrlUser(dataset.getId());
    DataverseRole memberRole = ctxt.roles().findBuiltinRoleByAlias(DataverseRole.MEMBER);
    final String privateUrlToken = UUID.randomUUID().toString();
    RoleAssignment roleAssignment = ctxt.engine().submit(new AssignRoleCommand(privateUrlUser, memberRole, dataset, getRequest(), privateUrlToken));
    PrivateUrl privateUrl = new PrivateUrl(roleAssignment, dataset, ctxt.systemConfig().getDataverseSiteUrl());
    return privateUrl;
}
Also used : PrivateUrl(edu.harvard.iq.dataverse.privateurl.PrivateUrl) IllegalCommandException(edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException) PrivateUrlUser(edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser) RoleAssignment(edu.harvard.iq.dataverse.RoleAssignment) DatasetVersion(edu.harvard.iq.dataverse.DatasetVersion) DataverseRole(edu.harvard.iq.dataverse.authorization.DataverseRole)

Aggregations

DataverseRole (edu.harvard.iq.dataverse.authorization.DataverseRole)44 RoleAssignment (edu.harvard.iq.dataverse.RoleAssignment)23 RoleAssignee (edu.harvard.iq.dataverse.authorization.RoleAssignee)19 Test (org.junit.Test)19 PrivateUrlUser (edu.harvard.iq.dataverse.authorization.users.PrivateUrlUser)18 Dataset (edu.harvard.iq.dataverse.Dataset)16 DvObject (edu.harvard.iq.dataverse.DvObject)12 Dataverse (edu.harvard.iq.dataverse.Dataverse)9 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)8 DatasetVersion (edu.harvard.iq.dataverse.DatasetVersion)6 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)6 ArrayList (java.util.ArrayList)5 User (edu.harvard.iq.dataverse.authorization.users.User)4 DataverseRoleServiceBean (edu.harvard.iq.dataverse.DataverseRoleServiceBean)3 Permission (edu.harvard.iq.dataverse.authorization.Permission)3 TestCommandContext (edu.harvard.iq.dataverse.engine.TestCommandContext)3 TestDataverseEngine (edu.harvard.iq.dataverse.engine.TestDataverseEngine)3 IllegalCommandException (edu.harvard.iq.dataverse.engine.command.exception.IllegalCommandException)3 PrivateUrl (edu.harvard.iq.dataverse.privateurl.PrivateUrl)3 Timestamp (java.sql.Timestamp)3