ajout de User#admin
This commit is contained in:
parent
83c0712947
commit
80903e7693
|
@ -68,6 +68,6 @@ class UsersController < ApplicationController
|
|||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def user_params
|
||||
params.require(:user).permit(:name, :email)
|
||||
params.require(:user).permit(:name, :email, :admin)
|
||||
end
|
||||
end
|
||||
|
|
3
app/views/shared/_colored_pill.html.erb
Normal file
3
app/views/shared/_colored_pill.html.erb
Normal file
|
@ -0,0 +1,3 @@
|
|||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-<%= (defined?(color) && color.presence) || "gray" %>-100 text-<%= (defined?(color) && color.presence) || "gray" %>-800">
|
||||
<%= yield %>
|
||||
</span>
|
|
@ -28,6 +28,10 @@
|
|||
<%= form.label :name %>
|
||||
<%= form.text_field :name %>
|
||||
</div>
|
||||
<div>
|
||||
<%= form.label :admin %>
|
||||
<%= form.check_box :admin %>
|
||||
</div>
|
||||
|
||||
<div class="inline">
|
||||
<%= form.submit class: "rounded-lg py-3 px-5 bg-blue-600 text-white inline-block font-medium cursor-pointer" %>
|
||||
|
|
|
@ -22,6 +22,9 @@
|
|||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Status
|
||||
</th>
|
||||
<th scope="col" class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
||||
Admin?
|
||||
</th>
|
||||
<th scope="col" class="relative px-6 py-3">
|
||||
<span class="sr-only">Edit</span>
|
||||
</th>
|
||||
|
@ -50,13 +53,24 @@
|
|||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
<% if user.confirmed? %>
|
||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-green-100 text-green-800">
|
||||
<%= render "shared/colored_pill", { color: "green" } do %>
|
||||
Confirmed
|
||||
</span>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<span class="px-2 inline-flex text-xs leading-5 font-semibold rounded-full bg-yellow-100 text-yellow-800">
|
||||
<%= render "shared/colored_pill", { color: "yellow" } do %>
|
||||
Unconfirmed
|
||||
</span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-500">
|
||||
<% if user.admin? %>
|
||||
<%= render "shared/colored_pill", { color: "green" } do %>
|
||||
Yes
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= render "shared/colored_pill", { color: "yellow" } do %>
|
||||
No
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="px-6 py-4 whitespace-nowrap text-right text-sm font-medium">
|
||||
|
|
6
db/migrate/20220123074307_add_admin_to_users.rb
Normal file
6
db/migrate/20220123074307_add_admin_to_users.rb
Normal file
|
@ -0,0 +1,6 @@
|
|||
class AddAdminToUsers < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :users, :admin, :boolean, null: false, default: false
|
||||
add_index :users, :admin
|
||||
end
|
||||
end
|
4
db/schema.rb
generated
4
db/schema.rb
generated
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2021_12_26_105150) do
|
||||
ActiveRecord::Schema.define(version: 2022_01_23_074307) do
|
||||
|
||||
create_table "checks", force: :cascade do |t|
|
||||
t.string "name"
|
||||
|
@ -32,6 +32,8 @@ ActiveRecord::Schema.define(version: 2021_12_26_105150) do
|
|||
t.datetime "confirmed_at", precision: 6
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
t.boolean "admin", default: false, null: false
|
||||
t.index ["admin"], name: "index_users_on_admin"
|
||||
t.index ["email"], name: "index_users_on_email", unique: true
|
||||
t.index ["remember_token"], name: "index_users_on_remember_token", unique: true
|
||||
t.index ["session_token"], name: "index_users_on_session_token", unique: true
|
||||
|
|
Loading…
Reference in a new issue