public ActionResult Create(GroupRole collection) { if (!Request.IsAuthenticated || !userRepository.canAccessData(User.Identity.Name, "QuanTriNguoiDung")) { TempData["message"] = "Bạn không có quyền truy cập vào trang phân quyền nhóm người dùng"; TempData["messageType"] = "error"; return(RedirectToAction("Index", "AdminHome")); } try { // TODO: Add insert logic here GroupRole groupRole = repository.GroupRoles.Where(gr => gr.GroupID == collection.GroupID).FirstOrDefault(); if (groupRole != null) { collection.id = groupRole.id; } repository.saveGroupRole(collection); TempData["message"] = "Đã phân quyền cho nhóm người dùng"; TempData["messageType"] = "inf"; return(RedirectToAction("Create", new { GroupID = collection.GroupID })); } catch (Exception ex) { TempData["message"] = "Có lỗi hệ thống : " + ex.Message; TempData["messageType"] = "error"; return(View(new { GroupID = collection.GroupID })); } }
public static GroupRoleCollection LoadForGroup(Int32 groupId) { GroupRoleCollection GroupRoles = new GroupRoleCollection(); //CREATE THE DYNAMIC SQL TO LOAD OBJECT StringBuilder selectQuery = new StringBuilder(); selectQuery.Append("SELECT RoleId"); selectQuery.Append(" FROM ac_GroupRoles"); selectQuery.Append(" WHERE GroupId = @groupId"); Database database = Token.Instance.Database; DbCommand selectCommand = database.GetSqlStringCommand(selectQuery.ToString()); database.AddInParameter(selectCommand, "@groupId", System.Data.DbType.Int32, groupId); //EXECUTE THE COMMAND using (IDataReader dr = database.ExecuteReader(selectCommand)) { while (dr.Read()) { GroupRole groupRole = new GroupRole(); groupRole.GroupId = groupId; groupRole.RoleId = dr.GetInt32(0); GroupRoles.Add(groupRole); } dr.Close(); } return(GroupRoles); }
public ActionResult Delete(int id, GroupRole collection) { if (!Request.IsAuthenticated || !userRepository.canAccessData(User.Identity.Name, "QuanTriNguoiDung")) { TempData["message"] = "Bạn không có quyền truy cập vào trang phân quyền nhóm người dùng"; TempData["messageType"] = "error"; return(RedirectToAction("Index", "AdminHome")); } try { string result = repository.deleteGroupRole(id); if (result.Trim().Length == 0) { result = "Đã xóa thành công "; } TempData["message"] = result; TempData["messageType"] = "inf"; return(RedirectToAction("Create", new { GroupID = collection.GroupID })); } catch (Exception ex) { TempData["message"] = "Có lỗi hệ thống : " + ex.Message; TempData["messageType"] = "error"; return(View(id)); } }
List <GroupRole> IGroupRolesInterface.this[UGUI requestingAgent, UGI group] { get { var roles = new List <GroupRole>(); using (var conn = new MySqlConnection(m_ConnectionString)) { conn.Open(); using (var cmd = new MySqlCommand("SELECT r.*," + RCountQuery + " FROM grouproles AS r WHERE r.GroupID = @groupid", conn)) { cmd.Parameters.AddParameter("@groupid", group.ID); using (MySqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { GroupRole role = reader.ToGroupRole(); role.Group = ResolveName(requestingAgent, role.Group); roles.Add(role); } } } } return(roles); } }
List <GroupRole> IGroupRolesInterface.this[UGUI requestingAgent, UGI group, UGUI principal] { get { var roles = new List <GroupRole>(); using (var conn = new SqlConnection(m_ConnectionString)) { conn.Open(); using (var cmd = new SqlCommand("SELECT r.*," + RCountQuery + " FROM grouprolememberships AS rm INNER JOIN grouproles AS r ON rm.GroupID AND r.GroupID AND rm.RoleID = r.RoleID WHERE r.GroupID = @groupid AND rm.PrincipalID = @principalid", conn)) { cmd.Parameters.AddParameter("@groupid", group.ID); cmd.Parameters.AddParameter("@principalid", principal.ID); using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read()) { GroupRole role = reader.ToGroupRole(); role.Group = ResolveName(requestingAgent, role.Group); roles.Add(role); } } } } return(roles); } }
public async Task <GroupSchema> RegisterGroupNewAsync(GroupSchema groupSchema, string creationUser) { var group = new Group() { Name = groupSchema.Name, CreationDate = DateTimeOffset.Now, ChangeDate = DateTimeOffset.Now }; group.GroupRoles = new List <GroupRole>(); foreach (var role in groupSchema.Roles) { var groupRole = new GroupRole() { GroupId = group.Id, RoleId = role }; group.GroupRoles.Add(groupRole); } await Context.Groups.AddAsync(group); await Context.SaveChangesAsync(); var result = MapResult(group); return(await Task.FromResult(result)); }
public IActionResult PutGroupRole(int id, [FromBody] GroupRole groupRole) { groupRole.Id = id; var groupRoleFound = this.context.GroupRoles.FirstOrDefault(group => group.Id == id); if (groupRoleFound is null) { return(BadRequest(new ErrorModel { Messege = "Không tìm thấy nhóm quyền" })); } else { if (this.entityCRUD.Update <GroupRole, GroupRole>(groupRole, groupRoleFound).Result) { return(Ok(true)); } else { return(BadRequest(new ErrorModel { Messege = "Vui lòng nhập đủ các trường" })); } } }
public GroupRoleListViewModel UpdateGroupRole(GroupRoleListViewModel model) { var entityCollection = this._groupRolesRepository.Get(null).Where(x => x.GroupId == model.GroupId); if (entityCollection.Count() > 0) { foreach (var item in entityCollection) { this._groupRolesRepository.Delete(item); } this._unitOfWork.Commit(); } if (model.List?.Count > 0) { foreach (var item in model.List) { GroupRole newEntity = new GroupRole { GroupId = model.GroupId, RoleId = item.Value }; this._groupRolesRepository.Add(newEntity); } this._unitOfWork.Commit(); } return(model); }
public async Task <IActionResult> DeleteRole(string roleid) { GroupRole role = _context.GroupRoles.FirstOrDefault(r => r.RoleId.ToLower() == roleid.ToLower()); if (role == null) { StatusMessage = "Error: The Role was null!"; return(Redirect(Request.Headers["Referer"].ToString())); } Group group = _context.Groups.FirstOrDefault(g => g.Id == role.GroupId); if (group == null) { StatusMessage = "Error: The Role's Group was null!"; return(Redirect(Request.Headers["Referer"].ToString())); } User user = await _userManager.GetUserAsync(User); if (!await group.HasPermissionAsync(user, "createrole")) { StatusMessage = "Error: You don't have permission!"; return(Redirect(Request.Headers["Referer"].ToString())); } _context.GroupRoles.Remove(role); await _context.SaveChangesAsync(); StatusMessage = $"Successfully deleted the role {role.Name}!"; return(Redirect(Request.Headers["Referer"].ToString())); }
public ActionResult GrandRole(GroupRole gr) { string mes = ""; //Kiểm tra quyền đã có hay chưa. var data = db.GroupRoles.Any(x => x.GroupId == gr.GroupId && x.BusinessId == gr.BusinessId && x.RoleId == gr.RoleId); //Lấy ra quyền cần huỷ if (data) { //huỷ quyền var grouprole = db.GroupRoles.FirstOrDefault(x => x.GroupId == gr.GroupId && x.BusinessId == gr.BusinessId && x.RoleId == gr.RoleId); db.GroupRoles.Remove(grouprole); db.SaveChanges(); mes = "Huỷ quyền thành công"; } else { //gán quyền db.GroupRoles.Add(gr); db.SaveChanges(); mes = "Gán quyền thành công"; } return(Json(new { StatusCode = 200, Message = mes, }, JsonRequestBehavior.AllowGet)); }
public bool AddRole(Guid roleId, Guid groupId) { try { var groupRoleBO = new GroupRoleBO(); var groupRole = groupRoleBO.Get(this.ConnectionHandler, groupId, roleId); if (groupRole == null) { var role = new GroupRole { GroupId = groupId, RoleId = roleId }; if (!groupRoleBO.Insert(this.ConnectionHandler, role)) { throw new Exception("خطایی در ذخیره نقش گروه وجود دارد"); } } return(true); } catch (KnownException ex) { Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } catch (Exception ex) { Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } }
public static CreateRoleModel FromExisting(GroupRole role) { CreateRoleModel model = new CreateRoleModel() { Color = role.Color, GroupId = role.GroupId, RoleId = role.RoleId, Weight = role.Weight, Name = role.Name, Salary = role.Salary }; model.CreateRole = role.Permissions.Contains("createrole|"); model.AddRole = role.Permissions.Contains("addrole|"); model.RemoveRole = role.Permissions.Contains("removerole|"); model.Invite = role.Permissions.Contains("addinvite|"); model.Uninvite = role.Permissions.Contains("uninvite|"); model.Kick = role.Permissions.Contains("kick|"); model.Ban = role.Permissions.Contains("ban|"); model.Edit = role.Permissions.Contains("edit|"); model.Description = role.Permissions.Contains("description|"); model.Post = role.Permissions.Contains("post|"); model.Eco = role.Permissions.Contains("eco|"); model.Plots = role.Permissions.Contains("plot|"); model.Plots = role.Permissions.Contains("news|"); return(model); }
public async Task <string> Handle(CreateGroupRoleCommand request, CancellationToken cancellationToken) { // Pokusím se načíst skupinu uživatelů, do které se má přidat nová role (vyhodím výjimku, pokud ji nedohledám). var group = await _groupRepository.GetByIdAsync(request.GroupId, true); // Připravím si role aktuálně přihlášeného uživatele, abych věděl jestli má právo na přidání role. var currentUserRoles = _groupRoleRepository.GetForUserInGroup(_currentUserIdService.UserId, request.GroupId); // Pokud nemá aktuálně přihlášený uživatel právo na přidání role, vyhodím výjimku. if (group.CreatedBy != _currentUserIdService.UserId && currentUserRoles.Any(r => r.Permission == UserGroupPermission.Admin)) { throw new ForbiddenAccessException(); } // Vytvořím entitu naplněnou daty z příkazu. var entity = new GroupRole() { GroupId = request.GroupId, Name = request.Name, Permission = request.Permission }; // Přidám záznam do datového zdroje a uložím.` await _groupRoleRepository.AddOrUpdateAsync(entity, cancellationToken); await _unitOfWork.SaveChangesAsync(cancellationToken); // Vrátím Id vytvořeného záznamu. return(entity.Id); }
/// <summary> /// 将数据插入表 /// </summary> /// <param name="M">赋值后的实体</param> /// <returns></returns> public static void Insert(GroupRole M) { IDbHelper Sql = GetHelper(); StringBuilder sb = new StringBuilder(); sb.Append("insert into [GroupRole]([UserID],[RoleID]) values("); sb.Append(M.UserID.ToS()); sb.Append(","); sb.Append(M.RoleID.ToS()); sb.Append(")"); if (DataBase.CmsDbType == DataBase.DbType.SqlServer) { sb.Append(";select @@Identity"); } if (DataBase.CmsDbType == DataBase.DbType.SQLite) { sb.Append(";select last_insert_rowid()"); } if (DataBase.CmsDbType == DataBase.DbType.MySql) { sb.Append(";select LAST_INSERT_ID()"); } if (DataBase.CmsDbType == DataBase.DbType.Access) { sb.Append(";select max(ID) from GroupRole"); } if (DataBase.CmsDbType == DataBase.DbType.Oracle) { sb.Append(";select LAST_INSERT_ID()"); } M.ID = Sql.ExecuteScalar(CommandType.Text, sb.ToString()).ToInt32(); }
public ActionResult UpdatePermission(GroupRole groupRole) { // kiểm tra quền đã được gán hay chưa if (_groupRole.GetAll().Any(x => x.GroupId == groupRole.GroupId && x.BusinessId == groupRole.BusinessId && x.RoleId == groupRole.RoleId)) { // nếu có thì xóa (hủy quên) // lấy đối tượng cần xóa var obj = _groupRole.GetAll().FirstOrDefault(x => x.GroupId == groupRole.GroupId && x.BusinessId == groupRole.BusinessId && x.RoleId == groupRole.RoleId); _groupRole.DeleteEntity(obj); return(Json(new { Status = 200, Message = "Successfully canceled" }, JsonRequestBehavior.AllowGet));; } else { _groupRole.Create(groupRole); return(Json(new { Status = 200, Message = "Successful assignment" }, JsonRequestBehavior.AllowGet)); } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); string roleIdParam = PageParameter("groupRoleId"); if (!string.IsNullOrWhiteSpace(roleIdParam)) { int roleId = int.MinValue; if (int.TryParse(roleIdParam, out roleId) && !roleId.Equals(0)) { _groupRole = new GroupRoleService().Get(roleId); } else { _groupRole = new GroupRole { Id = 0 }; } _groupRole.LoadAttributes(); phAttributes.Controls.Clear(); Rock.Attribute.Helper.AddEditControls(_groupRole, phAttributes, !Page.IsPostBack); } }
/// <summary> /// Shows the edit. /// </summary> /// <param name="groupRoleId">The group role id.</param> protected void ShowEdit(int groupRoleId) { pnlList.Visible = false; pnlDetails.Visible = true; GroupRoleService groupRoleService = new GroupRoleService(); GroupRole groupRole = groupRoleService.Get(groupRoleId); bool readOnly = false; hfGroupRoleId.Value = groupRoleId.ToString(); LoadDropDowns(); if (groupRole != null) { iconIsSystem.Visible = groupRole.IsSystem; hfGroupRoleId.Value = groupRole.Id.ToString(); tbName.Text = groupRole.Name; tbDescription.Text = groupRole.Description; ddlGroupType.SelectedValue = groupRole.GroupTypeId.ToString(); tbSortOrder.Text = groupRole.SortOrder != null?groupRole.SortOrder.ToString() : string.Empty; tbMaxCount.Text = groupRole.MaxCount != null?groupRole.MaxCount.ToString() : string.Empty; tbMinCount.Text = groupRole.MinCount != null?groupRole.MinCount.ToString() : string.Empty; readOnly = groupRole.IsSystem; if (groupRole.IsSystem) { lActionTitle.Text = ActionTitle.View(GroupRole.FriendlyTypeName); btnCancel.Text = "Close"; } else { lActionTitle.Text = ActionTitle.Edit(GroupRole.FriendlyTypeName); btnCancel.Text = "Cancel"; } } else { lActionTitle.Text = ActionTitle.Add(GroupRole.FriendlyTypeName); iconIsSystem.Visible = false; hfGroupRoleId.Value = 0.ToString(); tbName.Text = string.Empty; tbDescription.Text = string.Empty; ddlGroupType.SelectedValue = null; tbSortOrder.Text = string.Empty; tbMinCount.Text = string.Empty; tbMaxCount.Text = string.Empty; } tbName.ReadOnly = readOnly; tbDescription.ReadOnly = readOnly; ddlGroupType.Enabled = !readOnly; tbSortOrder.ReadOnly = readOnly; tbMaxCount.ReadOnly = readOnly; tbMinCount.ReadOnly = readOnly; btnSave.Visible = !readOnly; }
public async Task <IActionResult> CreateRole(string groupid, string roleid) { Group group = await _context.Groups.FindAsync(groupid); User user = await _userManager.GetUserAsync(User); if (string.IsNullOrWhiteSpace(roleid)) { roleid = ""; } GroupRole role = await _context.GroupRoles.FindAsync(roleid); CreateRoleModel model; if (role == null) { model = new CreateRoleModel() { GroupId = group.Id }; } else { model = CreateRoleModel.FromExisting(role); } return(View(model)); }
private bool CheckPrivileges(string ipPort, GroupRole min) { if (_authUsers.ContainsKey(ipPort) && _authUsers[ipPort] != null) { return(_authUsers[ipPort].GroupRole >= min); } return(false); }
/// <summary> /// Builds a list of available roles /// </summary> private void BuildRoles() { DataView roles = BusinessObject.GetAllAsDataView <Role>(); roles.Sort = Role.Role_Field + " ASC"; GroupRole.DataSource = roles; GroupRole.DataBind(); }
void IGroupRolesInterface.Update(UGUI requestingAgent, GroupRole role) { if (!IsGroupOwner(role.Group, requestingAgent)) { VerifyAgentPowers(role.Group, requestingAgent, GroupPowers.RoleProperties); } m_InnerService.Roles.Update(requestingAgent, role); }
public GroupMember(WorldClient client, GroupRole role) { Client = client; Character = client.Character; CharId = client.Character.ID; Role = role; Name = client.Character.Character.Name; IsOnline = true; }
/// <summary> /// Check if the user has a given GroupRole level /// </summary> /// <param name="u"></param> /// <param name="min"></param> /// <returns></returns> public bool CheckPrivileges(User u, GroupRole min) { if (!_authUsers.Contains(u)) { return(false); } return(u.GroupRole >= min); }
public static GroupRole Load(Int32 groupId, Int32 roleId) { GroupRole groupRole = new GroupRole(); groupRole.GroupId = groupId; groupRole.RoleId = roleId; groupRole.IsDirty = false; return(groupRole); }
public GroupMember(WorldClient client, GroupRole role) { this.Client = client; this.Character = client.Character; this.CharId = client.Character.ID; this.Role = role; this.Name = client.Character.Character.Name; this.IsOnline = true; }
public HttpResponseMessage UpdateGroupRole(HttpRequestMessage request, [FromBody] GroupRole groupRoleModel) { return(GetHttpResponse(request, () => { var groupRole = _CoreService.UpdateGroupRole(groupRoleModel); return request.CreateResponse <GroupRole>(HttpStatusCode.OK, groupRole); })); }
public static bool Delete(Int32 groupId, Int32 roleId) { GroupRole groupRole = new GroupRole(); if (groupRole.Load(groupId, roleId)) { return(groupRole.Delete()); } return(false); }
public ActionResult DeleteConfirmed(int id) { GroupRole groupRole = _groupRole.Get(id); _groupRole.Remove(groupRole); //GroupRole groupRole = db.GroupRoles.Find(id); //db.GroupRoles.Remove(groupRole); //db.SaveChanges(); return(RedirectToAction("Index")); }
public GroupRole(GroupRole src) { Group = new UGI(src.Group); ID = src.ID; Name = src.Name; Description = src.Description; Title = src.Title; Powers = src.Powers; Members = src.Members; }
public virtual GroupRole GetUserRole(User user, int groupId) { GroupUser relation = db.find <GroupUser>(getCondition(groupId, user.Id)).first(); if (relation == null) { return(null); } return(GroupRole.GetById(relation.Status)); }
public static GroupRole CreateGroupRole(int id) { GroupRole groupRole = new GroupRole(); groupRole.ID = id; return groupRole; }
public void AddToGroupRole(GroupRole groupRole) { base.AddObject("GroupRole", groupRole); }