Show More
Commit Description:
fix destroy button link
Commit Description:
fix destroy button link
References:
File last commit:
Show/Diff file:
Action:
app/controllers/user_admin_controller.rb | 538 lines | 14.3 KiB | text/x-ruby | RubyLexer |
add download score as csv
r449 require 'csv'
pramook
initial commit...
r0 class UserAdminController < ApplicationController
Jittat Fakcharoenphol
moved send mail code back to helper
r336 include MailHelperMethods
jittat
[web] updated grader monitoring...
r105 before_filter :admin_authorization
pramook
initial commit...
r0
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
jittat
added random user passwords, better user creation by list....
r200 verify :method => :post, :only => [ :destroy,
:create, :create_from_list,
Jittat Fakcharoenphol
sends mass emails
r309 :update,
:manage_contest,
:bulk_mail
],
pramook
initial commit...
r0 :redirect_to => { :action => :list }
Jittat Fakcharoenphol
renamed model Configuration to GraderConfiguration, renamed rhtml views to erb, fixed other small errors
r320 def index
Jittat Fakcharoenphol
added pagination to user_admin, using will_paginate plugin
r299 @user_count = User.count
Jittat Fakcharoenphol
also shows users in all (without pagination)
r300 if params[:page] == 'all'
@users = User.all
@paginated = false
else
@users = User.paginate :page => params[:page]
@paginated = true
end
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at']
Jittat Fakcharoenphol
lists users in each contest. individual user contest management moved to each contest user list page
r297 @contests = Contest.enabled
pramook
initial commit...
r0 end
jittat
MERGED change set 372:399 from ytopc08-2 branch...
r190 def active
sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago])
@users = []
sessions.each do |session|
if session.data[:user_id]
@users << User.find(session.data[:user_id])
end
end
end
pramook
initial commit...
r0 def show
@user = User.find(params[:id])
end
def new
@user = User.new
end
def create
@user = User.new(params[:user])
jittat
start working on e-mail registration...
r155 @user.activated = true
pramook
initial commit...
r0 if @user.save
flash[:notice] = 'User was successfully created.'
- bootstrap: user admin quick add
r571 redirect_to :action => 'index'
pramook
initial commit...
r0 else
render :action => 'new'
Jittat Fakcharoenphol
added default contest
r308 end
pramook
initial commit...
r0 end
more heart beat feature...
r541 def clear_last_ip
@user = User.find(params[:id])
@user.last_ip = nil
@user.save
- bootstrap: user admin quick add
r571 redirect_to action: 'index', page: params[:page]
more heart beat feature...
r541 end
jittat
add adding list of users...
r4 def create_from_list
lines = params[:user_list]
jittat
added random user passwords, better user creation by list....
r200
note = []
jittat
add adding list of users...
r4 lines.split("\n").each do |line|
jittat
fixed line cut error when create list of users...
r139 items = line.chomp.split(',')
jittat
added random user passwords, better user creation by list....
r200 if items.length>=2
login = items[0]
full_name = items[1]
added_random_password = false
if items.length>=3
Jittat Fakcharoenphol
fixed new users import bug when passwords contain extra spaces at the end
r307 password = items[2].chomp(" ")
jittat
added random user passwords, better user creation by list....
r200 user_alias = (items.length>=4) ? items[3] : login
else
password = random_password
user_alias = (items.length>=4) ? items[3] : login
added_random_password = true
end
modify user list creation into user list update
r469 user = User.find_by_login(login)
if (user)
user.full_name = full_name
user.password = password
else
user = User.new({:login => login,
:full_name => full_name,
:password => password,
:password_confirmation => password,
:alias => user_alias})
end
jittat
start working on e-mail registration...
r155 user.activated = true
jittat
add adding list of users...
r4 user.save
jittat
added random user passwords, better user creation by list....
r200
if added_random_password
note << "'#{login}' (+)"
else
note << login
end
jittat
add adding list of users...
r4 end
end
jittat
added random user passwords, better user creation by list....
r200 flash[:notice] = 'User(s) ' + note.join(', ') +
' were successfully created. ' +
'( (+) - created with random passwords.)'
- bootstrap: user admin quick add
r571 redirect_to :action => 'index'
jittat
add adding list of users...
r4 end
pramook
initial commit...
r0 def edit
@user = User.find(params[:id])
end
def update
@user = User.find(params[:id])
if @user.update_attributes(params[:user])
flash[:notice] = 'User was successfully updated.'
redirect_to :action => 'show', :id => @user
else
render :action => 'edit'
end
end
def destroy
User.find(params[:id]).destroy
- bootstrap: user admin quick add
r571 redirect_to :action => 'index'
pramook
initial commit...
r0 end
def user_stat
add download score as csv
r449 if params[:commit] == 'download csv'
@problems = Problem.all
else
@problems = Problem.find_available_problems
end
report only enabled user
r550 @users = User.includes(:contests, :contest_stat).where(enabled: true) #find(:all, :include => [:contests, :contest_stat]).where(enabled: true)
pramook
initial commit...
r0 @scorearray = Array.new
@users.each do |u|
ustat = Array.new
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 ustat[0] = u
pramook
initial commit...
r0 @problems.each do |p|
add feature check maximum score in submission ranges...
r350 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
add check for nil problem
r527 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
add feature check maximum score in submission ranges...
r350 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
else
ustat << [0,false]
end
end
@scorearray << ustat
end
fix download score in user_stat not working
r499 if params[:commit] == 'download csv' then
csv = gen_csv_from_scorearray(@scorearray,@problems)
send_data csv, filename: 'last_score.csv'
else
render template: 'user_admin/user_stat'
end
merge with dae again
r480 end
def user_stat_max
add download score as csv
r449 if params[:commit] == 'download csv'
@problems = Problem.all
else
@problems = Problem.find_available_problems
end
add feature check maximum score in submission ranges...
r350 @users = User.find(:all, :include => [:contests, :contest_stat])
@scorearray = Array.new
#set up range from param
since_id = params.fetch(:since_id, 0).to_i
until_id = params.fetch(:until_id, 0).to_i
@users.each do |u|
ustat = Array.new
ustat[0] = u
@problems.each do |p|
max_points = 0
Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
max_points = sub.points if sub and sub.points and (sub.points > max_points)
end
ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
pramook
initial commit...
r0 end
@scorearray << ustat
end
add table sorter and combine user_stat and user_stat_max action into one view
r430
add download score as csv
r449 if params[:commit] == 'download csv' then
csv = gen_csv_from_scorearray(@scorearray,@problems)
send_data csv, filename: 'max_score.csv'
else
render template: 'user_admin/user_stat'
end
pramook
initial commit...
r0 end
jittat
[web] import from site...
r106
def import
if params[:file]==''
flash[:notice] = 'Error importing no file'
- bootstrap: user admin quick add
r571 redirect_to :action => 'index' and return
jittat
[web] import from site...
r106 end
import_from_file(params[:file])
end
jittat
added random user passwords, better user creation by list....
r200 def random_all_passwords
users = User.find(:all)
@prefix = params[:prefix] || ''
@non_admin_users = User.find_non_admin_with_prefix(@prefix)
@changed = false
Jittat Fakcharoenphol
fixed form_tag bug in views
r340 if request.request_method == 'POST'
jittat
added random user passwords, better user creation by list....
r200 @non_admin_users.each do |user|
password = random_password
user.password = password
user.password_confirmation = password
user.save
end
@changed = true
end
end
more heart beat feature...
r541
Jittat Fakcharoenphol
manages users in contests
r280 # contest management
Jittat Fakcharoenphol
lists users in each contest. individual user contest management moved to each contest user list page
r297 def contests
Jittat Fakcharoenphol
assigns all users from on contest list to another
r298 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
@contests = Contest.enabled
end
def assign_from_list
contest_id = params[:users_contest_id]
org_contest, users = find_contest_and_user_from_contest_id(contest_id)
contest = Contest.find(params[:new_contest][:id])
if !contest
flash[:notice] = 'Error: no contest'
redirect_to :action => 'contests', :id =>contest_id
Jittat Fakcharoenphol
lists users in each contest. individual user contest management moved to each contest user list page
r297 end
Jittat Fakcharoenphol
assigns all users from on contest list to another
r298
note = []
users.each do |u|
u.contests = [contest]
note << u.login
Jittat Fakcharoenphol
lists users in each contest. individual user contest management moved to each contest user list page
r297 end
Jittat Fakcharoenphol
assigns all users from on contest list to another
r298 flash[:notice] = 'User(s) ' + note.join(', ') +
" were successfully reassigned to #{contest.title}."
redirect_to :action => 'contests', :id =>contest.id
Jittat Fakcharoenphol
lists users in each contest. individual user contest management moved to each contest user list page
r297 end
Jittat Fakcharoenphol
manages users in contests
r280 def add_to_contest
user = User.find(params[:id])
contest = Contest.find(params[:contest_id])
if user and contest
user.contests << contest
end
- bootstrap: user admin quick add
r571 redirect_to :action => 'index'
Jittat Fakcharoenphol
manages users in contests
r280 end
def remove_from_contest
user = User.find(params[:id])
contest = Contest.find(params[:contest_id])
if user and contest
user.contests.delete(contest)
end
- bootstrap: user admin quick add
r571 redirect_to :action => 'index'
Jittat Fakcharoenphol
manages users in contests
r280 end
def contest_management
end
def manage_contest
contest = Contest.find(params[:contest][:id])
if !contest
flash[:notice] = 'You did not choose the contest.'
redirect_to :action => 'contest_management' and return
end
operation = params[:operation]
Jittat Fakcharoenphol
assigns users to a unique contest, small styling on contest title
r281 if not ['add','remove','assign'].include? operation
Jittat Fakcharoenphol
manages users in contests
r280 flash[:notice] = 'You did not choose the operation to perform.'
redirect_to :action => 'contest_management' and return
end
lines = params[:login_list]
if !lines or lines.blank?
flash[:notice] = 'You entered an empty list.'
redirect_to :action => 'contest_management' and return
end
note = []
Jittat Fakcharoenphol
a cleaner, testable way to log out user after contest changed
r295 users = []
Jittat Fakcharoenphol
manages users in contests
r280 lines.split("\n").each do |line|
user = User.find_by_login(line.chomp)
if user
if operation=='add'
Jittat Fakcharoenphol
logs out users after contests changed
r294 if ! user.contests.include? contest
user.contests << contest
end
Jittat Fakcharoenphol
assigns users to a unique contest, small styling on contest title
r281 elsif operation=='remove'
user.contests.delete(contest)
Jittat Fakcharoenphol
manages users in contests
r280 else
Jittat Fakcharoenphol
assigns users to a unique contest, small styling on contest title
r281 user.contests = [contest]
Jittat Fakcharoenphol
manages users in contests
r280 end
Jittat Fakcharoenphol
logs out users after contests changed
r294
Jittat Fakcharoenphol
a cleaner, testable way to log out user after contest changed
r295 if params[:reset_timer]
user.contest_stat.forced_logout = true
user.contest_stat.reset_timer_and_save
end
Jittat Fakcharoenphol
resets contest start time when changing users' contest
r289
Jittat Fakcharoenphol
sends notification emails to users after contest upgrade.
r296 if params[:notification_emails]
send_contest_update_notification_email(user, contest)
end
Jittat Fakcharoenphol
manages users in contests
r280 note << user.login
Jittat Fakcharoenphol
a cleaner, testable way to log out user after contest changed
r295 users << user
Jittat Fakcharoenphol
manages users in contests
r280 end
end
Jittat Fakcharoenphol
logs out users after contests changed
r294
if params[:reset_timer]
Jittat Fakcharoenphol
a cleaner, testable way to log out user after contest changed
r295 logout_users(users)
Jittat Fakcharoenphol
logs out users after contests changed
r294 end
Jittat Fakcharoenphol
manages users in contests
r280 flash[:notice] = 'User(s) ' + note.join(', ') +
' were successfully modified. '
redirect_to :action => 'contest_management'
end
jittat
added random user passwords, better user creation by list....
r200
Jittat Fakcharoenphol
added admin users management
r233 # admin management
def admin
@admins = User.find(:all).find_all {|user| user.admin? }
end
def grant_admin
login = params[:login]
user = User.find_by_login(login)
if user!=nil
admin_role = Role.find_by_name('admin')
user.roles << admin_role
else
flash[:notice] = 'Unknown user'
end
flash[:notice] = 'User added as admins'
redirect_to :action => 'admin'
end
def revoke_admin
user = User.find(params[:id])
if user==nil
flash[:notice] = 'Unknown user'
redirect_to :action => 'admin' and return
elsif user.login == 'root'
flash[:notice] = 'You cannot revoke admisnistrator permission from root.'
redirect_to :action => 'admin' and return
end
admin_role = Role.find_by_name('admin')
user.roles.delete(admin_role)
flash[:notice] = 'User permission revoked'
redirect_to :action => 'admin'
end
Jittat Fakcharoenphol
sends mass emails
r309 # mass mailing
def mass_mailing
end
def bulk_mail
lines = params[:login_list]
if !lines or lines.blank?
flash[:notice] = 'You entered an empty list.'
redirect_to :action => 'mass_mailing' and return
end
Jittat Fakcharoenphol
sends mails by mail gem
r331 mail_subject = params[:subject]
if !mail_subject or mail_subject.blank?
Jittat Fakcharoenphol
sends mass emails
r309 flash[:notice] = 'You entered an empty mail subject.'
redirect_to :action => 'mass_mailing' and return
end
Jittat Fakcharoenphol
sends mails by mail gem
r331
mail_body = params[:email_body]
if !mail_body or mail_body.blank?
flash[:notice] = 'You entered an empty mail body.'
redirect_to :action => 'mass_mailing' and return
end
Jittat Fakcharoenphol
sends mass emails
r309
note = []
users = []
lines.split("\n").each do |line|
user = User.find_by_login(line.chomp)
if user
Jittat Fakcharoenphol
moved send mail code back to helper
r336 send_mail(user.email, mail_subject, mail_body)
Jittat Fakcharoenphol
sends mass emails
r309 note << user.login
end
end
flash[:notice] = 'User(s) ' + note.join(', ') +
' were successfully modified. '
redirect_to :action => 'mass_mailing'
end
jittat
[web] import from site...
r106 protected
jittat
added random user passwords, better user creation by list....
r200 def random_password(length=5)
chars = 'abcdefghijkmnopqrstuvwxyz23456789'
newpass = ""
length.times { newpass << chars[rand(chars.size-1)] }
return newpass
end
jittat
[web] import from site...
r106 def import_from_file(f)
data_hash = YAML.load(f)
@import_log = ""
country_data = data_hash[:countries]
site_data = data_hash[:sites]
user_data = data_hash[:users]
# import country
countries = {}
country_data.each_pair do |id,country|
c = Country.find_by_name(country[:name])
if c!=nil
countries[id] = c
@import_log << "Found #{country[:name]}\n"
else
countries[id] = Country.new(:name => country[:name])
countries[id].save
@import_log << "Created #{country[:name]}\n"
end
end
# import sites
sites = {}
site_data.each_pair do |id,site|
s = Site.find_by_name(site[:name])
if s!=nil
@import_log << "Found #{site[:name]}\n"
else
s = Site.new(:name => site[:name])
@import_log << "Created #{site[:name]}\n"
end
s.password = site[:password]
s.country = countries[site[:country_id]]
s.save
sites[id] = s
end
# import users
user_data.each_pair do |id,user|
u = User.find_by_login(user[:login])
if u!=nil
@import_log << "Found #{user[:login]}\n"
else
u = User.new(:login => user[:login])
@import_log << "Created #{user[:login]}\n"
end
u.full_name = user[:name]
u.password = user[:password]
u.country = countries[user[:country_id]]
u.site = sites[user[:site_id]]
jittat
MERGED 308:HEAD from http://theory.cpe.ku.ac.th/grader/web/branches/ytopc08-2/, removed some registration info...
r162 u.activated = true
u.email = "empty-#{u.login}@none.com"
if not u.save
@import_log << "Errors\n"
u.errors.each { |attr,msg| @import_log << "#{attr} - #{msg}\n" }
end
jittat
[web] import from site...
r106 end
end
Jittat Fakcharoenphol
a cleaner, testable way to log out user after contest changed
r295 def logout_users(users)
users.each do |user|
contest_stat = user.contest_stat(true)
if contest_stat and !contest_stat.forced_logout
contest_stat.forced_logout = true
contest_stat.save
Jittat Fakcharoenphol
logs out users after contests changed
r294 end
end
end
Jittat Fakcharoenphol
sends notification emails to users after contest upgrade.
r296 def send_contest_update_notification_email(user, contest)
Jittat Fakcharoenphol
renamed model Configuration to GraderConfiguration, renamed rhtml views to erb, fixed other small errors
r320 contest_title_name = GraderConfiguration['contest.name']
Jittat Fakcharoenphol
sends notification emails to users after contest upgrade.
r296 contest_name = contest.name
Jittat Fakcharoenphol
sends mails by mail gem
r331 mail_subject = t('contest.notification.email_subject', {
:contest_title_name => contest_title_name,
:contest_name => contest_name })
mail_body = t('contest.notification.email_body', {
:full_name => user.full_name,
:contest_title_name => contest_title_name,
:contest_name => contest.name,
})
Jittat Fakcharoenphol
sends notification emails to users after contest upgrade.
r296
Jittat Fakcharoenphol
sends mails by mail gem
r331 logger.info mail_body
Jittat Fakcharoenphol
moved send mail code back to helper
r336 send_mail(user.email, mail_subject, mail_body)
Jittat Fakcharoenphol
sends notification emails to users after contest upgrade.
r296 end
Jittat Fakcharoenphol
assigns all users from on contest list to another
r298
def find_contest_and_user_from_contest_id(id)
if id!='none'
@contest = Contest.find(id)
else
@contest = nil
end
if @contest
@users = @contest.users
else
@users = User.find_users_with_no_contest
end
return [@contest, @users]
end
add download score as csv
r449
def gen_csv_from_scorearray(scorearray,problem)
CSV.generate do |csv|
#add header
header = ['User','Name', 'Activated?', 'Logged in', 'Contest']
problem.each { |p| header << p.name }
header += ['Total','Passed']
csv << header
#add data
scorearray.each do |sc|
total = num_passed = 0
row = Array.new
sc.each_index do |i|
if i == 0
row << sc[i].login
row << sc[i].full_name
row << sc[i].activated
row << (sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no')
row << sc[i].contests.collect {|c| c.name}.join(', ')
else
row << sc[i][0]
total += sc[i][0]
num_passed += 1 if sc[i][1]
end
end
row << total
row << num_passed
csv << row
end
end
end
pramook
initial commit...
r0 end