Browse Source

Rename de la colonne admin de la table user en is_admin

Lou 3 years ago
parent
commit
d2e888405a

+ 3
- 3
app/controllers/api/v1/users_controller.rb View File

43
 
43
 
44
   # Only allow a trusted parameter "white list" through.
44
   # Only allow a trusted parameter "white list" through.
45
   def user_params
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
     else
48
     else
49
       params.require(:user).permit(:email, :username, :password)
49
       params.require(:user).permit(:email, :username, :password)
50
     end
50
     end
55
   end
55
   end
56
 
56
 
57
   def check_owner_or_admin
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
   end
59
   end
60
 end
60
 end

+ 1
- 1
app/controllers/concerns/authenticable.rb View File

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

+ 1
- 1
app/serializers/user_serializer.rb View File

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

+ 1
- 1
db/migrate/20210413093535_create_users.rb View File

6
       t.string :username, null: false
6
       t.string :username, null: false
7
       t.index :username, unique: true
7
       t.index :username, unique: true
8
       t.string :password_digest
8
       t.string :password_digest
9
-      t.boolean :admin, default: false   
9
+      t.boolean :is_admin, default: false   
10
 
10
 
11
       t.timestamps
11
       t.timestamps
12
     end
12
     end

+ 1
- 1
db/schema.rb View File

67
     t.string "email", null: false
67
     t.string "email", null: false
68
     t.string "username", null: false
68
     t.string "username", null: false
69
     t.string "password_digest"
69
     t.string "password_digest"
70
-    t.boolean "admin", default: false
70
+    t.boolean "is_admin", default: false
71
     t.datetime "created_at", precision: 6, null: false
71
     t.datetime "created_at", precision: 6, null: false
72
     t.datetime "updated_at", precision: 6, null: false
72
     t.datetime "updated_at", precision: 6, null: false
73
     t.index ["email"], name: "index_users_on_email", unique: true
73
     t.index ["email"], name: "index_users_on_email", unique: true

+ 1
- 1
db/seeds.rb View File

29
   end
29
   end
30
 end
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
 puts "Created Admin"
33
 puts "Created Admin"
34
 
34
 
35
 30.times do |i|
35
 30.times do |i|

+ 2
- 2
test/fixtures/users.yml View File

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

Loading…
Cancel
Save