/// <summary>
        /// Deletes a user by artifact ID.
        /// </summary>
        /// <param name="artifactId"></param>
        /// <returns></returns>
        public bool Delete(int artifactId)
        {
            var userToDelete = new DTOs.User(artifactId);
            WriteResultSet <DTOs.User> resultSet;

            try
            {
                using (var client = _helper.GetServicesManager().CreateProxy <IRSAPIClient>(API.ExecutionIdentity.System))
                {
                    client.APIOptions.WorkspaceID = -1;
                    resultSet = client.Repositories.User.Delete(userToDelete);
                }
                if (!resultSet.Success || resultSet.Results.Count == 0)
                {
                    throw new Exception("User was not found");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("An error occurred deleting for the user: {0}", ex.Message);
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Creates/Gets OAuth credentials
        /// </summary>
        /// <returns></returns>
        private async Task <OAuth2Client> CreateAdminUserOAuthCredentials()
        {
            using (IOAuth2ClientManager oAuth2ClientManager = GetServiceFactory().CreateProxy <IOAuth2ClientManager>())
            {
                DTOs.User user = GetUser(_userName);

                List <OAuth2Client> oAuths = await oAuth2ClientManager.ReadAllAsync();

                if (oAuths.Exists(x => x.Name.Equals(_oAuth2Name)))
                {
                    if (oAuths.Exists(x => x.Name.Equals(_oAuth2Name) && x.ContextUser == user.ArtifactID))
                    {
                        Console.WriteLine($"User ({user.EmailAddress}) already has OAuth2 Credentials within ({_oAuth2Name})");
                        return(oAuths.Find(x => x.Name.Equals(_oAuth2Name) && x.ContextUser == user.ArtifactID));
                    }

                    throw new Exception($"A different user was has OAuth2 Credentials within ({_oAuth2Name})");
                }

                OAuth2Client oAuthResult = await oAuth2ClientManager.CreateAsync(_oAuth2Name, OAuth2Flow.ClientCredentials, new List <Uri>(), user.ArtifactID);

                if (oAuthResult != null)
                {
                    Console.WriteLine($"Created OAuth2 Client Credentials for ({user.EmailAddress}) within ({oAuthResult.Name})");
                    return(oAuthResult);
                }
                else
                {
                    throw new Exception($"Failed to create OAuth2 Client Credentials for ({user.EmailAddress}) within ({_oAuth2Name})");
                }
            }
        }
        /// <summary>
        /// Adds the user to the DynamicAPI Group for permissions
        /// </summary>
        /// <param name="groupId"></param>
        private void AddAdminUserToGroup(int groupId)
        {
            using (IRSAPIClient rsapiClient = GetServiceFactory().CreateProxy <IRSAPIClient>())
            {
                DTOs.User user = GetUser(_userName);
                user.Groups.Add(new Group(groupId));
                WriteResultSet <DTOs.User> userUpdateResults = null;

                try
                {
                    userUpdateResults = rsapiClient.Repositories.User.Update(user);

                    if (userUpdateResults.Success)
                    {
                        Console.WriteLine($"Added user to DynamicAPI Group");
                    }
                    else
                    {
                        Console.WriteLine($"Unable to add user to DynamicAPI Group: {userUpdateResults.Message}");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"An error occurred updating the user: {ex.Message}");
                }
            }
        }
Пример #4
0
        private kCura.Relativity.Client.DTOs.User RetrieveSampleUserArtifact(String firstName, String lastName, String emailAddress)
        {
            kCura.Relativity.Client.DTOs.User userArtifact = new kCura.Relativity.Client.DTOs.User
            {
                ArtifactTypeName = ArtifactTypeNames.User,
                TextIdentifier   = $"{firstName} {lastName}",
                FirstName        = firstName,
                LastName         = lastName,
                EmailAddress     = emailAddress,
                Groups           = new FieldValueList <Group>()
                {
                    new Group(123), new Group(456)
                },
                Type = new kCura.Relativity.Client.DTOs.Choice {
                    Name = "Type"
                },
                Client = new Client {
                    Name = "Client"
                },
                RelativityAccess = true,
                DocumentSkip     = new kCura.Relativity.Client.DTOs.Choice {
                    Name = "DocumentSkip"
                },
                BetaUser                = true,
                ChangeSettings          = true,
                KeyboardShortcuts       = true,
                ItemListPageLength      = 12345,
                DefaultSelectedFileType = new kCura.Relativity.Client.DTOs.Choice {
                    Name = "DefaultSelectedFileType"
                },
                SkipDefaultPreference = new kCura.Relativity.Client.DTOs.Choice {
                    Name = "SkipDefaultPreference"
                },
                EnforceViewerCompatibility    = true,
                AdvancedSearchPublicByDefault = true,
                NativeViewerCacheAhead        = true,
                CanChangeDocumentViewer       = true,
                ShowFilters    = true,
                DocumentViewer = new kCura.Relativity.Client.DTOs.Choice {
                    Name = "DocumentViewer"
                }
            };

            return(userArtifact);
        }
Пример #5
0
        /// <summary>
        /// Update single user's client
        /// </summary>
        /// <param name="proxy"></param>
        /// <param name="userId"></param>
        /// <param name="clientId"></param>
        /// <returns></returns>
        public static bool UpdateClientForUser(IRSAPIClient proxy, int userId, int clientId)
        {
            proxy.APIOptions.WorkspaceID = -1;

            var userToUpdate = new kCura.Relativity.Client.DTOs.User(userId)
            {
                Client = new Client(clientId)
            };

            try
            {
                proxy.Repositories.User.UpdateSingle(userToUpdate);
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Пример #6
0
        private void MockUserRepository_ReadSingle_ReturnsUser(Int32 groupCount)
        {
            User userDto = new User
            {
                FirstName    = "FirstName",
                LastName     = "LastName",
                EmailAddress = "*****@*****.**",
                Groups       = new FieldValueList <Group>()
            };

            for (Int32 i = 1; i <= groupCount; i++)
            {
                Group group = new Group
                {
                    Name = $"Group{i}"
                };
                userDto.Groups.Add(group);
            }

            MockUserRepository
            .Setup(x => x.ReadSingle(It.IsAny <Int32>()))
            .Returns(userDto);
        }
Пример #7
0
        public static bool Delete_User(IRSAPIClient client, int artifactId)
        {
            client.APIOptions.WorkspaceID = -1;
            User userToDelete = new User(artifactId);
            WriteResultSet <kCura.Relativity.Client.DTOs.User> resultSet = new WriteResultSet <User>();

            try
            {
                resultSet = client.Repositories.User.Delete(userToDelete);

                if (!resultSet.Success || resultSet.Results.Count == 0)
                {
                    throw new Exception("User was not found");
                }
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("An error occurred deleting for the user: {0}", ex.Message);
                return(false);
            }

            return(true);
        }
        /// <summary>
        /// Creates a temporary, enabled user with a default generated password.
        /// </summary>
        /// <returns></returns>
        public int Create()
        {
            const string errorContext   = "An error occured when creating a new Relativity User.";
            var          userArtifactId = 0;
            var          firstName      = "Temp User";
            var          randomGuid     = Convert.ToString(Guid.NewGuid());
            var          lastName       = randomGuid;
            var          emailAddress   = "tempuser." + randomGuid + "@test.com";

            //Code Types
            const int defaultSelectedFileType = 1;
            const int userType              = 3;
            const int documentSkip          = 1000003;
            const int skipDefaultPreference = 1000004;
            const int password              = 1000005;
            const int sendNewPasswordTo     = 1000006;

            //Get the ArtifactIDs for the required Choice, Group, and Client objects.
            var returnPasswordCodeId         = FindChoiceArtifactId(sendNewPasswordTo, "Return");
            var passwordCodeId               = FindChoiceArtifactId(password, "Auto-generate password");
            var documentSkipCodeId           = FindChoiceArtifactId(documentSkip, "Enabled");
            var documentSkipPreferenceCodeId = FindChoiceArtifactId(skipDefaultPreference, "Normal");
            var defaultFileTypeCodeId        = FindChoiceArtifactId(defaultSelectedFileType, "Native");
            var userTypeCodeId               = FindChoiceArtifactId(userType, "Internal");
            var everyoneGroupArtifactId      = FindGroupArtifactId("Everyone");
            var clientArtifactId             = FindClientArtifactId("Relativity Template");

            var userDto = new DTOs.User
            {
                AdvancedSearchPublicByDefault = true,
                AuthenticationData            = "",
                BetaUser                = false,
                ChangePassword          = true,
                ChangePasswordNextLogin = false,
                ChangeSettings          = true,
                Client    = new DTOs.Client(clientArtifactId),
                DataFocus = 1,
                DefaultSelectedFileType    = new DTOs.Choice(defaultFileTypeCodeId),
                DocumentSkip               = new DTOs.Choice(documentSkipCodeId),
                EmailAddress               = emailAddress,
                EnforceViewerCompatibility = true,
                FirstName = firstName,
                Groups    = new List <DTOs.Group> {
                    new kCura.Relativity.Client.DTOs.Group(everyoneGroupArtifactId)
                },
                ItemListPageLength     = 25,
                KeyboardShortcuts      = true,
                LastName               = lastName,
                MaximumPasswordAge     = 0,
                NativeViewerCacheAhead = true,
                PasswordAction         = new DTOs.Choice(passwordCodeId),
                RelativityAccess       = true,
                SendPasswordTo         = new DTOs.Choice(returnPasswordCodeId),
                SkipDefaultPreference  = new DTOs.Choice(documentSkipPreferenceCodeId),
                TrustedIPs             = "",
                Type = new DTOs.Choice(userTypeCodeId)
            };

            WriteResultSet <DTOs.User> createResults;

            try
            {
                using (var client = _helper.GetServicesManager().CreateProxy <IRSAPIClient>(API.ExecutionIdentity.System))
                {
                    client.APIOptions.WorkspaceID = -1;
                    createResults = client.Repositories.User.Create(userDto);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(errorContext, ex);
            }

            // Check for success.
            if (createResults.Success)
            {
                userArtifactId = createResults.Results[0].Artifact.ArtifactID;
            }

            return(userArtifactId);
        }
        /// <summary>
        /// Creates a user with a supplied identity.
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="emailAddress"></param>
        /// <param name="password"></param>
        /// <param name="groupArtifactIds"></param>
        /// <param name="relativityAccess"></param>
        /// <param name="userType"></param>
        /// <param name="clientName"></param>
        /// <returns></returns>
        public int Create(String firstName, String lastName, String emailAddress, String password, List <int> groupArtifactIds, Boolean relativityAccess, String userType, String clientName)
        {
            int defaultSelectedFileType = 1;
            int userTypeCodeTypeId      = 3;
            int documentSkip            = 1000003;
            int skipDefaultPreference   = 1000004;
            int passwordCodeTypeId      = 1000005;
            int sendNewPasswordTo       = 1000006;

            int returnPasswordCodeId         = FindChoiceArtifactId(sendNewPasswordTo, "Return");
            int passwordCodeId               = FindChoiceArtifactId(passwordCodeTypeId, "Manually set password");
            int documentSkipCodeId           = FindChoiceArtifactId(documentSkip, "Enabled");
            int documentSkipPreferenceCodeId = FindChoiceArtifactId(skipDefaultPreference, "Normal");
            int defaultFileTypeCodeId        = FindChoiceArtifactId(defaultSelectedFileType, "Native");
            int userTypeCodeId               = FindChoiceArtifactId(userTypeCodeTypeId, userType);
            int everyoneGroupArtifactId      = FindGroupArtifactId("Everyone");
            int clientArtifactId             = FindClientArtifactId(clientName);

            DTOs.User userDto = new DTOs.User
            {
                FirstName    = firstName,
                LastName     = lastName,
                EmailAddress = emailAddress,
                AdvancedSearchPublicByDefault = true,
                AuthenticationData            = "",
                BetaUser                = false,
                ChangePassword          = true,
                ChangePasswordNextLogin = false,
                ChangeSettings          = true,
                Client    = new DTOs.Client(clientArtifactId),
                DataFocus = 1,
                DefaultSelectedFileType    = new DTOs.Choice(defaultFileTypeCodeId),
                DocumentSkip               = new DTOs.Choice(documentSkipCodeId),
                EnforceViewerCompatibility = true,
                Groups = new List <DTOs.Group> {
                    new kCura.Relativity.Client.DTOs.Group(everyoneGroupArtifactId)
                },
                ItemListPageLength     = 25,
                KeyboardShortcuts      = true,
                MaximumPasswordAge     = 0,
                NativeViewerCacheAhead = true,
                PasswordAction         = new DTOs.Choice(passwordCodeId),
                RelativityAccess       = relativityAccess,
                SendPasswordTo         = new DTOs.Choice(returnPasswordCodeId),
                SkipDefaultPreference  = new DTOs.Choice(documentSkipPreferenceCodeId),
                TrustedIPs             = "",
                Type     = new DTOs.Choice(userTypeCodeId),
                Password = password
            };

            foreach (Int32 groupArtifactId in groupArtifactIds)
            {
                userDto.Groups.Add(new kCura.Relativity.Client.DTOs.Group(groupArtifactId));
            }
            WriteResultSet <DTOs.User> results;

            using (var client = _helper.GetServicesManager().CreateProxy <IRSAPIClient>(API.ExecutionIdentity.System))
            {
                client.APIOptions.WorkspaceID = -1;
                results = client.Repositories.User.Create(userDto);
            }
            return(results.Results[0].Artifact.ArtifactID);
        }
Пример #10
0
        public static int CreateUserUsingRepository(IRSAPIClient rsapiClient)
        {
            rsapiClient.APIOptions.WorkspaceID = -1;

            int       newUserArtifactId       = -1;
            const int defaultSelectedFileType = 1;
            const int userType              = 3;
            const int documentSkip          = 1000003;
            const int skipDefaultPreference = 1000004;
            const int password              = 1000005;
            const int sendNewPasswordTo     = 1000006;

            int returnPasswordCodeId = FindChoiceArtifactId(rsapiClient, sendNewPasswordTo, "Return");
            int passwordCodeId       = FindChoiceArtifactId(rsapiClient, password, "Auto-generate password");
            int documentSkipCodeId   = FindChoiceArtifactId(rsapiClient, documentSkip, "Enabled");

            int documentSkipPreferenceCodeId = FindChoiceArtifactId(rsapiClient, skipDefaultPreference, "Normal");
            int defaultFileTypeCodeId        = FindChoiceArtifactId(rsapiClient, defaultSelectedFileType, "Native");
            int userTypeCodeId = FindChoiceArtifactId(rsapiClient, userType, "Internal");

            int everyoneGroupArtifactId = FindGroupArtifactId(rsapiClient, "Everyone");
            int clientArtifactId        = FindClientArtifactId(rsapiClient, "Relativity Template");

            long ticks = DateTime.Now.Ticks;

            kCura.Relativity.Client.DTOs.User userDto = new kCura.Relativity.Client.DTOs.User
            {
                AdvancedSearchPublicByDefault = true,
                AuthenticationData            = "",
                BetaUser                = false,
                ChangePassword          = true,
                ChangePasswordNextLogin = false,
                ChangeSettings          = true,
                Client    = new Client(clientArtifactId),
                DataFocus = 1,
                DefaultSelectedFileType    = new kCura.Relativity.Client.DTOs.Choice(defaultFileTypeCodeId),
                DocumentSkip               = new kCura.Relativity.Client.DTOs.Choice(documentSkipCodeId),
                EmailAddress               = $"email.{ticks}@test.com",
                EnforceViewerCompatibility = true,
                FirstName = $"firstName_{ticks}",
                Groups    = new List <Group> {
                    new Group(everyoneGroupArtifactId)
                },
                ItemListPageLength     = 25,
                KeyboardShortcuts      = true,
                LastName               = "Test User",
                MaximumPasswordAge     = 0,
                NativeViewerCacheAhead = true,
                PasswordAction         = new kCura.Relativity.Client.DTOs.Choice(passwordCodeId),
                RelativityAccess       = true,
                SendPasswordTo         = new kCura.Relativity.Client.DTOs.Choice(returnPasswordCodeId),
                SkipDefaultPreference  = new kCura.Relativity.Client.DTOs.Choice(documentSkipPreferenceCodeId),
                TrustedIPs             = "",
                Type = new kCura.Relativity.Client.DTOs.Choice(userTypeCodeId)
            };

            WriteResultSet <kCura.Relativity.Client.DTOs.User> userWriteResultSet = new WriteResultSet <kCura.Relativity.Client.DTOs.User>();

            try
            {
                userWriteResultSet = rsapiClient.Repositories.User.Create(userDto);
            }
            catch (Exception ex)
            {
                Console.WriteLine($"An error occurred: {ex.Message}");
            }

            // Check for success.
            if (!userWriteResultSet.Success)
            {
                Console.WriteLine($"An error occurred creating user: {userWriteResultSet.Message}");

                foreach (Result <kCura.Relativity.Client.DTOs.User> createResult in userWriteResultSet.Results)
                {
                    if (!createResult.Success)
                    {
                        Console.WriteLine($"An error occurred in create request: {createResult.Message}");
                    }
                }
            }

            if (userWriteResultSet.Results != null)
            {
                newUserArtifactId = userWriteResultSet.Results.FirstOrDefault().Artifact.ArtifactID;
            }
            return(newUserArtifactId);
        }