diff --git a/src/api/lib/tasks/rollout.rake b/src/api/lib/tasks/rollout.rake index c3d4ececfd7..0e90b503e02 100644 --- a/src/api/lib/tasks/rollout.rake +++ b/src/api/lib/tasks/rollout.rake @@ -1,35 +1,29 @@ # rubocop:disable Rails/SkipsModelValidations + +# Follow the recommendations for the rollout in: +# https://github.com/openSUSE/open-build-service/wiki/Feature-Toggles#steps-for-rolling-out + namespace :rollout do desc 'Move all the users to rollout program' task all_on: :environment do User.all_without_nobody - .not_staff .where(in_rollout: false).in_batches.update_all(in_rollout: true) end desc 'Move all the users out of the rollout program' task all_off: :environment do User.all_without_nobody - .not_staff .where(in_rollout: true).in_batches.update_all(in_rollout: false) end desc 'Move the users already in beta to rollout program' task from_beta: :environment do - User.not_staff - .where(in_beta: true, in_rollout: false).in_batches.update_all(in_rollout: true) - end - - desc 'Move the members of groups to rollout program' - task from_groups: :environment do - User.not_staff - .where(in_rollout: false).joins(:groups_users).distinct.in_batches.update_all(in_rollout: true) + User.where(in_beta: true, in_rollout: false).in_batches.update_all(in_rollout: true) end desc 'Move the users with recent activity to rollout program' task recently_logged_users: :environment do User.all_without_nobody - .not_staff .where(in_rollout: false, last_logged_in_at: Time.zone.today.prev_month(3)..Time.zone.today) .in_batches.update_all(in_rollout: true) end @@ -37,11 +31,15 @@ namespace :rollout do desc 'Move the users without recent activity to rollout program' task non_recently_logged_users: :environment do User.all_without_nobody - .not_staff .where.not(in_rollout: true).where.not(last_logged_in_at: Time.zone.today.prev_month(3)..Time.zone.today) .in_batches.update_all(in_rollout: true) end + desc 'Move the members of groups to rollout program' + task from_groups: :environment do + User.where(in_rollout: false).joins(:groups_users).distinct.in_batches.update_all(in_rollout: true) + end + desc 'Move Staff users to rollout program' task staff_on: :environment do User.staff @@ -53,5 +51,17 @@ namespace :rollout do User.staff .where(in_rollout: true).in_batches.update_all(in_rollout: false) end + + desc 'Move the anonymous user to the rollout program' + task anonymous_on: :environment do + user = User.find_by(login: '_nobody_', in_rollout: false) + user&.update_column(:in_rollout, true) + end + + desc 'Move the anonymous user out of the rollout program' + task anonymous_off: :environment do + user = User.find_by(login: '_nobody_', in_rollout: true) + user&.update_column(:in_rollout, false) + end end # rubocop:enable Rails/SkipsModelValidations diff --git a/src/api/spec/lib/tasks/rollout_spec.rb b/src/api/spec/lib/tasks/rollout_spec.rb index a1bd9504af0..466bebc7b35 100644 --- a/src/api/spec/lib/tasks/rollout_spec.rb +++ b/src/api/spec/lib/tasks/rollout_spec.rb @@ -52,17 +52,6 @@ it { expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(3).to(4) } end - describe 'from_groups' do - let(:task) { 'rollout:from_groups' } - let(:users) { User.joins(:groups_users).distinct } - - it 'will move all the users from groups to Rollout Program' do - expect { rake_task.invoke }.to change(users.where(in_rollout: true), :count).from(1).to(2) - end - - it { expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(3).to(4) } - end - describe 'recently_logged_users' do let(:task) { 'rollout:recently_logged_users' } let(:users) { User.where(last_logged_in_at: Time.zone.today.prev_month(3)..Time.zone.today) } @@ -85,6 +74,17 @@ it { expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(3).to(4) } end + describe 'from_groups' do + let(:task) { 'rollout:from_groups' } + let(:users) { User.joins(:groups_users).distinct } + + it 'will move all the users from groups to Rollout Program' do + expect { rake_task.invoke }.to change(users.where(in_rollout: true), :count).from(1).to(2) + end + + it { expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(3).to(4) } + end + context 'with Staff users' do let!(:staff_user_1) { create(:staff_user, in_rollout: false) } let!(:staff_user_2) { create(:staff_user, in_rollout: false) } @@ -111,4 +111,24 @@ it { expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(4).to(3) } end end + + context 'with anonymous user' do + describe 'anonymous_on' do + let!(:anonymous_user) { create(:user_nobody, in_rollout: false) } + let(:task) { 'rollout:anonymous_on' } + + it 'will move the anonymous user to Rollout Program' do + expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(3).to(4) + end + end + + describe 'anonymous_off' do + let!(:anonymous_user) { create(:user_nobody, in_rollout: true) } + let(:task) { 'rollout:anonymous_off' } + + it 'will move anonymous user out of Rollout Program' do + expect { rake_task.invoke }.to change(all_in_rollout_users, :count).from(4).to(3) + end + end + end end