Skip to content
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

BC-7466 - Switch SHD administration of schools (students) to new deletion routines #5478

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

uidp
Copy link
Contributor

@uidp uidp commented Jan 31, 2025

Description

Switch SHD administration of schools (students) to new deletion routines

Links to Tickets or other pull requests

BC-7466
hpi-schul-cloud/superhero-dashboard#278

Approval for review

  • DEV: If api was changed - generate-client:server was executed in vue frontend and changes were tested and put in a PR with the same branch name.
  • QA: In addition to review, the code has been manually tested (if manual testing is possible)
  • All points were discussed with the ticket creator, support-team or product owner. The code upholds all quality guidelines from the PR-template.

@uidp uidp added the WIP This feature branch is in progress, do not merge into master. label Jan 31, 2025
const validUserIds: EntityId[] = [];
const invalidUserIds: EntityId[] = [];

for (const userId of targetRefIds) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could be rewritten using a map, and then Promise.all

const invalidUserIds: EntityId[] = [];

for (const userId of targetRefIds) {
const userExists = await this.userRepo.findByIdOrNull(userId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering why is even possible...but we should not be able to access user repo directly. It should be accessed via a service which user module exports.

public async createDeletionBatch(
params: CreateDeletionBatchParams,
validUserIds: EntityId[],
invalidUserIds: EntityId[] | undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
invalidUserIds: EntityId[] | undefined
invalidUserIds?: EntityId[]

}

// TODO implement as join on deletionbatches.targetRefIds to avoid N+1
public async getUsersByRoles(userIds: EntityId[]): Promise<UsersByRole[]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be private

Comment on lines 117 to 120
for (const targetRefId of batch.targetRefIds) {
const deleteNow = new Date(Date.now());
await this.deletionRequestService.createDeletionRequest(targetRefId, DomainName.USER, deleteNow);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (const targetRefId of batch.targetRefIds) {
const deleteNow = new Date(Date.now());
await this.deletionRequestService.createDeletionRequest(targetRefId, DomainName.USER, deleteNow);
}
const deleteNow = new Date();
const deletionRequests = batch.targetRefIds.map(targetRefId => this.deletionRequestService.createDeletionRequest(targetRefId, DomainName.USER, deleteNow)
);
await Promise.all(deletionRequests);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on a second thought, this Promise.all might not be a good idea
Because it can be that we try to create a deletion request for a user id which already exists, in which case we should get an exception. And promise.all would stop

}

public async createDeletionRequestForBatch(batchId: EntityId): Promise<DeletionBatchSummary> {
const deletionBatch = await this.deletionBatchRepo.findById(batchId);
Copy link
Contributor

@virgilchiriac virgilchiriac Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should not access repo directly in the uc, but via service...
a simple wrapper function in service should do

],
exports: [DeletionRequestService, DeletionLogService],
exports: [DeletionRequestService, DeletionLogService, DeletionBatchService, DeletionBatchRepo],
Copy link
Contributor

@virgilchiriac virgilchiriac Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repo does not belong here... is needed because is injected in the uc, but there we should also not access the repo directly, but instead access the service

constructor(
private readonly deletionBatchService: DeletionBatchService,
private readonly deletionBatchRepo: DeletionBatchRepo,
private readonly userRepo: UserRepo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repo should not be accessed directly in uc

delete endpoint
store all info
response to contain skipped and invalid ids
batch status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP This feature branch is in progress, do not merge into master.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants