Implement API to Assign Bucket to Employees #76

Merged
ashutosh.nehete merged 1 commits from Ashutosh_Task#387_Assign_Bucket into Feature_Directory 2025-05-27 11:09:51 +00:00
Collaborator

Tenant & Employee Identification

  • Retrieves:
    • tenantId via _userHelper.GetTenantId()
    • Currently logged-in employee via _userHelper.GetCurrentEmployeeAsync()

Initial Validation

  • Checks:
    • If assignBuckets is not null
    • If bucketId is not empty
  • If invalid, returns 400 Bad Request

Permission Checking

  • Retrieves all role IDs assigned to the logged-in employee.
  • Retrieves feature permission IDs from those roles.
  • Fetches the bucket from the DB by bucketId and tenantId.
    • If not found, returns 404 Not Found

Authorization Check

  • Validates if the employee has access to the bucket based on roles:
    • Directory Admin: Has access to all buckets
    • Directory Manager: Has access if already mapped to the bucket
    • Directory User: Has access only if they created the bucket
  • If no access, returns 401 Unauthorized

Process Assignments

  • Retrieves a list of active employees for the tenant.
  • Initializes counters:
    • assignedEmployee for tracking how many were assigned
    • removededEmployee for tracking how many were removed
  • Iterates over assignBuckets:
    • If IsActive is true:
      • Adds a new EmployeeBucketMapping
      • Increments assignedEmployee
    • If IsActive is false:
      • Finds the existing mapping and removes it
      • Increments removededEmployee

Audit Logging

  • Adds a DirectoryUpdateLog entry for the update.

Save and Prepare Response

  • Saves changes using SaveChangesAsync
  • Converts the updated bucket into AssignBucketVM
  • Loads and sets EmployeeIds currently assigned to the bucket
  • Logs:
    • Assignments (Info log)
    • Removals (Error log, though should ideally also be Info)
  • Returns 200 OK with the updated bucket view model.
**Tenant & Employee Identification** - Retrieves: - tenantId via _userHelper.GetTenantId() - Currently logged-in employee via _userHelper.GetCurrentEmployeeAsync() **Initial Validation** - Checks: - If assignBuckets is not null - If bucketId is not empty - If invalid, returns 400 Bad Request **Permission Checking** - Retrieves all role IDs assigned to the logged-in employee. - Retrieves feature permission IDs from those roles. - Fetches the bucket from the DB by bucketId and tenantId. - If not found, returns 404 Not Found **Authorization Check** - Validates if the employee has access to the bucket based on roles: - Directory Admin: Has access to all buckets - Directory Manager: Has access if already mapped to the bucket - Directory User: Has access only if they created the bucket - If no access, returns 401 Unauthorized **Process Assignments** - Retrieves a list of active employees for the tenant. - Initializes counters: - assignedEmployee for tracking how many were assigned - removededEmployee for tracking how many were removed - Iterates over assignBuckets: - If IsActive is true: - Adds a new EmployeeBucketMapping - Increments assignedEmployee - If IsActive is false: - Finds the existing mapping and removes it - Increments removededEmployee **Audit Logging** - Adds a DirectoryUpdateLog entry for the update. **Save and Prepare Response** - Saves changes using SaveChangesAsync - Converts the updated bucket into AssignBucketVM - Loads and sets EmployeeIds currently assigned to the bucket - Logs: - Assignments (Info log) - Removals (Error log, though should ideally also be Info) - Returns 200 OK with the updated bucket view model.
ashutosh.nehete added 1 commit 2025-05-27 11:09:30 +00:00
ashutosh.nehete merged commit 6036415ef4 into Feature_Directory 2025-05-27 11:09:51 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: admin/marco.pms.api#76
No description provided.