Bladeren bron

Rename de la colonne admin de la table user en is_admin

Lou 3 jaren geleden
bovenliggende
commit
d2e888405a

+ 3
- 3
app/controllers/api/v1/users_controller.rb Bestand weergeven

@@ -43,8 +43,8 @@ class Api::V1::UsersController < ApplicationController
43 43
 
44 44
   # Only allow a trusted parameter "white list" through.
45 45
   def user_params
46
-    if current_user&.admin
47
-      params.require(:user).permit(:email, :username, :password, :admin)
46
+    if current_user&.is_admin
47
+      params.require(:user).permit(:email, :username, :password, :is_admin)
48 48
     else
49 49
       params.require(:user).permit(:email, :username, :password)
50 50
     end
@@ -55,6 +55,6 @@ class Api::V1::UsersController < ApplicationController
55 55
   end
56 56
 
57 57
   def check_owner_or_admin
58
-    head :forbidden unless @user.id == current_user&.id || current_user&.admin
58
+    head :forbidden unless @user.id == current_user&.id || current_user&.is_admin
59 59
   end
60 60
 end

+ 1
- 1
app/controllers/concerns/authenticable.rb Bestand weergeven

@@ -17,6 +17,6 @@ module Authenticable
17 17
   end
18 18
 
19 19
   def is_admin?
20
-    head :forbidden unless self.current_user.admin    
20
+    head :forbidden unless self.current_user.is_admin    
21 21
   end
22 22
 end

+ 1
- 1
app/serializers/user_serializer.rb Bestand weergeven

@@ -1,6 +1,6 @@
1 1
 class UserSerializer
2 2
   include JSONAPI::Serializer
3
-  attributes :email, :username, :admin
3
+  attributes :email, :username, :is_admin
4 4
   has_many :activities
5 5
 
6 6
   cache_options store: Rails.cache, namespace: 'jsonapi-serializer', expires_in: 1.hour

+ 1
- 1
db/migrate/20210413093535_create_users.rb Bestand weergeven

@@ -6,7 +6,7 @@ class CreateUsers < ActiveRecord::Migration[6.1]
6 6
       t.string :username, null: false
7 7
       t.index :username, unique: true
8 8
       t.string :password_digest
9
-      t.boolean :admin, default: false   
9
+      t.boolean :is_admin, default: false   
10 10
 
11 11
       t.timestamps
12 12
     end

+ 1
- 1
db/schema.rb Bestand weergeven

@@ -67,7 +67,7 @@ ActiveRecord::Schema.define(version: 2021_08_03_145424) do
67 67
     t.string "email", null: false
68 68
     t.string "username", null: false
69 69
     t.string "password_digest"
70
-    t.boolean "admin", default: false
70
+    t.boolean "is_admin", default: false
71 71
     t.datetime "created_at", precision: 6, null: false
72 72
     t.datetime "updated_at", precision: 6, null: false
73 73
     t.index ["email"], name: "index_users_on_email", unique: true

+ 1
- 1
db/seeds.rb Bestand weergeven

@@ -29,7 +29,7 @@ Task.reset_pk_sequence
29 29
   end
30 30
 end
31 31
 
32
-User.create! username: "admin", email: "admin@email.com", password: "azerty", admin: true
32
+User.create! username: "admin", email: "admin@email.com", password: "azerty", is_admin: true
33 33
 puts "Created Admin"
34 34
 
35 35
 30.times do |i|

+ 2
- 2
test/fixtures/users.yml Bestand weergeven

@@ -3,11 +3,11 @@
3 3
 one:
4 4
   email: one@one.com
5 5
   username: OneUsername
6
-  admin: false
6
+  is_admin: false
7 7
   password_digest: <%= BCrypt::Password.create('g00d_pa$$') %>
8 8
 
9 9
 two:
10 10
   email: two@two.com
11 11
   username: TwoUsername
12
-  admin: false
12
+  is_admin: false
13 13
   password_digest: <%= BCrypt::Password.create('g00d_pa$$') %>

Loading…
Annuleren
Opslaan