2012-06-17 03:15:46 +02:00
|
|
|
class UsersController < ApplicationController
|
2016-05-15 20:19:47 +02:00
|
|
|
before_filter :require_logged_in_moderator, :only => [ :enable_invitation,
|
|
|
|
:disable_invitation,
|
|
|
|
:ban, :unban ]
|
2015-06-26 17:27:04 +02:00
|
|
|
|
2012-06-30 21:14:35 +02:00
|
|
|
def show
|
2014-01-12 21:22:47 +01:00
|
|
|
@showing_user = User.where(:username => params[:username]).first!
|
2012-09-07 16:18:15 +02:00
|
|
|
@title = "User #{@showing_user.username}"
|
2015-04-10 04:05:50 +02:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html { render :action => "show" }
|
|
|
|
format.json { render :json => @showing_user }
|
|
|
|
end
|
2012-06-30 21:14:35 +02:00
|
|
|
end
|
2012-07-08 02:47:13 +02:00
|
|
|
|
|
|
|
def tree
|
2016-11-24 14:38:21 +01:00
|
|
|
@title = I18n.t 'controllers.users_controller.usertitle'
|
2012-09-07 16:18:15 +02:00
|
|
|
|
2014-04-29 17:20:50 +02:00
|
|
|
if params[:by].to_s == "karma"
|
|
|
|
@users = User.order("karma DESC, id ASC").to_a
|
|
|
|
@user_count = @users.length
|
2015-02-23 23:56:06 +01:00
|
|
|
@title << " By Karma"
|
|
|
|
render :action => "list"
|
|
|
|
elsif params[:moderators]
|
2016-04-24 03:20:10 +02:00
|
|
|
@users = User.where("is_admin = ? OR is_moderator = ?", true, true).
|
2015-02-23 23:56:06 +01:00
|
|
|
order("id ASC").to_a
|
|
|
|
@user_count = @users.length
|
|
|
|
@title = "Moderators and Administrators"
|
2014-04-29 17:20:50 +02:00
|
|
|
render :action => "list"
|
|
|
|
else
|
|
|
|
users = User.order("id DESC").to_a
|
|
|
|
@user_count = users.length
|
|
|
|
@users_by_parent = users.group_by(&:invited_by_user_id)
|
2015-02-23 23:56:06 +01:00
|
|
|
@newest = User.order("id DESC").limit(10)
|
2014-04-29 17:20:50 +02:00
|
|
|
end
|
2012-07-08 02:47:13 +02:00
|
|
|
end
|
2013-02-22 21:52:22 +01:00
|
|
|
|
|
|
|
def invite
|
|
|
|
@title = "Pass Along an Invitation"
|
|
|
|
end
|
2015-06-26 17:27:04 +02:00
|
|
|
|
2016-05-15 20:19:47 +02:00
|
|
|
def disable_invitation
|
|
|
|
target = User.where(:username => params[:username]).first
|
|
|
|
if !target
|
|
|
|
flash[:error] = "Invalid user."
|
2016-05-16 05:54:45 +02:00
|
|
|
redirect_to "/"
|
|
|
|
else
|
|
|
|
target.disable_invite_by_user_for_reason!(@user, params[:reason])
|
2016-05-15 20:19:47 +02:00
|
|
|
|
2016-05-16 05:54:45 +02:00
|
|
|
flash[:success] = "User has had invite capability disabled."
|
|
|
|
redirect_to user_path(:user => target.username)
|
|
|
|
end
|
2016-05-15 20:19:47 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def enable_invitation
|
|
|
|
target = User.where(:username => params[:username]).first
|
|
|
|
if !target
|
|
|
|
flash[:error] = "Invalid user."
|
2016-05-16 05:54:45 +02:00
|
|
|
redirect_to "/"
|
|
|
|
else
|
|
|
|
target.enable_invite_by_user!(@user)
|
2016-05-15 20:19:47 +02:00
|
|
|
|
2016-05-16 05:54:45 +02:00
|
|
|
flash[:success] = "User has had invite capability enabled."
|
|
|
|
redirect_to user_path(:user => target.username)
|
|
|
|
end
|
2016-05-15 20:19:47 +02:00
|
|
|
end
|
|
|
|
|
2015-06-26 17:27:04 +02:00
|
|
|
def ban
|
|
|
|
buser = User.where(:username => params[:username]).first
|
|
|
|
if !buser
|
|
|
|
flash[:error] = "Invalid user."
|
|
|
|
return redirect_to "/"
|
|
|
|
end
|
|
|
|
|
|
|
|
if !params[:reason].present?
|
|
|
|
flash[:error] = "You must give a reason for the ban."
|
|
|
|
return redirect_to user_path(:user => buser.username)
|
|
|
|
end
|
|
|
|
|
|
|
|
buser.ban_by_user_for_reason!(@user, params[:reason])
|
|
|
|
|
|
|
|
flash[:success] = "User has been banned."
|
|
|
|
return redirect_to user_path(:user => buser.username)
|
|
|
|
end
|
|
|
|
|
|
|
|
def unban
|
|
|
|
buser = User.where(:username => params[:username]).first
|
|
|
|
if !buser
|
|
|
|
flash[:error] = "Invalid user."
|
|
|
|
return redirect_to "/"
|
|
|
|
end
|
|
|
|
|
|
|
|
buser.unban_by_user!(@user)
|
|
|
|
|
|
|
|
flash[:success] = "User has been unbanned."
|
|
|
|
return redirect_to user_path(:user => buser.username)
|
|
|
|
end
|
2012-06-17 03:15:46 +02:00
|
|
|
end
|