예제 #1
0
        public void AssignSharedSpaceAdminRoleToUserTest()
        {
            //FIND shared space admin role
            LogicalQueryPhrase roleLogicalName = new LogicalQueryPhrase(Role.LOGICAL_NAME_FIELD, "role.shared.space.admin");
            CrossQueryPhrase   byRole          = new CrossQueryPhrase(WorkspaceRole.ROLE_FIELD, roleLogicalName);
            List <QueryPhrase> queries         = new List <QueryPhrase>();

            queries.Add(byRole);
            EntityListResult <WorkspaceRole> roles = entityService.Get <WorkspaceRole>(sharedSpaceContext, queries, null);

            Assert.AreEqual <int>(1, roles.total_count.Value);
            WorkspaceRole sharedSpaceAdminRole = roles.data[0];

            //CREATE USER
            SharedspaceUser createdUser = CreateUser();

            //UPDATE USER by adding shared space admin role
            SharedspaceUser userForUpdate = new SharedspaceUser(createdUser.Id);

            userForUpdate.WorkspaceRoles = createdUser.WorkspaceRoles;
            userForUpdate.WorkspaceRoles.data.Add(sharedSpaceAdminRole);
            entityService.Update(sharedSpaceContext, userForUpdate);

            //READ USER
            List <String> fields = new List <string> {
                SharedspaceUser.NAME_FIELD, SharedspaceUser.WORKSPACE_ROLES_FIELD
            };
            SharedspaceUser updatedUser = entityService.GetById <SharedspaceUser>(sharedSpaceContext, createdUser.Id, fields);

            List <EntityId> assignedWorkspaceRoles = updatedUser.WorkspaceRoles.data.Select(p => p.Id).ToList();

            Assert.IsTrue(assignedWorkspaceRoles.Contains(sharedSpaceAdminRole.Id));
        }
예제 #2
0
        public static WorkspaceRole GetWorkspaceAdminRole()
        {
            if (workspaceAdminRole == null)
            {
                LogicalQueryPhrase logicalNamePhrase = new LogicalQueryPhrase(Role.LOGICAL_NAME_FIELD, WorkspaceRole.WORKSPACE_ADMIN_ROLE_LOGICAL_NAME);
                CrossQueryPhrase   byRole            = new CrossQueryPhrase(WorkspaceRole.ROLE_FIELD, logicalNamePhrase);

                LogicalQueryPhrase workspaceIdPhrase = new LogicalQueryPhrase(Workspace.ID_FIELD, workspaceContext.WorkspaceId);
                CrossQueryPhrase   byWorkpace        = new CrossQueryPhrase(WorkspaceRole.WORKSPACE_FIELD, workspaceIdPhrase);

                List <QueryPhrase> queries = new List <QueryPhrase>();
                queries.Add(byWorkpace);
                queries.Add(byRole);
                EntityListResult <WorkspaceRole> roles = entityService.Get <WorkspaceRole>(sharedSpaceContext, queries, null);
                workspaceAdminRole = roles.data[0];
                Assert.AreEqual(WorkspaceRole.WORKSPACE_ADMIN_ROLE_LOGICAL_NAME, workspaceAdminRole.Role.LogicalName);
                Assert.AreEqual(workspaceContext.WorkspaceId.ToString(), workspaceAdminRole.Workspace.Id.ToString());
            }
            return(workspaceAdminRole);
        }
예제 #3
0
        private static SharedspaceUser CreateUser(WorkspaceRole role = null)
        {
            SharedspaceUser user = new SharedspaceUser();

            user.Name      = "Name" + Guid.NewGuid() + "@hpe.com";
            user.Password  = "******";
            user.LastName  = "Last name";
            user.FirstName = "First name";
            user.Email     = user.Name;
            user.Phone1    = "123-123-123";

            if (role != null)
            {
                user.WorkspaceRoles = EntityList <WorkspaceRole> .Create(role);
            }

            var fields = new string[] { "name", "workspace_roles" };

            SharedspaceUser createdUser = entityService.Create <SharedspaceUser>(sharedSpaceContext, user, fields);

            Assert.AreEqual <string>(user.Name, createdUser.Name);
            return(createdUser);
        }