diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb
index c37a02dfa..7f70e2dac 100644
--- a/app/controllers/projects_controller.rb
+++ b/app/controllers/projects_controller.rb
@@ -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
diff --git a/app/jobs/user_assignments/group_assignment_job.rb b/app/jobs/user_assignments/group_assignment_job.rb
index 6b6aa613c..2e4cd8587 100644
--- a/app/jobs/user_assignments/group_assignment_job.rb
+++ b/app/jobs/user_assignments/group_assignment_job.rb
@@ -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
diff --git a/app/models/project.rb b/app/models/project.rb
index 3b514ce70..d3fa4c9a0 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -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
diff --git a/app/views/projects/index/modals/_edit_project_contents.html.erb b/app/views/projects/index/modals/_edit_project_contents.html.erb
index f184e73be..31c140ecd 100644
--- a/app/views/projects/index/modals/_edit_project_contents.html.erb
+++ b/app/views/projects/index/modals/_edit_project_contents.html.erb
@@ -25,8 +25,8 @@
- <%= 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'%>
diff --git a/app/views/projects/index/modals/_new_project.html.erb b/app/views/projects/index/modals/_new_project.html.erb
index fee45a4c4..81fcf3bfc 100644
--- a/app/views/projects/index/modals/_new_project.html.erb
+++ b/app/views/projects/index/modals/_new_project.html.erb
@@ -25,7 +25,7 @@
- <%= 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'%>
diff --git a/db/migrate/20210222123822_add_default_public_user_role_to_projects.rb b/db/migrate/20210222123822_add_default_public_user_role_to_projects.rb
new file mode 100644
index 000000000..b2c462c12
--- /dev/null
+++ b/db/migrate/20210222123822_add_default_public_user_role_to_projects.rb
@@ -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
diff --git a/db/migrate/20210222123823_migrate_to_new_user_roles.rb b/db/migrate/20210222123823_migrate_to_new_user_roles.rb
index 47cea1970..bd273a752 100644
--- a/db/migrate/20210222123823_migrate_to_new_user_roles.rb
+++ b/db/migrate/20210222123823_migrate_to_new_user_roles.rb
@@ -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) }
diff --git a/db/migrate/20210627095718_add_group_user_role_to_projects.rb b/db/migrate/20210627095718_add_group_user_role_to_projects.rb
deleted file mode 100644
index eef0ef3ee..000000000
--- a/db/migrate/20210627095718_add_group_user_role_to_projects.rb
+++ /dev/null
@@ -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
diff --git a/db/structure.sql b/db/structure.sql
index c3b320f2a..8319638b6 100644
--- a/db/structure.sql
+++ b/db/structure.sql
@@ -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'),