/// <summary> /// 撤销角色权限 /// </summary> public int Revoke(Role role, Priv resource, IList <Operation> operations) { // using (DaoManager _dao = new DaoManager()) // { PrivLogic privlogic = new PrivLogic(); IDictionary <Priv, IList <Operation> > _permission = privlogic.QueryPermission(resource.Type, resource.Id, role); string _pmsExp = ""; if (_permission != null && _permission.Count > 0) //修改 { int rtn = privlogic.DelResRoleMap(resource.Id, role.ID); if (rtn <= 0) { return(-1); } foreach (KeyValuePair <Priv, IList <Operation> > _pair in _permission) { foreach (Operation _opera in _pair.Value) { if (!IsContainOperation(_opera, operations)) { _pmsExp = _pmsExp + _opera.Id + "|"; } } break; } return(privlogic.InsertResRoleMap(resource, role.ID, _pmsExp, "")); } return(0); //} }
/// <summary> /// 角色授权 /// </summary> public int Grant(Role role, Priv resource, IList <Operation> operations, object param) { //using (DaoManager _dao = new DaoManager()) //{ PrivLogic privlogic = new PrivLogic(); IDictionary <Priv, IList <Operation> > _permission = privlogic.QueryPermission(resource.Type, resource.Id, role); string _pmsExp = ""; //新增 if (_permission.Count == 0) { foreach (Operation _opera in operations) { _pmsExp = _pmsExp + _opera.Id + "|"; } return(privlogic.InsertResRoleMap(resource, role.ID, _pmsExp, (param == null ? "" : param.ToString()))); } else //修改 { int rtn = privlogic.DelResRoleMap(resource.Id, role.ID); if (rtn <= 0) { return(-1); } foreach (KeyValuePair <Priv, IList <Operation> > _pair in _permission) { foreach (Operation _opera in _pair.Value) { _pmsExp = _pmsExp + _opera.Id + "|"; } break; } foreach (Operation _opera in operations) { if (_pmsExp.IndexOf(_opera.Id) < 0) { _pmsExp = _pmsExp + _opera.Id + "|"; } } return(privlogic.InsertResRoleMap(resource, role.ID, _pmsExp, (param == null ? "" : param.ToString()))); } //} }
/// <summary> /// 撤销角色对某一资源全部权限 /// </summary> public int Revoke(Role role, Priv resource) { //using (DaoManager _dao = new DaoManager()) //{ PrivLogic privlogic = new PrivLogic(); IDictionary <Priv, IList <Operation> > _permission = privlogic.QueryPermission(resource.Type, resource.Id, role); if (_permission != null && _permission.Count > 0) //修改 { int rtn = privlogic.DelResRoleMap(resource.Id, role.ID); if (rtn <= 0) { return(-1); } } return(0); //} }
/// <summary> /// 保存权限 /// </summary> /// <param name="resType"></param> /// <param name="role"></param> /// <param name="resource"></param> /// <param name="pmsExp"></param> /// <returns></returns> public static int SavePermission(string resType, Role role, Priv resource, string pmsExp) { //using (DaoManager _dao = new DaoManager()) //{ PrivLogic privlogic = new PrivLogic(); IDictionary <Priv, IList <Operation> > _permission = privlogic.QueryPermission(resType, resource.Id, role); //新增 if (_permission.Count > 0) { int rtn = privlogic.DelResRoleMap(resource.Id, role.ID); if (rtn <= 0) { return(-1); } } return(privlogic.InsertResRoleMap(resource, role.ID, pmsExp, "")); //} }
/// <summary> /// 是否允许角色对资源的操作 /// </summary> public bool IsAllowed(Role role, Priv resource, Operation operation) { PrivLogic privlogic = new PrivLogic(); IDictionary <Priv, IList <Operation> > _permission = privlogic.QueryPermission(resource.Type, resource.Id, role); if (_permission == null || _permission.Count == 0) { return(false); } foreach (KeyValuePair <Priv, IList <Operation> > _pair in _permission) { foreach (Operation _opera in _pair.Value) { if (_opera.Id == operation.Id) { return(true); } } break; } return(false); }