diff options
author | Francisco Javier López <fjlopez@gitlab.com> | 2018-04-06 18:23:49 +0300 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-04-06 18:23:49 +0300 |
commit | f20912df033d07c46b0989012244d96d0a12b66d (patch) | |
tree | 6207b8face17f9b7166ba1a5e047032e3927e53e /app/services/projects/move_notification_settings_service.rb | |
parent | 44f4a674e2a87d104f700265d835aba000c589f0 (diff) |
Extend API for importing a project export with overwrite support
Diffstat (limited to 'app/services/projects/move_notification_settings_service.rb')
-rw-r--r-- | app/services/projects/move_notification_settings_service.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/services/projects/move_notification_settings_service.rb b/app/services/projects/move_notification_settings_service.rb new file mode 100644 index 00000000000..f7be461a5da --- /dev/null +++ b/app/services/projects/move_notification_settings_service.rb @@ -0,0 +1,38 @@ +module Projects + class MoveNotificationSettingsService < BaseMoveRelationsService + def execute(source_project, remove_remaining_elements: true) + return unless super + + Project.transaction(requires_new: true) do + move_notification_settings + remove_remaining_notification_settings if remove_remaining_elements + + success + end + end + + private + + def move_notification_settings + prepare_relation(non_existent_notifications) + .update_all(source_id: @project.id) + end + + # Remove remaining notification settings from source_project + def remove_remaining_notification_settings + source_project.notification_settings.destroy_all + end + + # Get users of current notification_settings + def users_in_target_project + @project.notification_settings.select(:user_id) + end + + # Look for notification_settings in source_project that are not in the target project + def non_existent_notifications + source_project.notification_settings + .select(:id) + .where.not(user_id: users_in_target_project) + end + end +end |