diff --git a/config/initializers/extends/permission_extends.rb b/config/initializers/extends/permission_extends.rb index 09e33bcbc..2c8f35104 100644 --- a/config/initializers/extends/permission_extends.rb +++ b/config/initializers/extends/permission_extends.rb @@ -18,6 +18,7 @@ module PermissionExtends module ProtocolPermissions %w( READ + READ_ARCHIVED MANAGE USERS_MANAGE ).each { |permission| const_set(permission, "protocol_#{permission.underscore}") } @@ -137,6 +138,7 @@ module PermissionExtends TeamPermissions::LABEL_TEMPLATES_READ, TeamPermissions::LABEL_TEMPLATES_MANAGE, ProtocolPermissions::READ, + ProtocolPermissions::READ_ARCHIVED, ProtocolPermissions::MANAGE, ReportPermissions::READ, ReportPermissions::MANAGE, @@ -228,6 +230,7 @@ module PermissionExtends VIEWER_PERMISSIONS = [ TeamPermissions::LABEL_TEMPLATES_READ, ProtocolPermissions::READ, + ProtocolPermissions::READ_ARCHIVED, ReportPermissions::READ, ProjectPermissions::READ, ProjectPermissions::READ_ARCHIVED, @@ -242,7 +245,9 @@ module PermissionExtends MyModulePermissions::READ, MyModulePermissions::USERS_READ, MyModulePermissions::READ_ARCHIVED, - MyModulePermissions::ACTIVITIES_READ + MyModulePermissions::ACTIVITIES_READ, + RepositoryPermissions::READ, + RepositoryPermissions::READ_ARCHIVED ] end end diff --git a/db/migrate/20221222123021_add_missing_repository_and_protocol_permissions.rb b/db/migrate/20221222123021_add_missing_repository_and_protocol_permissions.rb new file mode 100644 index 000000000..51799a79f --- /dev/null +++ b/db/migrate/20221222123021_add_missing_repository_and_protocol_permissions.rb @@ -0,0 +1,39 @@ +# frozen_string_literal: true + +class AddMissingRepositoryAndProtocolPermissions < ActiveRecord::Migration[6.1] + OWNER_PERMISSIONS = [ProtocolPermissions::READ_ARCHIVED].freeze + NORMAL_USER_PERMISSIONS = [ProtocolPermissions::READ_ARCHIVED].freeze + VIEWER_PERMISSIONS = [ProtocolPermissions::READ_ARCHIVED, + RepositoryPermissions::READ, + RepositoryPermissions::READ_ARCHIVED].freeze + + def change + reversible do |dir| + dir.up do + owner_role = UserRole.find_predefined_owner_role + normal_user_role = UserRole.find_predefined_normal_user_role + viewer_role = UserRole.find_predefined_viewer_role + + owner_role.permissions = owner_role.permissions | OWNER_PERMISSIONS + owner_role.save(validate: false) + normal_user_role.permissions = normal_user_role.permissions | NORMAL_USER_PERMISSIONS + normal_user_role.save(validate: false) + viewer_role.permissions = viewer_role.permissions | VIEWER_PERMISSIONS + viewer_role.save(validate: false) + end + + dir.down do + owner_role = UserRole.find_predefined_owner_role + normal_user_role = UserRole.find_predefined_normal_user_role + viewer_role = UserRole.find_predefined_viewer_role + + owner_role.permissions = owner_role.permissions - OWNER_PERMISSIONS + owner_role.save(validate: false) + normal_user_role.permissions = normal_user_role.permissions - NORMAL_USER_PERMISSIONS + normal_user_role.save(validate: false) + viewer_role.permissions = viewer_role.permissions - VIEWER_PERMISSIONS + viewer_role.save(validate: false) + end + end + end +end diff --git a/db/structure.sql b/db/structure.sql index 8587d0f11..c58030d80 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -8594,6 +8594,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220818094636'), ('20220914124900'), ('20221007113010'), -('20221028085051'); +('20221028085051'), +('20221222123021');