Renamed 'group_user_role', fixed public project migration [SCI-6234] (#3642)

* Renamed 'group_user_role', fixed public project migration [SCI-6234]

* Moved public project update inside loop [SCI-6234]
This commit is contained in:
artoscinote 2021-11-10 09:52:37 +01:00 committed by GitHub
parent dfa79c6996
commit 0eacb91bed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 33 additions and 30 deletions

View file

@ -335,7 +335,7 @@ class ProjectsController < ApplicationController
.permit(
:name, :team_id, :visibility,
:archived, :project_folder_id,
:group_user_role_id
:default_public_user_role_id
)
end

View file

@ -13,7 +13,7 @@ module UserAssignments
UserAssignment.create!(
user: user,
assignable: project,
user_role: project.group_user_role,
user_role: project.default_public_user_role,
assigned_by: @assigned_by,
assigned: :automatically
)
@ -21,7 +21,7 @@ module UserAssignments
UserAssignments::PropagateAssignmentJob.perform_later(
project,
user,
project.group_user_role,
project.default_public_user_role,
@assigned_by
)
end

View file

@ -37,8 +37,8 @@ class Project < ApplicationRecord
foreign_key: 'restored_by_id',
class_name: 'User',
optional: true
belongs_to :group_user_role,
foreign_key: 'group_user_role_id',
belongs_to :default_public_user_role,
foreign_key: 'default_public_user_role_id',
class_name: 'UserRole',
optional: true
belongs_to :team, inverse_of: :projects, touch: true
@ -327,11 +327,11 @@ class Project < ApplicationRecord
end
def bulk_assignment?
visible? && group_user_role.present?
visible? && default_public_user_role.present?
end
def selected_user_role_validation
errors.add(:group_user_role_id, :inclusion) unless group_user_role.in?(UserRole.all)
errors.add(:default_public_user_role_id, :inclusion) unless default_public_user_role.in?(UserRole.all)
end
def sync_project_assignments

View file

@ -25,8 +25,8 @@
</div>
<div class="row <%= f.object.hidden? ? 'hidden' : '' %>" id="role_select_wrapper">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<%= f.select :group_user_role_id,
options_for_select(user_roles_collection, selected: f.object.group_user_role_id),
<%= f.select :default_public_user_role_id,
options_for_select(user_roles_collection, selected: f.object.default_public_user_role_id),
{ label: t('user_assignment.select_default_user_role') },
class: 'form-control selectpicker'%>
</div>

View file

@ -25,7 +25,7 @@
</div>
<div class="row hidden" id="role_select_wrapper">
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<%= f.select :group_user_role_id,
<%= f.select :default_public_user_role_id,
options_for_select(user_roles_collection, UserRole.find_by(name: I18n.t('user_roles.predefined.viewer')).id),
class: 'form-control selectpicker'%>
</div>

View file

@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddDefaultPublicUserRoleToProjects < ActiveRecord::Migration[6.1]
def change
add_reference :projects, :default_public_user_role, foreign_key: { to_table: :user_roles }
end
end

View file

@ -45,6 +45,8 @@ class MigrateToNewUserRoles < ActiveRecord::Migration[6.1]
Team.preload(:users).find_each do |team|
public_projects = team.projects.where(visibility: 'visible')
public_projects.preload(:team, experiments: :my_modules).find_each(batch_size: 10) do |project|
project.update!(default_public_user_role: viewer_role)
user_assignments = []
already_assigned_user_ids = project.user_assignments.pluck(:user_id)
unassigned_users = team.users.reject { |u| already_assigned_user_ids.include?(u.id) }

View file

@ -1,5 +0,0 @@
class AddGroupUserRoleToProjects < ActiveRecord::Migration[6.1]
def change
add_reference :projects, :group_user_role, foreign_key: { to_table: :user_roles }
end
end

View file

@ -1187,7 +1187,7 @@ CREATE TABLE public.projects (
template boolean,
demo boolean DEFAULT false NOT NULL,
project_folder_id bigint,
group_user_role_id bigint
default_public_user_role_id bigint
);
@ -2587,9 +2587,9 @@ CREATE TABLE public.user_assignments (
user_id bigint NOT NULL,
user_role_id bigint NOT NULL,
assigned_by_id bigint,
assigned integer DEFAULT 0 NOT NULL,
created_at timestamp(6) without time zone NOT NULL,
updated_at timestamp(6) without time zone NOT NULL,
assigned integer DEFAULT 0 NOT NULL
updated_at timestamp(6) without time zone NOT NULL
);
@ -4978,10 +4978,10 @@ CREATE INDEX index_projects_on_created_by_id ON public.projects USING btree (cre
--
-- Name: index_projects_on_group_user_role_id; Type: INDEX; Schema: public; Owner: -
-- Name: index_projects_on_default_public_user_role_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_projects_on_group_user_role_id ON public.projects USING btree (group_user_role_id);
CREATE INDEX index_projects_on_default_public_user_role_id ON public.projects USING btree (default_public_user_role_id);
--
@ -6651,14 +6651,6 @@ ALTER TABLE ONLY public.repository_rows
ADD CONSTRAINT fk_rails_7186e2b731 FOREIGN KEY (last_modified_by_id) REFERENCES public.users(id);
--
-- Name: projects fk_rails_73110d691c; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.projects
ADD CONSTRAINT fk_rails_73110d691c FOREIGN KEY (group_user_role_id) REFERENCES public.user_roles(id);
--
-- Name: oauth_access_tokens fk_rails_732cb83ab7; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -6955,6 +6947,14 @@ ALTER TABLE ONLY public.repository_status_items
ADD CONSTRAINT fk_rails_9acc03f846 FOREIGN KEY (created_by_id) REFERENCES public.users(id);
--
-- Name: projects fk_rails_9b9763cd55; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.projects
ADD CONSTRAINT fk_rails_9b9763cd55 FOREIGN KEY (default_public_user_role_id) REFERENCES public.user_roles(id);
--
-- Name: results fk_rails_9be849c454; Type: FK CONSTRAINT; Schema: public; Owner: -
--
@ -7685,6 +7685,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20210128105458'),
('20210202214508'),
('20210217114042'),
('20210222123822'),
('20210222123823'),
('20210312185911'),
('20210325152257'),
@ -7693,10 +7694,8 @@ INSERT INTO "schema_migrations" (version) VALUES
('20210506125657'),
('20210531114633'),
('20210603152345'),
('20210612070220'),
('20210616071836'),
('20210622101238'),
('20210627095718'),
('20210715125349'),
('20210716124649'),
('20210720112050'),