Commit 71b3eb9f by Bui Minh Duc

implement edit user type feature

parent 9f74b759
......@@ -49,4 +49,16 @@ class UsersController < ApplicationController
@current_user = current_user
end
def edit
@user = User.find_by(id: params[:id])
end
def update
user = User.find_by(id: params[:id])
user.name = params[:user][:name]
user.user_type = params[:user][:user_type]
user.save
redirect_to action: "show", id: params[:id]
end
end
......@@ -17,4 +17,17 @@ module ApplicationHelper
current_user ||= User.find(session[:user_id]) if session[:user_id]
current_user
end
def user_type(user = nil)
if user.nil?
user = current_user
end
if user.user_type == 0
"Normal User"
elsif user.user_type == 1
"Leader"
else
"Manager"
end
end
end
......@@ -23,6 +23,7 @@
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="#"><span class="label label-primary"><%= user_type %></span></a></li>
<li><a href="<%= signout_path %>"><span class="glyphicon glyphicon-log-out"></span> Log out</a></li>
</ul>
</li>
......
<div class="container">
<ol class="breadcrumb">
<li>
<%= link_to @user.login, user_path(@user) %>
<span class="label label-primary"><%= user_type @user %></span>
</li>
</ol>
<br><br>
<div class="col-md-6 col-md-offset-3">
<%= form_for :user, url: {action: "update"}, method: :patch do |f| %>
<div class="form-group">
<%= f.label "Name" %>
<%= f.text_field :name, { class: "form-control" } %>
</div>
<div class="form-group">
<%= f.label "User Type" %>
<%= f.select :user_type, [["Normal User", 0], ["Leader", 1], ["Manager", 2]], {}, { class: "form-control" } %>
</div>
<br>
<div class="form-group">
<%= f.submit "Update", { class: "btn btn-primary btn-block" } %>
</div>
<% end %>
</div>
</div>
<div class="container">
<ol class="breadcrumb">
<li><%= @user.login %></li>
<li>
<%= @user.login %>
<span class="label label-primary"><%= user_type @user %></span>
<a href="<%= edit_user_path(@user) %>"><span class="glyphicon glyphicon-edit"></span></a>
</li>
</ol>
<div class="panel panel-default">
......
class AddUserTypeToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :user_type, :integer
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20170118072055) do
ActiveRecord::Schema.define(version: 20170118085141) do
create_table "comments", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin" do |t|
t.string "html_url"
......@@ -144,6 +144,7 @@ ActiveRecord::Schema.define(version: 20170118072055) do
t.string "provider"
t.string "uid"
t.string "name"
t.integer "user_type"
t.index ["team_id"], name: "index_users_on_team_id", using: :btree
end
......
......@@ -1331,3 +1331,10 @@ I, [2017-01-18T14:00:03.798798 #10735] INFO -- : Begin task update ["socialtool
I, [2017-01-18T14:00:03.802621 #10735] INFO -- : Insert issues
I, [2017-01-18T15:00:04.369718 #15471] INFO -- : Begin task update ["socialtools", "arubaito-ex", "kuruma-ex", "arubaito_v2", "usedcar_v2", "usedcar_api"]
I, [2017-01-18T15:00:04.373572 #15471] INFO -- : Insert issues
I, [2017-01-18T16:00:04.018659 #20780] INFO -- : Begin task update ["socialtools", "arubaito-ex", "kuruma-ex", "arubaito_v2", "usedcar_v2", "usedcar_api"]
I, [2017-01-18T16:00:04.022826 #20780] INFO -- : Insert issues
I, [2017-01-18T17:00:03.929032 #26269] INFO -- : Begin task update ["socialtools", "arubaito-ex", "kuruma-ex", "arubaito_v2", "usedcar_v2", "usedcar_api"]
I, [2017-01-18T17:00:03.932951 #26269] INFO -- : Insert issues
I, [2017-01-18T17:02:48.388765 #26269] INFO -- : Insert comments
I, [2017-01-18T17:03:26.029747 #26269] INFO -- : Insert review comments
I, [2017-01-18T17:04:41.627254 #26269] INFO -- : Finished task update in 277.839838402s
......@@ -89,6 +89,7 @@ class GithubLoader
db_user.login = user.login
db_user.url = user.url
db_user.html_url = user.html_url
db_user.user_type = 0
end
db_user.save
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment