Пример #1
0
        public string TransferRoles()
        {
            SecurityMigration securityMigration = new SecurityMigration();
            List<string> roles = securityMigration.GetBexisRoles(DataBase);
            SubjectManager subjectManager = new SubjectManager();
            int newGroups = 0;
            foreach (string role in roles)
            {
                string roleName = role;
                if (role.IndexOf('_') == 0)
                    roleName = role.Substring(1, role.Length - 1);
                if (subjectManager.GetGroupByName(roleName) == null)
                {
                    newGroups++;
                    subjectManager.CreateGroup(roleName, roleName);
                    List<string> usersInRole = securityMigration.GetBexisUsersInRole(DataBase, roleName);
                    foreach (string userName in usersInRole)
                    {
                        if (subjectManager.GetUserByName(userName) != null)
                            subjectManager.AddUserToGroup(userName, roleName);
                    }

                }
            }
            return "Groups was successfully transfered and old bexis users added to them";
        }
Пример #2
0
        public string TransferDataPermission()
        {
            SubjectManager subjectManager = new SubjectManager();
            var securityMigration = new SecurityMigration();
            Dictionary<int, int> DataSetIDs = new Dictionary<int, int>();
            var groups = subjectManager.GetAllGroups();
            string DatasetMappingPath = Path.Combine(AppConfiguration.DataPath, "DatasetMapping.txt");
            //Key is last datasetId and value is the new one
            Dictionary<int, int> DatasetsMapping = File.ReadAllLines(DatasetMappingPath).AsEnumerable().Select(item => new { oldId = int.Parse(item.Split('\t')[0]), newId = int.Parse(item.Split('\t')[1]) }).ToDictionary(c => c.oldId, c => c.newId);
            DatasetManager dm = new DatasetManager();

            PermissionManager permissionManager = new PermissionManager();
            List<SecurityMigration.Right> rights = securityMigration.GetBexisRights(DataBase, DatasetsMapping);
            foreach (var group in groups)
            {
                var groupRights = rights.Where(item => item.RoleName == group.Name || item.RoleName == "_" + group.Name);

                foreach (var right in groupRights)
                {
                    int newDataSetId = DatasetsMapping.FirstOrDefault(item => item.Key == right.DataSetId).Value;

                    //each entity wich exists in this list has view and download feature
                    permissionManager.CreateDataPermission(group.Id, 1, newDataSetId, RightType.View);
                    permissionManager.CreateDataPermission(group.Id, 1, newDataSetId, RightType.Download);

                    if (right.CanEdit)
                        permissionManager.CreateDataPermission(group.Id, 1, newDataSetId, RightType.Update);

                }
            }
            foreach (var DatasetMapping in DatasetsMapping)
            {
                //extract grant user from the last version and add it to new ver
                if (dm.GetDataset(DatasetMapping.Value) == null)
                    continue;
                DatasetVersion dsv = dm.GetDatasetLatestVersion(DatasetMapping.Value);
                string grantUserEmailAddress = dsv.Metadata.SelectSingleNode("Metadata/general/general/designatedDatasetManager/contactType/email/email").InnerText;
                if (!string.IsNullOrEmpty(grantUserEmailAddress))
                {
                    var grantUser = subjectManager.GetUserByEmail(grantUserEmailAddress);
                    permissionManager.CreateDataPermission(grantUser.Id, 1, DatasetMapping.Value, RightType.Grant);
                }
            }
            return "All of permissions transfered successfully.";
        }