public async Task <IActionResult> Create(RoleViewModel model) { //if (!HasPermission("CREATE_ROLES")) //{ // return Unauthorized(); //} if (ModelState.IsValid) { var role = model.ToEntity(); var result = await _roleManager.CreateAsync(role); if (result.Succeeded) { return(RedirectToAction("Index")); } else { AddErrors(result); } } ViewBag.PermissionGroups = PermissionGroup.GetList(); ViewBag.Permissions = _context.Permissions.ToList().ToListViewModel(); return(View(model)); }
/// <summary> /// populates a PermissionGroup with its child entities /// </summary> /// <param name="permissionGroup"></param> /// <param name="fillChilds"></param> private void FillPermissionGroupWithChilds(PermissionGroup permissionGroupObject, bool fillChilds) { // populate child data for a permissionGroupObject if (permissionGroupObject != null) { } }
public async Task <IActionResult> Edit(RoleViewModel model) { //if (!HasPermission("EDIT_ROLES")) //{ // return Unauthorized(); //} var role = await _roleManager.Roles.Include(r => r.RolePermissions).FirstOrDefaultAsync(r => r.Id == model.Id); if (role == null) { return(NotFound()); } if (ModelState.IsValid) { role = model.UpdateEntity(role); var result = await _roleManager.UpdateAsync(role); if (result.Succeeded) { return(RedirectToAction("Index")); } else { AddErrors(result); } } ViewBag.PermissionGroups = PermissionGroup.GetList(); ViewBag.Permissions = _context.Permissions.ToList().ToListViewModel(); return(View(model)); }
/// <summary> /// 添加权限分组 /// </summary> /// <param name="permissionGroup">权限信息</param> /// <returns>执行结果</returns> Result <PermissionGroup> AddPermissionGroup(PermissionGroup permissionGroup) { #region 级 long parentGroupId = permissionGroup.Parent == null ? 0 : permissionGroup.Parent.Id; PermissionGroup parentGroup = null; if (parentGroupId > 0) { IQuery parentQuery = QueryManager.Create <PermissionGroupEntity>(c => c.Id == parentGroupId); parentGroup = permissionGroupRepository.Get(parentQuery); if (parentGroup == null) { return(Result <PermissionGroup> .FailedResult("请选择正确的上级分组")); } } permissionGroup.SetParent(parentGroup); #endregion permissionGroup.Save();//保存 var result = Result <PermissionGroup> .SuccessResult("添加成功"); result.Data = permissionGroup; return(result); }
public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Domain,AccessType,Enable,User,Date")] PermissionGroup permissionGroup) { if (id != permissionGroup.Id) { return(NotFound()); } try { permissionGroup.Date = DateTime.Now; permissionGroup.User = User.Identity.Name; if (ModelState.IsValid) { _context.Update(permissionGroup); await _context.SaveChangesAsync(); GALibrary.GALogs.SaveLog("PermissionGroup", "Fim da edicao do grupo de permissao " + permissionGroup.Name + " realizada pelo usuario " + User.Identity.Name, 2, _context.Parameter.FirstOrDefault()); return(RedirectToAction(nameof(Index))); } ViewBag.AccessType = this.GetPermissionNames(permissionGroup.AccessType); ViewBag.PermissionGroupEnabled = new SelectList(new[] { new { ID = true, Name = "Sim" }, new { ID = false, Name = "Não" }, }, "ID", "Name", permissionGroup.Enable); return(View(permissionGroup)); } catch (Exception erro) { GALibrary.GALogs.SaveLog("PermissionGroup", "Erro ao editar grupo de permissao " + permissionGroup.Name + " pelo usuario " + User.Identity.Name + ": " + erro.ToString(), 1, _context.Parameter.FirstOrDefault()); return(View("~/Views/Shared/Error.cshtml")); } }
public IHttpActionResult PutPermissionGroup(int id, PermissionGroup permissionGroup) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != permissionGroup.Id) { return(BadRequest()); } db.Entry(permissionGroup).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!PermissionGroupExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
/// <summary> /// Tells if a user is allowed to add or remove other users from the given permission group. /// </summary> /// <param name="permissionGroup"></param> /// <param name="processingUserId"></param> /// <returns></returns> protected PermissionGroupModifiableStatus CanUserModifyMembershipForGroup(PermissionGroup permissionGroup, int processingUserId) { using (var db = new DatabaseContext()) { var processingUser = db.Users .Include(x => x.Permissions) .Single(x => x.ProfileId == processingUserId); //if you are a Bot Owner, you are always allowed to do it if (PermissionGroup.BotOwner.In(processingUser.Permissions.Select(x => x.PermissionGroup))) { return(PermissionGroupModifiableStatus.CanModifyGroupMembership); } //the only general restriction is that you are in the group you are trying to modify if (!permissionGroup.In(processingUser.Permissions.Select(x => x.PermissionGroup))) { return(PermissionGroupModifiableStatus.NotInGroup); } //now check rules specific to each group switch (permissionGroup) { case PermissionGroup.Reviewer: return(CanUserModifyReviewerGroup(permissionGroup, processingUser)); case PermissionGroup.BotOwner: return(CanUserModifyBotOwnersGroup(permissionGroup, processingUser)); default: throw new Exception("Unknow permission group, unable to determine specific modification restrictions."); } } }
public PermissionGroup AddOrUpdatePermissionGroup(PermissionGroup groupModel) { if (string.IsNullOrWhiteSpace(groupModel.GroupName) == false) { PermissionGroup groupEntity = _permissionGroupRepository.Get(x => x.GroupName == groupModel.GroupName); if (groupEntity == null) { groupEntity = new PermissionGroup() { GroupName = groupModel.GroupName }; _permissionGroupRepository.Add(groupEntity); } else { groupEntity = new PermissionGroup { Permissions = groupModel.Permissions, Id = groupModel.Id, GroupName = groupModel.GroupName }; } return(groupEntity); } else { throw new ArgumentNullException("Group name is empty or whitespace."); } }
private void FindUrl(string action, string controller) { using (FlyDbContext cxt = new FlyDbContext()) { var path = "/" + controller + "/" + action; var i = cxt.PermissionLines.Where(m => m.Url.ToLower().Contains(path.ToLower())).Count(); i += cxt.PermissionGroups.Where(m => m.Url.ToLower().Contains(path.ToLower()) && m.PlatformId == cxt.Platforms.FirstOrDefault().Id).Count(); if (i == 0) { PermissionGroup permissionGroup = cxt.PermissionGroups.Where(m => m.DisplayName == "未初始化的权限组").FirstOrDefault(); if (permissionGroup == null) { permissionGroup = new PermissionGroup { DisplayName = "未初始化的权限组", Tag = "#", Url = "#", SN = 0, PermissionLines = new List <PermissionLine>(), PlatformId = cxt.Platforms.FirstOrDefault().Id }; cxt.PermissionGroups.Add(permissionGroup); } permissionGroup.PermissionLines.Add( new PermissionLine { DisplayName = "未初始化的权限项", Url = path, Tag = "#" }); cxt.SaveChanges(); } } }
public async Task <IActionResult> Edit(int id, [Bind("GroupName,Domain,AccessType,Id")] PermissionGroup permissionGroup, int[] ReportIDSelected) { if (id != permissionGroup.Id) { return(NotFound()); } if (ModelState.IsValid) { permissionGroup.User = User.Identity.Name; permissionGroup.ChangeDate = DateTime.Now; var result = await permissionGroupRepository.Update(permissionGroup, ReportIDSelected); if (result == null) { return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); } await SetSelectViewBag(permissionGroup); return(View(permissionGroup)); }
internal bool AddPermission(string userName, Permission permission, out string permissionID, out string errorMessage) { permissionID = null; errorMessage = null; var organization = RemotelyContext.Users .Include(x => x.Organization) .ThenInclude(x => x.PermissionGroups) .FirstOrDefault(x => x.UserName == userName) .Organization; if (organization.PermissionGroups.Any(x => x.Name.ToLower() == permission.Name.ToLower())) { errorMessage = "Permission group already exists."; return(false); } var newPermission = new PermissionGroup() { Name = permission.Name, Organization = organization }; organization.PermissionGroups.Add(newPermission); RemotelyContext.SaveChanges(); permissionID = newPermission.ID; return(true); }
/// <summary> /// Retrieves list of PermissionGroup objects from SqlCommand, after database query /// number of rows retrieved and returned depends upon the rows field value /// </summary> /// <param name="cmd">The command object to use for query</param> /// <param name="rows">Number of rows to process</param> /// <returns>A list of PermissionGroup objects</returns> private PermissionGroupList GetList(SqlCommand cmd, long rows) { // Select multiple records SqlDataReader reader; long result = SelectRecords(cmd, out reader); //PermissionGroup list PermissionGroupList list = new PermissionGroupList(); using ( reader ) { // Read rows until end of result or number of rows specified is reached while (reader.Read() && rows-- != 0) { PermissionGroup permissionGroupObject = new PermissionGroup(); FillObject(permissionGroupObject, reader); list.Add(permissionGroupObject); } // Close the reader in order to receive output parameters // Output parameters are not available until reader is closed. reader.Close(); } return(list); }
public async Task <IActionResult> Create([Bind("Id,Name,Domain,AccessType,Enable,User,Date")] PermissionGroup permissionGroup) { try { permissionGroup.Date = DateTime.Now; permissionGroup.User = User.Identity.Name; permissionGroup.Enable = true; if (ModelState.IsValid) { _context.Add(permissionGroup); await _context.SaveChangesAsync(); GALibrary.GALogs.SaveLog("PermissionGroup", "Fim do cadastro do grupo de permissao " + permissionGroup.Name + " pelo usuario " + User.Identity.Name, 2, _context.Parameter.FirstOrDefault()); return(RedirectToAction(nameof(Index))); } ViewBag.AccessType = this.GetPermissionNames(permissionGroup.AccessType); return(View(permissionGroup)); } catch (Exception erro) { GALibrary.GALogs.SaveLog("PermissionGroup", "Erro ao cadastrar grupo de permissao pelo usuario " + User.Identity.Name + ": " + erro.ToString(), 1, _context.Parameter.FirstOrDefault()); return(View("~/Views/Shared/Error.cshtml")); } }
public async Task Add(PermissionGroup permissionGroup, Guid _UserId) { repository.AddAndReturnObject <PermissionGroup>(ref permissionGroup); await repository.SaveChangesAsync(); await loggingService.LogActionData <PermissionGroup>(LoggingCategory.PermissionGroup, LoggingAction.Create, permissionGroup, null, _UserId, permissionGroup.Code.ToString()); }
/// <summary> /// Update PermissionGroup Object. /// Data manipulation processing for: new, deleted, updated PermissionGroup /// </summary> /// <param name="permissionGroupObject"></param> /// <returns></returns> public bool Update(PermissionGroup permissionGroupObject) { bool success = false; success = UpdateBase(permissionGroupObject); return(success); }
public ActionResult DeleteConfirmed(int id) { PermissionGroup permissionGroup = db.PermissionGroups.Find(id); db.PermissionGroups.Remove(permissionGroup); db.SaveChanges(); return(RedirectToAction("Index")); }
private async Task <int> CreatePermissionGroupDetailAsync(PermissionGroup permissionGroup) { _permissionGroupRepository.Create(permissionGroup); if (await _uow.SaveChangesAsync() == 1) { return(permissionGroup.Id); } return(0); }
public static void EditPermissionGroup(PermissionGroup record) { var itm = appDb.PermissionGroups.FirstOrDefault(item => item.PermissionGroupId == record.PermissionGroupId); itm.IsActive = record.IsActive; itm.PermissionGroupName = record.PermissionGroupName; appDb.SaveChanges(); }
private void LoopGetParent(FlyDbContext ctx, PermissionGroup perGroup, List <PermissionGroup> orgList, Guid platformGuid) { if (perGroup.ParentId != null && !orgList.Exists(delegate(PermissionGroup o) { return(o.Id == perGroup.ParentId); })) { PermissionGroup parentPerGroup = ctx.PermissionGroups.Where(o => o.PlatformId == platformGuid && o.Id == perGroup.ParentId).FirstOrDefault(); orgList.Add(parentPerGroup); LoopGetParent(ctx, parentPerGroup, orgList, platformGuid); } }
public ActionResult _Edit(PermissionGroup pgroup) { if (ModelState.IsValid) { base.genericMgr.Update(pgroup); SaveSuccessMessage(Resources.ACC.PermissionGroup.PermissionGroup_Updated); } return(PartialView(pgroup)); }
public ActionResult Edit([Bind(Include = "Id,Name,Description")] PermissionGroup permissionGroup) { if (ModelState.IsValid) { db.Entry(permissionGroup).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(permissionGroup)); }
private void OnPermissionChanged(PermissionGroup changedItem, PermissionLevel permissionLevel) { if (PermissionChanged != null) { var args = new PermissionValueChangedEventArgs { ChangedItem = changedItem, PermissionLevel = permissionLevel }; PermissionChanged(this, args); } }
public async Task Delete(PermissionGroup permissionGroup, Guid _UserId) { //repository.Remove<PermissionGroup>(permissionGroup); permissionGroup.isActive = false; repository.Update <PermissionGroup>(permissionGroup); await repository.SaveChangesAsync(); await loggingService.LogActionData <PermissionGroup>(LoggingCategory.PermissionGroup, LoggingAction.Delete, permissionGroup, null, _UserId, permissionGroup.Code.ToString()); }
public override WWWResponse ProcessRequest(WWWRequest request) { string nodeName = ""; string groupName = ""; if (request.Form.Count > 0) { nodeName = request.Form ["node"]; groupName = request.Form ["group"]; if (nodeName == null || nodeName == "" || groupName == null || groupName == "") { return(new WWWResponse("/settings/experm", 302)); } if (API.Permissions.Groups.ContainsKey(groupName)) { PermissionGroup pGroup = API.Permissions.Groups [groupName]; if (pGroup.Permissions.Exists(nodeName)) { pGroup.Permissions.Remove(nodeName); API.Permissions.Save(); return(new WWWResponse("/settings/experm/group?group=" + groupName, 302)); } else { return(new WWWResponse("/settings/experm", 302)); } } } else { if (request._request.QueryString ["node"] != null) { nodeName = request._request.QueryString ["node"]; } if (request._request.QueryString ["group"] != null) { groupName = request._request.QueryString ["group"]; } if (nodeName == null || nodeName == "" || groupName == null || groupName == "") { return(new WWWResponse("/settings/experm", 302)); } } string html = Servers.HTTP.WWW._templates["expermgroupremovenode"]; html = html.Replace("{group_name}", groupName); html = html.Replace("{node_name}", nodeName); return(new WWWResponse(html)); }
public IActionResult addGroup([FromBody] PermissionObj form) { try { var userId = this.help.GetCurrentUser(HttpContext); if (userId <= 0) { return(StatusCode(401, "الرجاء الـتأكد من أنك قمت بتسجيل الدخول")); } var perm = this.help.getPermissin("Groups_Add", userId, db); if (!perm) { return(StatusCode(401, "لا تملك الصلاحية")); } if (form == null) { return(BadRequest("حذث خطأ في ارسال البيانات الرجاء إعادة الادخال")); } var Groups = (from p in db.Groups where p.Name == form.name select p).SingleOrDefault(); if (Groups != null) { return(StatusCode(401, "الاسم موجود مسبقا")); } Groups gr = new Groups(); gr.Name = form.name; gr.State = 1; gr.CreatedBy = userId; gr.CreatedOn = DateTime.Now; db.Groups.Add(gr); foreach (var item in form.id) { var h = item; PermissionGroup pg = new PermissionGroup(); pg.PermissioinId = item; pg.GroupId = gr.Id; pg.CreatedBy = userId; pg.CreatedOn = DateTime.Now; pg.State = 1; db.PermissionGroup.Add(pg); } db.SaveChanges(); return(Ok("تمت عملية الاضافة بنجاح")); } catch (Exception e) { return(StatusCode(500, e.Message)); } }
public IHttpActionResult GetPermissionGroup(int id) { PermissionGroup permissionGroup = db.PermissionGroups.Find(id); if (permissionGroup == null) { return(NotFound()); } return(Ok(permissionGroup)); }
public void ModMe(OpenPlayer player) { PermissionGroup permissionGroup = new PermissionGroup("testperms"); permissionGroup.SetPermission("testperms.mod", true); player.Permissions.AddPermissionGroup(permissionGroup); player.RefreshCommands(); player.SendMessage($"You are a mod now!"); }
public IActionResult Create() { //if (!HasPermission("CREATE_ROLES")) //{ // return Unauthorized(); //} ViewBag.PermissionGroups = PermissionGroup.GetList(); ViewBag.Permissions = _context.Permissions.ToList().ToListViewModel(); return(View()); }
public ActionResult Create([Bind(Include = "Id,Name,Description")] PermissionGroup permissionGroup) { if (ModelState.IsValid) { db.PermissionGroups.Add(permissionGroup); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(permissionGroup)); }
public PermissionGroupViewModel(PermissionGroup innerItem) { InnerItem = innerItem; foreach (var permission in InnerItem.AllAvailablePermissions) { Permissions.Add(new PermissionViewModel(permission, this)); } OnPropertyChanged("IsVisible"); }
public PermissionGroup CreateGroup(string groupName, string parentGroupId) { if(string.IsNullOrEmpty(groupName)) { throw new ArgumentNullException("Missing groupName"); } var existingItem = _documentSession.Query<PermissionGroup>().FirstOrDefault(i=>i.GroupName == groupName); if(existingItem != null) { throw new ArgumentException(string.Format("Permission Group with name \"{0}\" already exists", groupName)); } if(!string.IsNullOrEmpty(parentGroupId)) { var parent = _documentSession.Load<PermissionGroup>(parentGroupId); if(parent == null) { throw new ArgumentException("No parent group found for parentGroupId " + parentGroupId); } } var item = new PermissionGroup { Id = Guid.NewGuid().ToString(), GroupName = groupName, ParentGroupId = parentGroupId, }; _documentSession.Store(item); _documentSession.SaveChanges(); return item; }