protected override async Task <Group> OnExecute(IReadableDataSource dataSource) { if (SecurityGroup.Id == 0) { throw new ArgumentOutOfRangeException(nameof(SecurityGroup), "SecurityGroup.Id must have a value"); } if (SecurityGroup.Tenant == null) { throw new ArgumentOutOfRangeException(nameof(SecurityGroup), "SecurityGroup.Tenant must have a value"); } if (SecurityGroup.Tenant.Id == 0) { throw new ArgumentOutOfRangeException(nameof(SecurityGroup), "SecurityGroup.Tenant.Id must have a value"); } var databaseConnection = await dataSource.GetDbConnection(); var groupDetailsBatch = await databaseConnection.QueryMultipleAsync("security.usp_GetSecurityGroupById", new { Tenant_ID = SecurityGroup.Tenant.Id, Security_Group_ID = SecurityGroup.Id }, commandType : System.Data.CommandType.StoredProcedure, commandTimeout : 30); var groupDetails = await groupDetailsBatch.ReadSingleOrDefaultAsync <Group>(); var memberDetails = await groupDetailsBatch.ReadAsync(); var permissionDetails = await groupDetailsBatch.ReadAsync(); groupDetails.Users = (from member in memberDetails select new GroupMembership() { Id = member.Id, Enabled = member.Enabled, User = new Jibberwock.DataModels.Users.User() { Id = member.UserId, Name = member.UserName, Type = (Jibberwock.DataModels.Users.UserType)(int) member.UserType } }).ToArray(); groupDetails.AccessControlEntries = (from ace in permissionDetails select new AccessControlEntry() { Id = ace.Id, Permission = (Permission)ace.Permission, Resource = SecurableResourceHelpers.GetSecurableResourceFromDatabase(ace) }).ToArray(); return(groupDetails); }
protected override async Task <IEnumerable <SecurableResource> > OnExecute(IReadableDataSource dataSource) { if (CurrentUser.Id == 0) { throw new ArgumentOutOfRangeException(nameof(CurrentUser), "CurrentUser.Id must have a value"); } if (Tenant != null && Tenant.Id == 0) { throw new ArgumentOutOfRangeException(nameof(Tenant), "Tenant.Id must have a value"); } var databaseConnection = await dataSource.GetDbConnection(); var resultantFilter = NameFilter.Replace("*", "%"); var matchingObjects = await databaseConnection.QueryAsync("security.usp_GetSecurableResourcesByName", new { Name_Filter = resultantFilter, User_ID = CurrentUser.Id, Tenant_ID = Tenant?.Id }, commandType : System.Data.CommandType.StoredProcedure, commandTimeout : 30); return((from sr in matchingObjects select SecurableResourceHelpers.GetSecurableResourceFromDatabase(sr) as SecurableResource) .ToArray()); }
protected override async Task <AccessControlEntry> OnAuditedExecute(IReadWriteDataSource dataSource, IDbTransaction transaction, ModifyAccessControlEntry provisionalAuditTrailEntry) { if (AccessControlEntry.Group == null) { throw new ArgumentOutOfRangeException(nameof(AccessControlEntry), "AccessControlEntry.Group must have a value"); } if (AccessControlEntry.Group.Id == 0) { throw new ArgumentOutOfRangeException(nameof(AccessControlEntry), "AccessControlEntry.Group.Id must have a value"); } if (AccessControlEntry.Group.Tenant == null) { throw new ArgumentOutOfRangeException(nameof(AccessControlEntry), "AccessControlEntry.Group.Tenant must have a value"); } if (AccessControlEntry.Group.Tenant.Id == 0) { throw new ArgumentOutOfRangeException(nameof(AccessControlEntry), "AccessControlEntry.Group.Tenant.Id must have a value"); } if (AccessControlEntry.Resource == null) { throw new ArgumentOutOfRangeException(nameof(AccessControlEntry), "AccessControlEntry.Resource must have a value"); } if (AccessControlEntry.Resource.Id == 0) { throw new ArgumentOutOfRangeException(nameof(AccessControlEntry), "AccessControlEntry.Resource.Id must have a value"); } if (!Enum.IsDefined(typeof(Permission), AccessControlEntry.Permission)) { throw new ArgumentOutOfRangeException(nameof(AccessControlEntry), "AccessControlEntry.Permission must be a valid Permission"); } var databaseConnection = await dataSource.GetDbConnection(); provisionalAuditTrailEntry.RelatedTenant = AccessControlEntry.Group.Tenant; var resultantAccessControlEntry = await databaseConnection.QueryAsync <AccessControlEntry, Group, dynamic, Tenant, AccessControlEntry>("security.usp_CreateAccessControlEntry", (ace, grp, sr, ten) => { if (ace != null && grp != null) { ace.Group = grp; } if (ace != null && sr != null) { ace.Resource = SecurableResourceHelpers.GetSecurableResourceFromDatabase(sr); } if (ace != null && ten != null) { ace.ResourceTenant = ten; } return(ace); }, new { Tenant_ID = AccessControlEntry.Group.Tenant.Id, User_ID = PerformedBy.Id, Security_Group_ID = AccessControlEntry.Group.Id, Securable_Resource_ID = AccessControlEntry.Resource.Id, Permission_ID = AccessControlEntry.Permission }, transaction : transaction, commandType : System.Data.CommandType.StoredProcedure, commandTimeout : 30); AccessControlEntry = resultantAccessControlEntry.FirstOrDefault(); provisionalAuditTrailEntry.AccessControlEntry = AccessControlEntry; provisionalAuditTrailEntry.NewAccessControlEntry = true; return(AccessControlEntry); }