Class AuthorityRepository
- Namespace
- adas_core.Infrastructure.Repositories
- Assembly
- adas-core.Infrastructure.dll
Repository for managing user authorities and permissions in the system. This repository provides methods to create, retrieve, and delete authorities based on user and unit identifiers. It also includes logging for debugging purposes and ensures that initial data is loaded when necessary.
public class AuthorityRepository : MongoRepository<Authorization>, IAuthorityRepository, IMongoRepository<Authorization>
- Inheritance
-
AuthorityRepository
- Implements
- Inherited Members
- Extension Methods
Constructors
AuthorityRepository(IOptions<ApiSettings>, IMongoDatabase, ILogger<AuthorityRepository>)
Repository for managing user authorities and permissions in the system. This repository provides methods to create, retrieve, and delete authorities based on user and unit identifiers. It also includes logging for debugging purposes and ensures that initial data is loaded when necessary.
public AuthorityRepository(IOptions<ApiSettings> apiSettings, IMongoDatabase database, ILogger<AuthorityRepository> logger)
Parameters
apiSettingsIOptions<ApiSettings>The API settings containing configuration for the repository.
databaseIMongoDatabaseThe MongoDB database instance.
loggerILogger<AuthorityRepository>The logger for logging information, warnings, and errors.
Methods
CreateNewAuthority(string, ObjectId)
Creates a new authority for a user with the specified role. This method generates a new display ID for the authority and inserts it into the database. It also logs the creation of the new authority for debugging purposes.
public void CreateNewAuthority(string roleName, ObjectId userId)
Parameters
roleNamestringThe name of the role to be assigned to the new authority.
userIdObjectIdThe ID of the user for whom the new authority is being created.
DeleteAllAuthoritiesByDisplay(ObjectId)
Deletes all authorities associated with a specific display ID. This method constructs a filter to identify authorities that match the provided display ID and deletes them from the database. It also logs the deletion of authorities for debugging purposes.
public Task<bool> DeleteAllAuthoritiesByDisplay(ObjectId displayId)
Parameters
displayIdObjectIdThe ID of the display whose authorities are being deleted.
Returns
DeleteAllAuthoritiesByUnit(ObjectId)
Deletes all authorities associated with a specific unit ID. This method constructs a filter to identify authorities that match the provided unit ID and deletes them from the database. It also logs the deletion of authorities for debugging purposes.
public Task<bool> DeleteAllAuthoritiesByUnit(ObjectId unitId)
Parameters
unitIdObjectIdThe ID of the unit whose authorities are being deleted.
Returns
DeleteAllAuthoritiesByUser(ObjectId)
Deletes all authorities associated with a specific user ID. This method constructs a filter to identify authorities that match the provided user ID and deletes them from the database. It also logs the deletion of authorities for debugging purposes.
public Task<bool> DeleteAllAuthoritiesByUser(ObjectId userId)
Parameters
userIdObjectIdThe ID of the user whose authorities are being deleted.
Returns
GetAllAuthorities()
Retrieves a list of all authorities in the system. This method queries the database for all authority records and returns them as a list. It also logs the retrieval of all authorities for debugging purposes.
public Task<List<Authorization>> GetAllAuthorities()
Returns
- Task<List<Authorization>>
A list of all authorities in the system.
GetById(ObjectId)
Retrieves an authority by its unique identifier. This method constructs a filter to identify the authority that matches the provided ID and retrieves it from the database. It also logs the retrieval of the authority for debugging purposes.
public Task<Authorization> GetById(ObjectId authId)
Parameters
authIdObjectIdThe unique identifier of the authority to be retrieved.
Returns
- Task<Authorization>
The authority that matches the provided ID, or null if no matching authority is found.
GetByUnitId(ObjectId)
Retrieves a list of authorities associated with a specific unit ID. This method queries the database for authorities that match the provided unit ID and returns them as a list. It also logs the retrieval of authorities for debugging purposes.
public Task<List<Authorization>> GetByUnitId(ObjectId unitId)
Parameters
unitIdObjectIdThe ID of the unit whose authorities are being retrieved.
Returns
- Task<List<Authorization>>
A list of authorities associated with the specified unit ID.
GetCollectionName()
Retrieves the name of the collection used for storing authorities in the database. This method returns the collection name as specified in the API settings configuration.
public override string GetCollectionName()
Returns
GetUserAuthorities(ObjectId)
Retrieves a list of authorities associated with a specific user ID. This method queries the database for authorities that match the provided user ID and returns them as a list. It also logs the retrieval of authorities for debugging purposes.
public Task<List<Authorization>> GetUserAuthorities(ObjectId userId)
Parameters
userIdObjectIdThe ID of the user whose authorities are being retrieved.
Returns
- Task<List<Authorization>>
A list of authorities associated with the specified user ID.
InsertInitialLoad()
Inserts initial data into the database for authorities. This method checks if a system user exists and if they do, it ensures that they have the necessary panel authorization. If the system user does not have panel authorization, it creates a new authority for them with the appropriate permissions. This method is typically called during the initial setup of the application to ensure that essential data is present in the database.
public override sealed Task InsertInitialLoad()
Returns
- Task
A task representing the asynchronous operation.