Ashutosh_Task#269_Delete_Bucket #77

Merged
vikas.nale merged 2 commits from Ashutosh_Task#269_Delete_Bucket into Feature_Directory 2025-05-28 05:45:48 +00:00
Collaborator

1. Get Tenant and Logged-in Employee

  • Retrieves the current tenant ID from _userHelper.GetTenantId().
  • Fetches the currently logged-in employee using _userHelper.GetCurrentEmployeeAsync().

2. Check if the Bucket Exists

  • Looks up the bucket using the provided id and the current tenantId.
  • If the bucket is not found, logs a warning and returns a success response (though ideally this should be a 404 error).

3. Check for Contacts in the Bucket

  • Retrieves any employee-bucket and contact-bucket mappings for the bucket.
  • If there are any contacts assigned to this bucket:
    • Logs an info message.
    • Returns a 400 Bad Request with the message: "This bucket can not be deleted".

4. Authorization Check

  • Fetches the role IDs assigned to the current employee.
  • Gets the permission IDs mapped to those roles.
  • Gets the list of buckets assigned to the employee.
  • Then, based on permissions:
    • If the user has directoryAdmin → grant access.
    • If the user has directoryManager and is assigned to the bucket → grant access.
    • If the user has directoryUser and is the creator of the bucket → grant access.
    • If none of the above match → deny access and return 401 Unauthorized.

5. Perform Deletion

  • If authorized:
    • Removes all EmployeeBucketMapping entries linked to the bucket.
    • Removes the Bucket itself.
    • Logs the deletion in DirectoryUpdateLogs with timestamp and employee ID.
    • Saves changes to the database via SaveChangesAsync().

6. Final Logging and Response

  • Logs a success message about the deletion.
  • Returns a 200 OK success response with an empty object.
**1. Get Tenant and Logged-in Employee** - Retrieves the current tenant ID from _userHelper.GetTenantId(). - Fetches the currently logged-in employee using _userHelper.GetCurrentEmployeeAsync(). **2. Check if the Bucket Exists** - Looks up the bucket using the provided id and the current tenantId. - If the bucket is not found, logs a warning and returns a success response (though ideally this should be a 404 error). **3. Check for Contacts in the Bucket** - Retrieves any employee-bucket and contact-bucket mappings for the bucket. - If there are any contacts assigned to this bucket: - Logs an info message. - Returns a 400 Bad Request with the message: "This bucket can not be deleted". **4. Authorization Check** - Fetches the role IDs assigned to the current employee. - Gets the permission IDs mapped to those roles. - Gets the list of buckets assigned to the employee. - **Then, based on permissions**: - If the user has directoryAdmin → grant access. - If the user has directoryManager and is assigned to the bucket → grant access. - If the user has directoryUser and is the creator of the bucket → grant access. - If none of the above match → deny access and return 401 Unauthorized. **5. Perform Deletion** - If authorized: - Removes all EmployeeBucketMapping entries linked to the bucket. - Removes the Bucket itself. - Logs the deletion in DirectoryUpdateLogs with timestamp and employee ID. - Saves changes to the database via SaveChangesAsync(). **6. Final Logging and Response** - Logs a success message about the deletion. - Returns a 200 OK success response with an empty object.
ashutosh.nehete added 2 commits 2025-05-28 05:22:23 +00:00
vikas.nale merged commit b42b8b726a into Feature_Directory 2025-05-28 05:45:48 +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#77
No description provided.