From: Tom Hughes Date: Sun, 29 Oct 2023 15:34:12 +0000 (+0000) Subject: Add importer role that can be associated with higher rate limits X-Git-Tag: live~957^2~4 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/c6bb4a5f4eadc46bac599cd6a5174b199c1b6026 Add importer role that can be associated with higher rate limits --- diff --git a/app/assets/images/roles/blank_importer.png b/app/assets/images/roles/blank_importer.png new file mode 100644 index 000000000..1eb81180e Binary files /dev/null and b/app/assets/images/roles/blank_importer.png differ diff --git a/app/assets/images/roles/blank_importer.svg b/app/assets/images/roles/blank_importer.svg new file mode 100644 index 000000000..d4e53ec72 --- /dev/null +++ b/app/assets/images/roles/blank_importer.svg @@ -0,0 +1,65 @@ + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/app/assets/images/roles/importer.png b/app/assets/images/roles/importer.png new file mode 100644 index 000000000..671172947 Binary files /dev/null and b/app/assets/images/roles/importer.png differ diff --git a/app/assets/images/roles/importer.svg b/app/assets/images/roles/importer.svg new file mode 100644 index 000000000..449787ad8 --- /dev/null +++ b/app/assets/images/roles/importer.svg @@ -0,0 +1,71 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + diff --git a/app/models/user.rb b/app/models/user.rb index f804f4666..3d74b3933 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -290,6 +290,12 @@ class User < ApplicationRecord role? "administrator" end + ## + # returns true if the user has the importer role, false otherwise + def importer? + role? "importer" + end + ## # returns true if the user has the requested role def role?(role) diff --git a/app/models/user_role.rb b/app/models/user_role.rb index a081361a7..332848e42 100644 --- a/app/models/user_role.rb +++ b/app/models/user_role.rb @@ -23,7 +23,7 @@ class UserRole < ApplicationRecord belongs_to :user belongs_to :granter, :class_name => "User" - ALL_ROLES = %w[administrator moderator].freeze + ALL_ROLES = %w[administrator moderator importer].freeze validates :role, :inclusion => ALL_ROLES, :uniqueness => { :scope => :user_id } end diff --git a/config/initializers/migrate.rb b/config/initializers/migrate.rb index 0667e3346..43dd446a3 100644 --- a/config/initializers/migrate.rb +++ b/config/initializers/migrate.rb @@ -51,6 +51,10 @@ if defined?(ActiveRecord::ConnectionAdapters::AbstractAdapter) execute "DROP TYPE #{enumeration_name}" end + def add_enumeration_value(enumeration_name, value) + execute "ALTER TYPE #{enumeration_name} ADD VALUE '#{value}'" + end + def rename_enumeration(old_name, new_name) old_name = quote_table_name(old_name) new_name = quote_table_name(new_name) diff --git a/config/locales/en.yml b/config/locales/en.yml index 158f19ac4..ce84600d2 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -2739,12 +2739,15 @@ en: role: administrator: "This user is an administrator" moderator: "This user is a moderator" + importer: "This user is a importer" grant: administrator: "Grant administrator access" moderator: "Grant moderator access" + importer: "Grant importer access" revoke: administrator: "Revoke administrator access" moderator: "Revoke moderator access" + importer: "Revoke importer access" block_history: "Active Blocks" moderator_history: "Blocks Given" comments: "Comments" diff --git a/db/migrate/20231029151516_add_importer_role.rb b/db/migrate/20231029151516_add_importer_role.rb new file mode 100644 index 000000000..f3fcdb85f --- /dev/null +++ b/db/migrate/20231029151516_add_importer_role.rb @@ -0,0 +1,9 @@ +class AddImporterRole < ActiveRecord::Migration[7.1] + def up + add_enumeration_value :user_role_enum, "importer" + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/structure.sql b/db/structure.sql index 17f269666..f7f329326 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -91,7 +91,8 @@ CREATE TYPE public.nwr_enum AS ENUM ( CREATE TYPE public.user_role_enum AS ENUM ( 'administrator', - 'moderator' + 'moderator', + 'importer' ); @@ -3437,6 +3438,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('23'), ('22'), ('21'), +('20231029151516'), ('20231010194809'), ('20231007141103'), ('20230830115220'), diff --git a/test/factories/user.rb b/test/factories/user.rb index cdc606cf1..166461637 100644 --- a/test/factories/user.rb +++ b/test/factories/user.rb @@ -47,6 +47,12 @@ FactoryBot.define do end end + factory :importer_user do + after(:create) do |user, _evaluator| + create(:user_role, :role => "importer", :user => user) + end + end + factory :moderator_user do after(:create) do |user, _evaluator| create(:user_role, :role => "moderator", :user => user) diff --git a/test/helpers/user_roles_helper_test.rb b/test/helpers/user_roles_helper_test.rb index 7708d5115..ba51dd14f 100644 --- a/test/helpers/user_roles_helper_test.rb +++ b/test/helpers/user_roles_helper_test.rb @@ -9,17 +9,27 @@ class UserRolesHelperTest < ActionView::TestCase icon = role_icon(current_user, "moderator") assert_dom_equal "", icon + icon = role_icon(current_user, "importer") + assert_dom_equal "", icon + icon = role_icon(create(:moderator_user), "moderator") expected = <<~HTML.delete("\n") This user is a moderator HTML assert_dom_equal expected, icon + + icon = role_icon(create(:importer_user), "importer") + expected = <<~HTML.delete("\n") + This user is a importer + HTML + assert_dom_equal expected, icon end def test_role_icon_administrator self.current_user = create(:administrator_user) user = create(:user) + icon = role_icon(user, "moderator") expected = <<~HTML.delete("\n") @@ -28,7 +38,16 @@ class UserRolesHelperTest < ActionView::TestCase HTML assert_dom_equal expected, icon + icon = role_icon(user, "importer") + expected = <<~HTML.delete("\n") + + Grant importer access + + HTML + assert_dom_equal expected, icon + moderator_user = create(:moderator_user) + icon = role_icon(moderator_user, "moderator") expected = <<~HTML.delete("\n") @@ -36,6 +55,32 @@ class UserRolesHelperTest < ActionView::TestCase HTML assert_dom_equal expected, icon + + icon = role_icon(user, "importer") + expected = <<~HTML.delete("\n") + + Grant importer access + + HTML + assert_dom_equal expected, icon + + importer_user = create(:importer_user) + + icon = role_icon(user, "moderator") + expected = <<~HTML.delete("\n") + + Grant moderator access + + HTML + assert_dom_equal expected, icon + + icon = role_icon(importer_user, "importer") + expected = <<~HTML.delete("\n") + + Revoke importer access + + HTML + assert_dom_equal expected, icon end def test_role_icons_normal @@ -50,10 +95,17 @@ class UserRolesHelperTest < ActionView::TestCase HTML assert_dom_equal expected, icons + icons = role_icons(create(:importer_user)) + expected = <<~HTML.delete("\n") + This user is a importer + HTML + assert_dom_equal expected, icons + icons = role_icons(create(:super_user)) expected = <<~HTML.delete("\n") This user is an administrator This user is a moderator + This user is a importer HTML assert_dom_equal expected, icons end @@ -70,6 +122,9 @@ class UserRolesHelperTest < ActionView::TestCase Grant moderator access + + Grant importer access + HTML assert_dom_equal expected, icons @@ -82,6 +137,24 @@ class UserRolesHelperTest < ActionView::TestCase Revoke moderator access + + Grant importer access + + HTML + assert_dom_equal expected, icons + + importer_user = create(:importer_user) + icons = role_icons(importer_user) + expected = <<~HTML.delete("\n") + + Grant administrator access + + + Grant moderator access + + + Revoke importer access + HTML assert_dom_equal expected, icons @@ -94,6 +167,9 @@ class UserRolesHelperTest < ActionView::TestCase Revoke moderator access + + Revoke importer access + HTML assert_dom_equal expected, icons end