diff --git a/server/app/admin/users_admin.rb b/server/app/admin/users_admin.rb index dd9e5b8e3..45b179f14 100644 --- a/server/app/admin/users_admin.rb +++ b/server/app/admin/users_admin.rb @@ -7,6 +7,13 @@ item :users, icon: "fa fa-user" end + scopes do + User.roles.keys.each do |role| + scope role.capitalize.pluralize, -> { User.where(role: role) } + end + scope "Admins and Editors", -> { User.where(role: ['admin', 'editor']) } + end + search do |q| q ? collection.where("username ILIKE ? OR name ILIKE ?", "%#{q}%", "%#{q}%") : collection end diff --git a/server/app/graphql/types/browse_tables/browse_user_type.rb b/server/app/graphql/types/browse_tables/browse_user_type.rb index 5afe45824..645c127ad 100644 --- a/server/app/graphql/types/browse_tables/browse_user_type.rb +++ b/server/app/graphql/types/browse_tables/browse_user_type.rb @@ -2,7 +2,6 @@ module Types::BrowseTables class BrowseUserType < Types::Entities::UserType connection_type_class(Types::Connections::BrowseTableConnection) - @@role_mapping = User.roles.invert @@area_mapping = User.area_of_expertises.invert field :revision_count, Int, null: false @@ -12,10 +11,6 @@ def area_of_expertise @@area_mapping[object.area_of_expertise] end - def role - @@role_mapping[object.role] - end - def organizations Loaders::AssociationLoader.for(MaterializedViews::UserBrowseTableRow, :affiliations).load(object).then do |affil| affil.map do |a| diff --git a/server/app/models/materialized_views/user_browse_table_row.rb b/server/app/models/materialized_views/user_browse_table_row.rb index 06ed321f3..de3da68fa 100644 --- a/server/app/models/materialized_views/user_browse_table_row.rb +++ b/server/app/models/materialized_views/user_browse_table_row.rb @@ -1,4 +1,6 @@ class MaterializedViews::UserBrowseTableRow < MaterializedViews::MaterializedView has_many :affiliations, primary_key: :id, foreign_key: :user_id has_many :organizations, through: :affiliations + + enum role: ['curator', 'editor', 'admin'] end