public ActionResult Groups_Select() { SubjectManager subjectManager = new SubjectManager(); List<GroupGridRowModel> groups = subjectManager.GetAllGroups().Select(g => GroupGridRowModel.Convert(g)).ToList(); return View(new GridModel<GroupGridRowModel> { Data = groups }); }
public ActionResult Membership_Select(long id, long[] selectedGroups) { SubjectManager subjectManager = new SubjectManager(); List<UserMembershipGridRowModel> groups = new List<UserMembershipGridRowModel>(); if (selectedGroups != null) { groups = subjectManager.GetAllGroups().Select(g => UserMembershipGridRowModel.Convert(g, selectedGroups.Contains(g.Id))).ToList(); } else { User user = subjectManager.GetUserById(id); groups = subjectManager.GetAllGroups().Select(g => UserMembershipGridRowModel.Convert(g, g.Users.Any(u => u.Id == id))).ToList(); } return View(new GridModel<UserMembershipGridRowModel> { Data = groups }); }
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."; }