Skip to content

Commit

Permalink
fix: reset invite codes if study gets published as public
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimozkn committed Jul 22, 2024
1 parent c42a6e5 commit 10da302
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions designer_v2/lib/features/study/study_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:studyu_designer_v2/domain/study.dart';
import 'package:studyu_designer_v2/features/study/study_base_controller.dart';
import 'package:studyu_designer_v2/features/study/study_controller_state.dart';
import 'package:studyu_designer_v2/repositories/auth_repository.dart';
import 'package:studyu_designer_v2/repositories/invite_code_repository.dart';
import 'package:studyu_designer_v2/repositories/model_repository_events.dart';
import 'package:studyu_designer_v2/repositories/study_repository.dart';
import 'package:studyu_designer_v2/routing/router.dart';
Expand Down Expand Up @@ -56,6 +57,18 @@ class StudyController extends _$StudyController {
Future publishStudy({bool toRegistry = false}) {
final study = state.study.value!;
study.registryPublished = toRegistry;

// Remove all invites if study is open
if (study.participation == Participation.open && study.invites != null) {
final codeRepository =
ref.watch(inviteCodeRepositoryProvider(study.id)).delegate;

// Create a copy of the invites list to avoid errors during deletion as the original study.invites list is modified within the loop
for (final StudyInvite invite in List.from(study.invites!)) {
codeRepository.delete(invite);
}
}

return state.studyRepository.launch(study);
}

Expand Down

0 comments on commit 10da302

Please sign in to comment.