Skip to content

Commit

Permalink
Remove admin field on users because we're now using rolify
Browse files Browse the repository at this point in the history
  • Loading branch information
mlandauer committed Sep 10, 2024
1 parent 5451f47 commit 92c2729
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 14 deletions.
4 changes: 0 additions & 4 deletions app/dashboards/user_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class UserDashboard < Administrate::BaseDashboard
ATTRIBUTE_TYPES = T.let({
id: Field::Number,
activated_at: Field::DateTime,
admin: YesNoBooleanField,
alerts: Field::HasMany,
api_keys: Field::HasMany,
comments: Field::HasMany,
Expand Down Expand Up @@ -56,7 +55,6 @@ class UserDashboard < Administrate::BaseDashboard
email
name
organisation
admin
roles
].freeze, T::Array[Symbol])

Expand All @@ -66,7 +64,6 @@ class UserDashboard < Administrate::BaseDashboard
email
name
organisation
admin
roles
unconfirmed_email
alerts
Expand Down Expand Up @@ -95,7 +92,6 @@ class UserDashboard < Administrate::BaseDashboard
FORM_ATTRIBUTES = T.let(%i[
name
organisation
admin
roles
].freeze, T::Array[Symbol])

Expand Down
4 changes: 2 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class User < ApplicationRecord
has_many :reports, dependent: :nullify
has_many :contact_messages, dependent: :nullify

# Override standard method to also check rolify role
# TODO: Inline this
sig { returns(T::Boolean) }
def admin?
self[:admin] || has_role?(:admin)
has_role?(:admin)
end

# rubocop:disable Style/ArgumentsForwarding
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20240910032647_remove_admin_from_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RemoveAdminFromUsers < ActiveRecord::Migration[7.1]
def change
remove_column :users, :admin, :boolean, default: false, null: false
end
end
3 changes: 1 addition & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.1].define(version: 2024_09_10_003300) do
ActiveRecord::Schema[7.1].define(version: 2024_09_10_032647) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
enable_extension "postgis"
Expand Down Expand Up @@ -314,7 +314,6 @@
t.datetime "created_at", precision: nil
t.datetime "updated_at", precision: nil
t.datetime "reset_password_sent_at", precision: nil
t.boolean "admin", default: false, null: false
t.string "name"
t.string "organisation"
t.string "confirmation_token"
Expand Down
5 changes: 0 additions & 5 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,6 @@
end
password { "foofoo" }

factory :admin do
admin { true }
confirmed_at { 1.day.ago }
end

factory :confirmed_user do
confirmed_at { Time.zone.now }
end
Expand Down
3 changes: 2 additions & 1 deletion spec/support/session_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

module SessionHelpers
def sign_in_as_admin
admin = create(:admin)
admin = create(:confirmed_user)
admin.add_role(:admin)

visit admin_root_path

Expand Down

0 comments on commit 92c2729

Please sign in to comment.