Skip to content

Commit a0cd46a

Browse files
committed
MBS-10572: Do not remove personas in case of context data deletion
1 parent daefdeb commit a0cd46a

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

classes/privacy/provider.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,8 @@ public static function delete_data_for_users(approved_userlist $userlist): void
295295
foreach ($userpersonas as $persona) {
296296
// Delete all selections of this persona first.
297297
$DB->delete_records('block_ai_chat_personas_selected', ['personasid' => $persona->id]);
298-
// Then delete the persona itself.
299-
$DB->delete_records('block_ai_chat_personas', ['id' => $persona->id]);
298+
// Associated persona records must not be deleted, because they belong to the user and not the aichat instance
299+
// context. They could even still be used by different aichat instances.
300300
}
301301
}
302302
}
@@ -330,10 +330,10 @@ public static function delete_data_for_all_users_in_context(\context $context):
330330
$selections = $DB->get_records('block_ai_chat_personas_selected', ['contextid' => $context->id]);
331331

332332
foreach ($selections as $selection) {
333-
// Delete the persona.
334-
$DB->delete_records('block_ai_chat_personas', ['id' => $selection->personasid]);
335333
// Delete the selection.
336334
$DB->delete_records('block_ai_chat_personas_selected', ['id' => $selection->id]);
335+
// Associated persona records must not be deleted, because they belong to the user and not the aichat instance
336+
// context. They could even still be used by different aichat instances.
337337
}
338338
}
339339

tests/privacy/provider_test.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,11 @@ public function test_delete_data_for_all_users_in_context(): void {
413413
$this->assertEquals(data_wiper::ANONYMIZE_STRING, $dbrecord2->prompttext);
414414
$this->assertEquals(data_wiper::ANONYMIZE_STRING, $dbrecord2->promptcompletion);
415415

416-
// Verify persona1 and its selection in the deleted context are gone.
417-
$this->assertFalse($DB->record_exists('block_ai_chat_personas', ['id' => $persona1id]));
416+
// Verify the selection of persona1 in the deleted context is gone.
418417
$this->assertFalse($DB->record_exists('block_ai_chat_personas_selected', ['id' => $selection1id]));
418+
// Verify the persona still exists, because it is not data in this context but belongs to the user and could still
419+
// be used in different contexts.
420+
$this->assertTrue($DB->record_exists('block_ai_chat_personas', ['id' => $persona1id]));
419421

420422
// Verify persona2 and its selection in other context are still there.
421423
$this->assertTrue($DB->record_exists('block_ai_chat_personas', ['id' => $persona2id]));
@@ -530,12 +532,14 @@ public function test_delete_data_for_users(): void {
530532
$this->assertEquals('User 3 prompt', $dbrecord3->prompttext);
531533
$this->assertEquals('User 3 completion', $dbrecord3->promptcompletion);
532534

533-
// Verify user1's persona and its selection are deleted.
534-
$this->assertFalse($DB->record_exists('block_ai_chat_personas', ['id' => $persona1id]));
535+
// Verify the selection of user1's persona is deleted.
535536
$this->assertFalse($DB->record_exists('block_ai_chat_personas_selected', ['id' => $selection1id]));
537+
// Verify the persona still exists, because it is not data in this context but belongs to the user and could still
538+
// be used in different contexts.
539+
$this->assertTrue($DB->record_exists('block_ai_chat_personas', ['id' => $persona1id]));
536540

537-
// Verify user2's persona is deleted.
538-
$this->assertFalse($DB->record_exists('block_ai_chat_personas', ['id' => $persona2id]));
541+
// Verify user2's persona also still exists.
542+
$this->assertTrue($DB->record_exists('block_ai_chat_personas', ['id' => $persona2id]));
539543

540544
// Verify user3's persona is not affected.
541545
$this->assertTrue($DB->record_exists('block_ai_chat_personas', ['id' => $persona3id]));

0 commit comments

Comments
 (0)