Skip to content

Cleanup exist code #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/Acl.Net.Core.Database/AclDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,21 @@
/// <typeparam name="TUser">The type of the user entity.</typeparam>
/// <typeparam name="TRole">The type of the role entity.</typeparam>
/// <typeparam name="TResource">The type of the resource entity.</typeparam>
public abstract class AclDbContext<TKey, TUser, TRole, TResource> : DbContext

Check warning on line 59 in src/Acl.Net.Core.Database/AclDbContext.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

Reduce the number of generic parameters in the 'AclDbContext' class to no more than the 2 authorized. (https://rules.sonarsource.com/csharp/RSPEC-2436)

Check warning on line 59 in src/Acl.Net.Core.Database/AclDbContext.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

Reduce the number of generic parameters in the 'AclDbContext' class to no more than the 2 authorized. (https://rules.sonarsource.com/csharp/RSPEC-2436)
where TKey : IEquatable<TKey>
where TUser : User<TKey>
where TRole : Role<TKey>
where TResource : Resource<TKey>
{
private readonly IInitialDataSeeder<TKey, TRole> seeder;
private readonly IInitialDataSeeder<TKey, TRole> _seeder;

/// <summary>
/// Initializes a new instance of the <see cref="AclDbContext{TKey, TUser, TRole, TResource}"/> class with the provided data seeder.
/// </summary>
/// <param name="seeder">The initial data seeder.</param>
protected AclDbContext(IInitialDataSeeder<TKey, TRole> seeder)
{
this.seeder = seeder;
_seeder = seeder;
}

/// <summary>
Expand All @@ -80,7 +80,7 @@
/// <param name="seeder">The initial data seeder.</param>
protected AclDbContext(DbContextOptions options, IInitialDataSeeder<TKey, TRole> seeder) : base(options)
{
this.seeder = seeder;
_seeder = seeder;
}

/// <summary>
Expand Down Expand Up @@ -122,7 +122,7 @@

entity.HasMany<TResource>().WithOne().HasForeignKey(res => res.RoleId).IsRequired();

entity.HasData(seeder.SeedAdminRole(), seeder.SeedUserRole());
entity.HasData(_seeder.SeedAdminRole(), _seeder.SeedUserRole());
});

modelBuilder.Entity<TResource>(entity =>
Expand Down
2 changes: 1 addition & 1 deletion src/Acl.Net.Core.Database/Entities/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Represents a specific resource in the system.
/// </summary>
public class Resource : Resource<int> { }
public class Resource : Resource<int>;

/// <summary>
/// Represents a specific resource in the system, identified by a generic key type.
Expand Down
2 changes: 1 addition & 1 deletion src/Acl.Net.Core.Database/Entities/Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Represents a role within the Access Control List (ACL) system.
/// </summary>
public class Role : Role<int> { }
public class Role : Role<int>;

/// <summary>
/// Represents a role within the Access Control List (ACL) system, with a specific key type.
Expand Down
2 changes: 1 addition & 1 deletion src/Acl.Net.Core.Database/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// <summary>
/// Represents a user in the system.
/// </summary>
public class User : User<int> { }
public class User : User<int>;

/// <summary>
/// Represents a user in the system, identified by a generic key type.
Expand Down
50 changes: 25 additions & 25 deletions src/Acl.Net.Core.Managers/AclManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@
/// <typeparam name="TUser">The type of the user, which must be a derived type of <see cref="User{TKey}"/>.</typeparam>
/// <typeparam name="TRole">The type of the role, which must be a derived type of <see cref="Role{TKey}"/></typeparam>
/// <typeparam name="TResource">The type of the resource, which must be a derived type of <see cref="Resource{TKey}"/></typeparam>
public class AclManager<TKey, TUser, TRole, TResource> : IAclManager<TKey, TUser, TResource>

Check warning on line 115 in src/Acl.Net.Core.Managers/AclManager.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

Reduce the number of generic parameters in the 'AclManager' class to no more than the 2 authorized. (https://rules.sonarsource.com/csharp/RSPEC-2436)
where TKey : IEquatable<TKey>
where TUser : User<TKey>, new()
where TRole : Role<TKey>
where TResource : Resource<TKey>
{
protected readonly IInitialDataSeeder<TKey, TRole> initialDataSeeder;
protected readonly IUserManager<TKey, TUser, TRole> userManager;
protected readonly IResourceManager<TKey, TUser, TResource> resourceManager;
protected readonly IInitialDataSeeder<TKey, TRole> InitialDataSeeder;
protected readonly IUserManager<TKey, TUser, TRole> UserManager;
protected readonly IResourceManager<TKey, TUser, TResource> ResourceManager;

/// <summary>
/// Initializes a new instance of the <see cref="AclManager{TKey,TUser,TRole,TResource}"/> class
Expand All @@ -134,9 +134,9 @@
AclDbContext<TKey, TUser, TRole, TResource> context
)
{
this.initialDataSeeder = initialDataSeeder;
userManager = new UserManager<TKey, TUser, TRole, TResource>(context);
resourceManager = new ResourceManager<TKey, TUser, TRole, TResource>(context, initialDataSeeder);
InitialDataSeeder = initialDataSeeder;
UserManager = new UserManager<TKey, TUser, TRole, TResource>(context);
ResourceManager = new ResourceManager<TKey, TUser, TRole, TResource>(context, initialDataSeeder);
}

/// <summary>
Expand All @@ -152,9 +152,9 @@
IResourceManager<TKey, TUser, TResource> resourceManager
)
{
this.initialDataSeeder = initialDataSeeder;
this.userManager = userManager;
this.resourceManager = resourceManager;
InitialDataSeeder = initialDataSeeder;
UserManager = userManager;
ResourceManager = resourceManager;
}

/// <summary>
Expand All @@ -168,8 +168,8 @@
/// </exception>
public virtual bool IsPermitted(string userName, string resourceName)
{
var user = userManager.UserProcessing(userName, initialDataSeeder.SeedUserRole());
return resourceManager.IsPermitted(user, resourceName);
var user = UserManager.UserProcessing(userName, InitialDataSeeder.SeedUserRole());
return ResourceManager.IsPermitted(user, resourceName);
}

/// <summary>
Expand All @@ -183,7 +183,7 @@
/// </exception>
public virtual bool IsPermitted(TUser user, string resourceName)
{
return resourceManager.IsPermitted(user, resourceName);
return ResourceManager.IsPermitted(user, resourceName);
}

/// <summary>
Expand All @@ -194,8 +194,8 @@
/// <returns><see langword="true"/> if the user is permitted to access the resource; otherwise, <see langword="false"/>.</returns>
public virtual bool IsPermitted(string userName, TResource resource)
{
var user = userManager.UserProcessing(userName, initialDataSeeder.SeedUserRole());
return resourceManager.IsPermitted(user, resource);
var user = UserManager.UserProcessing(userName, InitialDataSeeder.SeedUserRole());
return ResourceManager.IsPermitted(user, resource);
}

/// <summary>
Expand All @@ -206,7 +206,7 @@
/// <returns><see langword="true"/> if the user is permitted to access the resource; otherwise, <see langword="false"/>.</returns>
public virtual bool IsPermitted(TUser user, TResource resource)
{
return resourceManager.IsPermitted(user, resource);
return ResourceManager.IsPermitted(user, resource);
}

/// <summary>
Expand All @@ -221,8 +221,8 @@
/// </exception>
public virtual IEnumerable<TResource> IsPermitted(string userName, IEnumerable<string> resourceNames)
{
var user = userManager.UserProcessing(userName, initialDataSeeder.SeedUserRole());
return resourceManager.IsPermitted(user, resourceNames);
var user = UserManager.UserProcessing(userName, InitialDataSeeder.SeedUserRole());
return ResourceManager.IsPermitted(user, resourceNames);
}

/// <summary>
Expand All @@ -237,8 +237,8 @@
/// </exception>
public virtual async Task<bool> IsPermittedAsync(string userName, string resourceName)
{
var user = await userManager.UserProcessingAsync(userName, initialDataSeeder.SeedUserRole());
return await resourceManager.IsPermittedAsync(user, resourceName);
var user = await UserManager.UserProcessingAsync(userName, InitialDataSeeder.SeedUserRole());
return await ResourceManager.IsPermittedAsync(user, resourceName);
}

/// <summary>
Expand All @@ -253,7 +253,7 @@
/// </exception>
public virtual async Task<bool> IsPermittedAsync(TUser user, string resourceName)
{
return await resourceManager.IsPermittedAsync(user, resourceName);
return await ResourceManager.IsPermittedAsync(user, resourceName);
}

/// <summary>
Expand All @@ -265,8 +265,8 @@
/// The task result contains <see langword="true"/> if the user is permitted to access the resource; otherwise, <see langword="false"/>.</returns>
public virtual async Task<bool> IsPermittedAsync(string userName, TResource resource)
{
var user = await userManager.UserProcessingAsync(userName, initialDataSeeder.SeedUserRole());
return await resourceManager.IsPermittedAsync(user, resource);
var user = await UserManager.UserProcessingAsync(userName, InitialDataSeeder.SeedUserRole());
return await ResourceManager.IsPermittedAsync(user, resource);
}

/// <summary>
Expand All @@ -278,7 +278,7 @@
/// The task result contains <see langword="true"/> if the user is permitted to access the resource; otherwise, <see langword="false"/>.</returns>
public virtual async Task<bool> IsPermittedAsync(TUser user, TResource resource)
{
return await resourceManager.IsPermittedAsync(user, resource);
return await ResourceManager.IsPermittedAsync(user, resource);
}

/// <summary>
Expand All @@ -294,7 +294,7 @@
/// </exception>
public virtual async Task<IEnumerable<TResource>> IsPermittedAsync(string userName, IEnumerable<string> resourceNames)
{
var user = await userManager.UserProcessingAsync(userName, initialDataSeeder.SeedUserRole());
return await resourceManager.IsPermittedAsync(user, resourceNames);
var user = await UserManager.UserProcessingAsync(userName, InitialDataSeeder.SeedUserRole());
return await ResourceManager.IsPermittedAsync(user, resourceNames);
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
using System.Runtime.Serialization;

namespace Acl.Net.Core.Managers.Exceptions;
namespace Acl.Net.Core.Managers.Exceptions;

/// <summary>
/// Represents an exception that is thrown when a specific resource is not found.
/// </summary>
[Serializable]
public class ResourceNotFoundException : Exception
{
/// <summary>
Expand All @@ -15,13 +12,4 @@ public class ResourceNotFoundException : Exception
public ResourceNotFoundException(string resourceName)
: base($"Resource with name '{resourceName}' not found.")
{ }

/// <summary>
/// Initializes a new instance of the <see cref="ResourceNotFoundException"/> class with serialized data.
/// </summary>
/// <param name="info">The <see cref="SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
/// <param name="context">The <see cref="StreamingContext"/> that contains contextual information about the source or destination.</param>
protected ResourceNotFoundException(SerializationInfo info, StreamingContext context)
: base(info, context)
{ }
}
8 changes: 2 additions & 6 deletions src/Acl.Net.Core.Managers/IAclManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@
/// <summary>
/// Defines the basic contract for Access Control List (ACL) management.
/// </summary>
public interface IAclManager : IAclManager<int>
{
}
public interface IAclManager : IAclManager<int>;

/// <summary>
/// Defines the contract for Access Control List (ACL) management with support for a specific key type.
/// </summary>
/// <typeparam name="TKey">The type of key used to identify users and resources.</typeparam>
public interface IAclManager<TKey> : IAclManager<TKey, User<TKey>, Resource<TKey>>
where TKey : IEquatable<TKey>
{
}
where TKey : IEquatable<TKey>;

/// <summary>
/// Defines the contract for Access Control List (ACL) management with support for specific key, user, and resource types.
Expand All @@ -24,7 +20,7 @@
/// <typeparam name="TKey">The type of key used to identify users and resources.</typeparam>
/// <typeparam name="TUser">The type representing a user.</typeparam>
/// <typeparam name="TResource">The type representing a resource.</typeparam>
public interface IAclManager<TKey, in TUser, TResource>

Check warning on line 23 in src/Acl.Net.Core.Managers/IAclManager.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

Reduce the number of generic parameters in the 'IAclManager' interface to no more than the 2 authorized. (https://rules.sonarsource.com/csharp/RSPEC-2436)

Check warning on line 23 in src/Acl.Net.Core.Managers/IAclManager.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

Reduce the number of generic parameters in the 'IAclManager' interface to no more than the 2 authorized. (https://rules.sonarsource.com/csharp/RSPEC-2436)
where TKey : IEquatable<TKey>
where TUser : User<TKey>
where TResource : Resource<TKey>
Expand Down
8 changes: 2 additions & 6 deletions src/Acl.Net.Core.Managers/IResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@
/// <summary>
/// Manages resource-related operations with a specific integer key type.
/// </summary>
public interface IResourceManager : IResourceManager<int>
{
}
public interface IResourceManager : IResourceManager<int>;

/// <summary>
/// Manages resource-related operations with a specific key type.
/// </summary>
/// <typeparam name="TKey">The type of the key.</typeparam>
public interface IResourceManager<TKey> : IResourceManager<TKey, User<TKey>, Resource<TKey>>
where TKey : IEquatable<TKey>
{
}
where TKey : IEquatable<TKey>;

/// <summary>
/// Manages resource-related operations with specific user and resource types.
Expand All @@ -24,7 +20,7 @@
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TUser">The type of the user.</typeparam>
/// <typeparam name="TResource">The type of the resource.</typeparam>
public interface IResourceManager<TKey, in TUser, TResource>

Check warning on line 23 in src/Acl.Net.Core.Managers/IResourceManager.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

Reduce the number of generic parameters in the 'IResourceManager' interface to no more than the 2 authorized. (https://rules.sonarsource.com/csharp/RSPEC-2436)

Check warning on line 23 in src/Acl.Net.Core.Managers/IResourceManager.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

Reduce the number of generic parameters in the 'IResourceManager' interface to no more than the 2 authorized. (https://rules.sonarsource.com/csharp/RSPEC-2436)
where TKey : IEquatable<TKey>
where TUser : User<TKey>
where TResource : Resource<TKey>
Expand Down
8 changes: 2 additions & 6 deletions src/Acl.Net.Core.Managers/IUserManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@
/// <summary>
/// Defines the contract for managing user-related operations using integer keys.
/// </summary>
public interface IUserManager : IUserManager<int>
{
}
public interface IUserManager : IUserManager<int>;

/// <summary>
/// Defines the contract for managing user-related operations with a specific key type.
/// </summary>
/// <typeparam name="TKey">The type of the key.</typeparam>
public interface IUserManager<TKey> : IUserManager<TKey, User<TKey>, Role<TKey>>
where TKey : IEquatable<TKey>
{
}
where TKey : IEquatable<TKey>;

/// <summary>
/// Defines the contract for managing user-related operations with specific user and role types.
Expand All @@ -24,7 +20,7 @@
/// <typeparam name="TKey">The type of the key.</typeparam>
/// <typeparam name="TUser">The type of the user.</typeparam>
/// <typeparam name="TRole">The type of the role.</typeparam>
public interface IUserManager<TKey, TUser, in TRole>

Check warning on line 23 in src/Acl.Net.Core.Managers/IUserManager.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

Reduce the number of generic parameters in the 'IUserManager' interface to no more than the 2 authorized. (https://rules.sonarsource.com/csharp/RSPEC-2436)
where TKey : IEquatable<TKey>
where TUser : User<TKey>
where TRole : Role<TKey>
Expand Down
20 changes: 10 additions & 10 deletions src/Acl.Net.Core.Managers/ResourceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@
/// <typeparam name="TUser">The type of the user.</typeparam>
/// <typeparam name="TRole">The type of the role.</typeparam>
/// <typeparam name="TResource">The type of the resource.</typeparam>
public class ResourceManager<TKey, TUser, TRole, TResource> : IResourceManager<TKey, TUser, TResource>

Check warning on line 49 in src/Acl.Net.Core.Managers/ResourceManager.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

Reduce the number of generic parameters in the 'ResourceManager' class to no more than the 2 authorized. (https://rules.sonarsource.com/csharp/RSPEC-2436)
where TKey : IEquatable<TKey>
where TUser : User<TKey>, new()
where TRole : Role<TKey>
where TResource : Resource<TKey>
{
protected readonly AclDbContext<TKey, TUser, TRole, TResource> context;
protected readonly IInitialDataSeeder<TKey, TRole> initialDataSeeder;
protected readonly AclDbContext<TKey, TUser, TRole, TResource> Context;
protected readonly IInitialDataSeeder<TKey, TRole> InitialDataSeeder;

/// <summary>
/// Initializes a new instance of the <see cref="ResourceManager{TKey, TUser, TRole, TResource}"/> class.
Expand All @@ -65,8 +65,8 @@
IInitialDataSeeder<TKey, TRole> initialDataSeeder
)
{
this.context = context;
this.initialDataSeeder = initialDataSeeder;
Context = context;
InitialDataSeeder = initialDataSeeder;
}

/// <summary>
Expand All @@ -92,8 +92,8 @@
/// <returns><see langword="true"/> if the user is permitted to access the resource; otherwise, <see langword="false"/>.</returns>
public virtual bool IsPermitted(TUser user, TResource resource)
{
return user.RoleId.Equals(initialDataSeeder.SeedAdminRole().Id) ||
context.Resources.Any(r => r.RoleId.Equals(user.RoleId) && r.Id.Equals(resource.Id));
return user.RoleId.Equals(InitialDataSeeder.SeedAdminRole().Id) ||
Context.Resources.Any(r => r.RoleId.Equals(user.RoleId) && r.Id.Equals(resource.Id));
}

/// <summary>
Expand Down Expand Up @@ -146,8 +146,8 @@
/// The task result contains <see langword="true"/> if the user is permitted to access the resource; otherwise, <see langword="false"/>.</returns>
public virtual async Task<bool> IsPermittedAsync(TUser user, TResource resource)
{
return user.RoleId.Equals(initialDataSeeder.SeedAdminRole().Id) ||
await context.Resources.AnyAsync(r => r.RoleId.Equals(user.RoleId) && r.Id.Equals(resource.Id));
return user.RoleId.Equals(InitialDataSeeder.SeedAdminRole().Id) ||
await Context.Resources.AnyAsync(r => r.RoleId.Equals(user.RoleId) && r.Id.Equals(resource.Id));
}

/// <summary>
Expand Down Expand Up @@ -204,7 +204,7 @@
/// </exception>
public virtual TResource GetResourceByName(string resourceName)
{
return context.Resources.FirstOrDefault(r => r.Name == resourceName)
return Context.Resources.FirstOrDefault(r => r.Name == resourceName)
?? throw new ResourceNotFoundException(resourceName);
}

Expand All @@ -219,7 +219,7 @@
/// </exception>
public virtual async Task<TResource> GetResourceByNameAsync(string resourceName)
{
return await context.Resources.FirstOrDefaultAsync(r => r.Name == resourceName)
return await Context.Resources.FirstOrDefaultAsync(r => r.Name == resourceName)
?? throw new ResourceNotFoundException(resourceName);
}
}
Loading
Loading