public ActionResult Subjects_Select(long entityId, long instanceId) { var subjectManager = new SubjectManager(); var entityPermissionManager = new EntityPermissionManager(); try { var subjects = new List <EntityPermissionGridRowModel>(); foreach (var subject in subjectManager.Subjects) { var rights = entityPermissionManager.GetRights(subject.Id, entityId, instanceId); var effectiveRights = entityPermissionManager.GetEffectiveRights(subject.Id, entityId, instanceId); subjects.Add(EntityPermissionGridRowModel.Convert(subject, rights, effectiveRights)); } return(View(new GridModel <EntityPermissionGridRowModel> { Data = subjects })); } finally { subjectManager.Dispose(); entityPermissionManager.Dispose(); } }
public ActionResult Subjects_Select(GridCommand command, long entityId, long instanceId) { var subjectManager = new SubjectManager(); var entityPermissionManager = new EntityPermissionManager(); try { var subjectsDb = new List <Subject>(); var count = 0; if (command != null)// filter subjects based on grid filter settings { FilterExpression filter = TelerikGridHelper.Convert(command.FilterDescriptors.ToList()); OrderByExpression orderBy = TelerikGridHelper.Convert(command.SortDescriptors.ToList()); subjectsDb = subjectManager.GetSubjects(filter, orderBy, command.Page, command.PageSize, out count); } else { subjectsDb = subjectManager.Subjects.ToList(); count = subjectsDb.Count(); } var subjects = new List <EntityPermissionGridRowModel>(); //using (PartyManager partyManager = new PartyManager()) //foreach (var subject in subjectsDb) //{ // var rights = entityPermissionManager.GetRights(subject.Id, entityId, instanceId); // var effectiveRights = entityPermissionManager.GetEffectiveRights(subject.Id, entityId, instanceId); // subjects.Add(EntityPermissionGridRowModel.Convert(subject, rights, effectiveRights)); //} var rightsDic = entityPermissionManager.GetRights(subjectsDb, entityId, instanceId); var effectiveRightsDic = entityPermissionManager.GetEffectiveRights(subjectsDb, entityId, instanceId); foreach (var item in rightsDic) { var subject = subjectsDb.Where(s => s.Id.Equals(item.Key)).FirstOrDefault(); var rights = item.Value; var effectiveRights = effectiveRightsDic[item.Key]; subjects.Add(EntityPermissionGridRowModel.Convert(subject, rights, effectiveRights)); } return(View(new GridModel <EntityPermissionGridRowModel> { Data = subjects, Total = count })); } finally { subjectManager.Dispose(); entityPermissionManager.Dispose(); } }
public void CreateAsync_GroupIsNull_ReturnZero(short rights, string[] result) { //Arrange var a = new EntityPermissionManager(); //Act var r = a.GetRights(rights); //Assert Assert.That(result, Is.EquivalentTo(r)); }
public ActionResult Permissions_Select(long subjectId, long entityId, long instanceId) { using (var entityPermissionManager = new EntityPermissionManager()) using (var subjectManager = new SubjectManager()) using (var partyManager = new PartyManager()) using (var entityManager = new EntityManager()) { var subject = subjectManager.SubjectRepository.Get(subjectId); var entityPermissions = new List <ReferredEntityPermissionGridRowModel>(); // User & Group Permissions if (subject is User) { var user = subject as User; // Group Permissions foreach (var group in user.Groups) { entityPermissions.Add(ReferredEntityPermissionGridRowModel.Convert(group.Name, "Group", entityPermissionManager.GetRights(group.Id, entityId, instanceId))); } // Party Relationships var userParty = partyManager.GetPartyByUser(user.Id); if (userParty != null) { var entityParty = partyManager.Parties.FirstOrDefault(m => m.PartyType.Title == entityManager.FindById(entityId).Name&& m.Name == instanceId.ToString()); if (entityParty != null) { var partyRelationships = partyManager.PartyRelationships.Where(m => m.SourceParty.Id == userParty.Id && m.TargetParty.Id == entityParty.Id); foreach (var partyRelationship in partyRelationships) { entityPermissions.Add(ReferredEntityPermissionGridRowModel.Convert("Party Relationship", partyRelationship.Title, partyRelationship.Permission)); } } } } // Public Permission var publicRights = entityPermissionManager.GetRights(subjectId: null, entityId, instanceId); if (publicRights > 0) { entityPermissions.Add(ReferredEntityPermissionGridRowModel.Convert("Public Dataset", "", publicRights)); } return(View(new GridModel <ReferredEntityPermissionGridRowModel> { Data = entityPermissions })); } }
public ActionResult Decisions(long entityId, string status = "") { using (var entityManager = new EntityManager()) using (var entityPermissionManager = new EntityPermissionManager()) using (var decisionManager = new DecisionManager()) { var entityStore = (IEntityStore)Activator.CreateInstance(entityManager.FindById(entityId).EntityStoreType); IQueryable <Decision> decisions = null; if (status == "Open") { ViewData["status"] = "Open"; decisions = decisionManager.Decisions.Where(d => d.Request.Entity.Id == entityId && d.Request.Status == 0); } else { decisions = decisionManager.Decisions.Where(d => d.Request.Entity.Id == entityId); } List <DecisionGridRowModel> model = new List <DecisionGridRowModel>(); foreach (var m in decisions) { //check if the entity exist otherwise set a default text for the user; string title = entityStore.Exist(m.Request.Key) ? entityStore.GetTitleById(m.Request.Key) : "Dataset currently / no longer accessible"; bool exist = entityStore.Exist(m.Request.Key); model.Add( new DecisionGridRowModel() { Id = m.Id, RequestId = m.Request.Id, Rights = string.Join(", ", entityPermissionManager.GetRights(m.Request.Rights)), //string.Join(",", Enum.GetNames(typeof(RightType)).Select(n => n).Where(n => (m.Request.Rights & (short)Enum.Parse(typeof(RightType), n)) > 0)), Status = m.Status, StatusAsText = Enum.GetName(typeof(DecisionStatus), m.Status), InstanceId = m.Request.Key, Title = title, Applicant = getPartyName(m.Request.Applicant), DecisionMaker = getPartyName(m.DecisionMaker), Intention = m.Request.Intention, RequestDate = m.Request.RequestDate, EntityExist = exist }); } ViewData["entityID"] = entityId; return(PartialView("_DecisionsAdmin", model.OrderBy(x => x.Status).ThenBy(n => n.Id))); } }
public ActionResult Decisions(long entityId) { using (var entityManager = new EntityManager()) using (var entityPermissionManager = new EntityPermissionManager()) using (var decisionManager = new DecisionManager()) { var entityStore = (IEntityStore)Activator.CreateInstance(entityManager.FindById(entityId).EntityStoreType); // Source + Transformation - Data var decisions = decisionManager.Decisions.Where(d => d.Request.Entity.Id == entityId && d.DecisionMaker.Name == HttpContext.User.Identity.Name); List <DecisionGridRowModel> model = new List <DecisionGridRowModel>(); foreach (var m in decisions) { // add the descicion to the model if the entity exist in the database // exclude when enity was deleted if (entityStore.Exist(m.Request.Key)) { model.Add( new DecisionGridRowModel() { Id = m.Id, RequestId = m.Request.Id, Rights = string.Join(", ", entityPermissionManager.GetRights(m.Request.Rights)), //string.Join(",", Enum.GetNames(typeof(RightType)).Select(n => n).Where(n => (m.Request.Rights & (short)Enum.Parse(typeof(RightType), n)) > 0)), Status = m.Status, StatusAsText = Enum.GetName(typeof(DecisionStatus), m.Status), InstanceId = m.Request.Key, Title = entityStore.GetTitleById(m.Request.Key), Applicant = getPartyName(m.Request.Applicant), Intention = m.Request.Intention, RequestDate = m.Request.RequestDate }); } } return(PartialView("_Decisions", model.OrderBy(x => x.Status).ThenBy(n => n.Id))); } }
public ActionResult Requests(long entityId) { using (var entityManager = new EntityManager()) using (var entityPermissionManager = new EntityPermissionManager()) using (var requestManager = new RequestManager()) { var entityStore = (IEntityStore)Activator.CreateInstance(entityManager.FindById(entityId).EntityStoreType); // Source + Transformation - Data var requests = requestManager.Requests.Where(r => r.Entity.Id == entityId && r.Applicant.Name == HttpContext.User.Identity.Name); List <RequestGridRowModel> model = new List <RequestGridRowModel>(); foreach (var m in requests) { // add the descicion to the model if the entity exist in the database // exclude when enity was deleted if (entityStore.Exist(m.Key)) { model.Add( new RequestGridRowModel() { Id = m.Id, InstanceId = m.Key, Title = entityStore.GetTitleById(m.Key), Rights = string.Join(", ", entityPermissionManager.GetRights(m.Rights)), //string.Join(",", Enum.GetNames(typeof(RightType)).Select(n => n).Where(n => (m.Request.Rights & (short)Enum.Parse(typeof(RightType), n)) > 0)), RequestStatus = Enum.GetName(typeof(RequestStatus), m.Status), Intention = m.Intention, RequestDate = m.RequestDate } ); } } return(PartialView("_Requests", model)); } }
public ActionResult Save(EditNotificationModel model) { using (NotificationManager nManager = new NotificationManager()) using (EntityPermissionManager pManager = new EntityPermissionManager()) using (EntityManager entityTypeManager = new EntityManager()) using (UserManager userManager = new UserManager()) { Dictionary <long, List <string> > dictionary = (Dictionary <long, List <string> >)Session["ResourceFilter"]; if (ModelState.IsValid && dictionary != null) { //if edit need comarison between stored dependensies and set in session //get resource filter from the notification //Dictionary<long, List<string>> dictionary = (Dictionary<long, List<string>>)Session["ResourceFilter"]; Session["ResourceFilter"] = null; List <Schedule> affectedSchedules = GetAffectedSchedules(dictionary, model.StartDate, model.EndDate); Notification notification = new Rbm.Entities.Booking.Notification(); if (model.Id == 0) { notification = nManager.CreateNotification(model.Subject, model.StartDate, model.EndDate, model.Message); } else { notification = nManager.GetNotificationById(model.Id); notification.Subject = model.Subject; notification.StartDate = model.StartDate; notification.EndDate = model.EndDate; notification.Message = model.Message; nManager.UpdateNotification(notification); } //save or update dependencies if (model.Id == 0) { foreach (KeyValuePair <long, List <string> > kp in dictionary) { foreach (string value in kp.Value) { nManager.CreateNotificationDependency(notification, Convert.ToInt64(kp.Key), value); } } } else { //remove dep. for (int i = 0; i < notification.NotificationDependency.Count(); i++) //foreach (NotificationDependency d in notification.NotificationDependency) { if (dictionary.ContainsKey(notification.NotificationDependency.ToList()[i].AttributeId)) { if (dictionary[notification.NotificationDependency.ToList()[i].AttributeId].Contains(notification.NotificationDependency.ToList()[i].DomainItem)) { //:) } else { notification.NotificationDependency.Remove(notification.NotificationDependency.ToList()[i]); nManager.UpdateNotification(notification); //nManager.DeleteNotificationDependency(d); } } else { //delete all dependencies notification.NotificationDependency.Clear(); nManager.UpdateNotification(notification); } } //add dep foreach (KeyValuePair <long, List <string> > kvp in dictionary) { long id = kvp.Key; foreach (string value in kvp.Value) { if (!notification.NotificationDependency.Any(a => a.AttributeId == id && a.DomainItem == value)) { nManager.CreateNotificationDependency(notification, Convert.ToInt64(id), value); } } } } if (notification.Id != 0 && model.Id == 0) { //Start -> add security ---------------------------------------- //31 is the sum from all rights: Read = 1, Write = 4, Delete = 8, Grant = 16 int fullRights = (int)RightType.Read + (int)RightType.Write + (int)RightType.Delete + (int)RightType.Grant; Entity entityType = entityTypeManager.FindByName("Notification"); //get admin groups: format= "groupname:resource structure attribute value" // give rights to group if fetch to notification string[] eventAdminGroups = Helper.Settings.get("EventAdminGroups").ToString().Split(','); Dictionary <string, string> adminGroupsDictionary = new Dictionary <string, string>(); if (eventAdminGroups != null && eventAdminGroups.Length > 0) { foreach (string group in eventAdminGroups) { string[] groupPair = group.Split(':'); adminGroupsDictionary.Add(groupPair[0], groupPair[1]); } } //get resource structrue attribute values to compare with admin group settings if (adminGroupsDictionary.Count > 0) { //get admin groups for notification var values = dictionary.SelectMany(pair => pair.Value).ToList(); var adminGroups = adminGroupsDictionary .Where(pair => values.Contains(pair.Value)) .Select(pair => pair.Key) .ToList(); using (var groupManager = new GroupManager()) { foreach (var g in adminGroups) { var group = groupManager.FindByNameAsync(g).Result; if (group != null) { if (pManager.GetRights(group.Id, entityType.Id, notification.Id) == 0) { pManager.Create(group.Id, entityType.Id, notification.Id, fullRights); } } } } } //rights to bexcis admin group using (var groupManager = new GroupManager()) { var adminGroup = groupManager.FindByNameAsync("administrator").Result; if (pManager.GetRights(adminGroup.Id, entityType.Id, notification.Id) == 0) { pManager.Create(adminGroup.Id, entityType.Id, notification.Id, fullRights); } } //rights to user that has create the notification var userTask = userManager.FindByNameAsync(HttpContext.User.Identity.Name); userTask.Wait(); var user = userTask.Result; pManager.Create(user, entityType, notification.Id, fullRights); //End -> add security ------------------------------------------ } //ToDo: Send email with notification to all in a affected schedule involved people if (affectedSchedules.Count > 0) { SendNotification(notification, affectedSchedules); } //return View("NotificationManager"); return(Json(new { success = true })); } else { List <AttributeDomainItemsModel> attributeDomainItems = (List <AttributeDomainItemsModel>)Session["FilterOptions"]; //Dictionary<long, List<string>> dictionary = (Dictionary<long, List<string>>)Session["ResourceFilter"]; if (dictionary != null) { foreach (AttributeDomainItemsModel m in attributeDomainItems) { for (int i = 0; i < m.DomainItems.Count(); i++) { var list = dictionary.SelectMany(x => x.Value); if (list.Contains(m.DomainItems[i].Key)) { m.DomainItems[i].Selected = true; } } } } model.AttributeDomainItems = attributeDomainItems; return(PartialView("_editNotification", model)); } } }