/// <summary> /// 根据userID和一组ContainerID,加载该Member所拥有的权限 /// </summary> /// <param name="userID"></param> /// <param name="containerIDs"></param> /// <returns></returns> public SCContainerAndPermissionCollection LoadCurrentContainerAndPermissions(string userID, IEnumerable <string> containerIDs) { var ids = containerIDs.ToArray(); SCContainerAndPermissionCollection result = null; var roleIDs = (from r in new OguUser(userID).Roles.GetAllRoles() select r.ID).ToArray(); if (ids.Length > 0 && roleIDs.Length > 0) { var timeConditon1 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder("A."); var condition = new WhereSqlClauseBuilder(); condition.AppendItem("A.Status", (int)SchemaObjectStatus.Normal); InSqlClauseBuilder inSql = new InSqlClauseBuilder("A.ContainerID"); inSql.AppendItem(ids); InSqlClauseBuilder inSqlRole = new InSqlClauseBuilder("A.MemberID"); inSqlRole.AppendItem(roleIDs); var sql = string.Format( "SELECT A.* FROM SC.Acl_Current A WHERE {0} ORDER BY SortID ", new ConnectiveSqlClauseCollection(timeConditon1, condition, inSql, inSqlRole).ToSqlString(TSqlBuilder.Instance)); result = new SCContainerAndPermissionCollection(); AUCommon.DoDbAction(() => { using (DbContext context = DbContext.GetContext(this.GetConnectionName())) { using (IDataReader reader = DbHelper.RunSqlReturnDR(sql, this.GetConnectionName())) { while (reader.Read()) { string containerID = (string)reader["ContainerID"]; string permission = (string)reader["ContainerPermission"]; if (result.ContainsKey(containerID, permission) == false) { result.Add(new SCContainerAndPermission() { ContainerID = containerID, ContainerPermission = permission }); } } } } }); return(result); } else { result = new SCContainerAndPermissionCollection(); } return(result); }
/// <summary> /// 根据userID和一组ContainerID,加载该Member所拥有的权限 /// </summary> /// <param name="userID"></param> /// <param name="containerIDs"></param> /// <returns></returns> public SCContainerAndPermissionCollection LoadCurrentContainerAndPermissions(string userID, IEnumerable<string> containerIDs) { var ids = containerIDs.ToArray(); SCContainerAndPermissionCollection result = null; var roleIDs = (from r in new OguUser(userID).Roles.GetAllRoles() select r.ID).ToArray(); if (ids.Length > 0 && roleIDs.Length > 0) { var timeConditon1 = VersionStrategyQuerySqlBuilder.Instance.TimePointToBuilder("A."); var condition = new WhereSqlClauseBuilder(); condition.AppendItem("A.Status", (int)SchemaObjectStatus.Normal); InSqlClauseBuilder inSql = new InSqlClauseBuilder("A.ContainerID"); inSql.AppendItem(ids); InSqlClauseBuilder inSqlRole = new InSqlClauseBuilder("A.MemberID"); inSqlRole.AppendItem(roleIDs); var sql = string.Format( "SELECT A.* FROM SC.Acl_Current A WHERE {0} ORDER BY SortID ", new ConnectiveSqlClauseCollection(timeConditon1, condition, inSql, inSqlRole).ToSqlString(TSqlBuilder.Instance)); result = new SCContainerAndPermissionCollection(); AUCommon.DoDbAction(() => { using (DbContext context = DbContext.GetContext(this.GetConnectionName())) { using (IDataReader reader = DbHelper.RunSqlReturnDR(sql, this.GetConnectionName())) { while (reader.Read()) { string containerID = (string)reader["ContainerID"]; string permission = (string)reader["ContainerPermission"]; if (result.ContainsKey(containerID, permission) == false) { result.Add(new SCContainerAndPermission() { ContainerID = containerID, ContainerPermission = permission }); } } } } }); return result; } else { result = new SCContainerAndPermissionCollection(); } return result; }
internal static bool ContainsPermission(SCContainerAndPermissionCollection permissions, string containerID, string permission) { if (permissions == null || string.IsNullOrEmpty(containerID)) { return(false); } else { return(permissions.ContainsKey(containerID, permission)); } }
/// <summary> /// 是否拥有指定的权限 /// </summary> /// <param name="principal"></param> /// <param name="permissions"></param> /// <param name="permissionName"></param> /// <param name="containerIDs"></param> /// <returns></returns> public static bool HasPermissions(IPrincipal principal, SCContainerAndPermissionCollection permissions, string permissionName, params string[] containerIDs) { bool result = IsSupervisor(principal); if (result == false) { if (principal != null) { permissions.NullCheck("permissions"); foreach (string containerID in containerIDs) { if (permissions.ContainsKey(containerID, permissionName)) { result = true; break; } } } } return result; }
/// <summary> /// 是否拥有指定的权限 /// </summary> /// <param name="principal"></param> /// <param name="permissions"></param> /// <param name="permissionName"></param> /// <param name="containerIDs"></param> /// <returns></returns> public static bool HasPermissions(IPrincipal principal, SCContainerAndPermissionCollection permissions, string permissionName, params string[] containerIDs) { bool result = IsSupervisor(principal); if (result == false) { if (principal != null) { permissions.NullCheck("permissions"); foreach (string containerID in containerIDs) { if (permissions.ContainsKey(containerID, permissionName)) { result = true; break; } } } } return(result); }