Example #1
0
        public JsonResult ValidateEmail(string email, long id = 0)
        {
            SubjectManager subjectManager = new SubjectManager();

            User user = subjectManager.GetUserByEmail(email);

            if (user == null)
            {
                return Json(true, JsonRequestBehavior.AllowGet);
            }
            else
            {
                if (user.Id == id)
                {
                    return Json(true, JsonRequestBehavior.AllowGet);
                }
                else
                {
                    string error = String.Format(CultureInfo.InvariantCulture, "The Email Address exists already.", email);

                    return Json(error, JsonRequestBehavior.AllowGet);
                }
            }
        }
Example #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.";
        }