Class: Admin::UsersController

Inherits:
CrudController
  • Object
show all
Defined in:
app/controllers/admin/users_controller.rb

Instance Method Summary collapse

Instance Method Details

#cancelObject


36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/admin/users_controller.rb', line 36

def cancel
  user = User.where(id: params[:id]).first

  Thread.new do
    org = Organization.where(id: user.organization_id).first
    org.destroy
  end

  sign_out user

  flash[:notice] = 'Account successfully cancelled.'
  redirect_to root_path
end

#editObject


32
33
34
# File 'app/controllers/admin/users_controller.rb', line 32

def edit
  redirect_to admin_users_path
end

#indexObject

GET /users GET /users.xml


16
17
18
19
20
21
# File 'app/controllers/admin/users_controller.rb', line 16

def index
  @search = User.organization(current_user).search(params[:q])
  @users = @search.result.paginate(:page => params[:page], :per_page => 10).order("updated_at DESC")
  
  respond_with(@users)
end

#reset_tokenObject


62
63
64
65
66
67
68
69
70
# File 'app/controllers/admin/users_controller.rb', line 62

def reset_token
  @user = User.find(params[:id])
  return redirect_to root_path if @user.id != current_user.id
  @user.authentication_token = @user.generate_authentication_token
  @user.save

  # respond_with(@user, :location => admin_user_path(@user))
  redirect_to admin_user_path(@user)
end

#set_roleObject


50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/admin/users_controller.rb', line 50

def set_role
  @user = User.find(params[:id])

  role = params[:user][:permissions].to_i == 1 ? 2 : 3

  permission = Permission.find(@user.permissions.first.id)
  permission.role_id = @user.owner == 1 ? 2 : role
  permission.save

  respond_with(@user, :location => admin_user_path(@user))
end

#showObject

GET /users/1 GET /users/1.xml


25
26
27
28
29
30
# File 'app/controllers/admin/users_controller.rb', line 25

def show
  @user = User.where(:id => params[:id]).first()
  @activities = PublicActivity::Activity.where(:owner_id => @user.id).order("created_at desc").limit(5)
  
  respond_with(@user)
end