Show More
Commit Description:
added message hiding for admin in msg console...
Commit Description:
added message hiding for admin in msg console
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@371 6386c4cd-e34a-4fa8-8920-d93eb39b512e
References:
File last commit:
Show/Diff file:
Action:
app/controllers/user_admin_controller.rb
| 165 lines
| 3.9 KiB
| text/x-ruby
| RubyLexer
|
|
r0 | class UserAdminController < ApplicationController | ||
|
r105 | before_filter :admin_authorization | ||
|
r0 | |||
def index | ||||
list | ||||
render :action => 'list' | ||||
end | ||||
# GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) | ||||
verify :method => :post, :only => [ :destroy, :create, :update ], | ||||
:redirect_to => { :action => :list } | ||||
def list | ||||
|
r1 | @users = User.find(:all) | ||
|
r162 | @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at'] | ||
|
r0 | end | ||
def show | ||||
@user = User.find(params[:id]) | ||||
end | ||||
def new | ||||
@user = User.new | ||||
end | ||||
def create | ||||
@user = User.new(params[:user]) | ||||
|
r155 | @user.activated = true | ||
|
r0 | if @user.save | ||
flash[:notice] = 'User was successfully created.' | ||||
redirect_to :action => 'list' | ||||
else | ||||
render :action => 'new' | ||||
end | ||||
end | ||||
|
r4 | def create_from_list | ||
lines = params[:user_list] | ||||
lines.split("\n").each do |line| | ||||
|
r139 | items = line.chomp.split(',') | ||
|
r136 | if items.length==4 | ||
|
r4 | user = User.new | ||
user.login = items[0] | ||||
|
r136 | user.full_name = items[1] | ||
user.alias = items[2] | ||||
user.password = items[3] | ||||
user.password_confirmation = items[3] | ||||
|
r155 | user.activated = true | ||
|
r4 | user.save | ||
end | ||||
end | ||||
redirect_to :action => 'list' | ||||
end | ||||
|
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 | ||||
redirect_to :action => 'list' | ||||
end | ||||
def user_stat | ||||
@problems = Problem.find_available_problems | ||||
@users = User.find(:all) | ||||
@scorearray = Array.new | ||||
@users.each do |u| | ||||
ustat = Array.new | ||||
|
r162 | ustat[0] = u | ||
|
r0 | @problems.each do |p| | ||
|
r35 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) | ||
if (sub!=nil) and (sub.points!=nil) | ||||
|
r138 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] | ||
|
r0 | else | ||
|
r8 | ustat << [0,false] | ||
|
r0 | end | ||
end | ||||
@scorearray << ustat | ||||
end | ||||
end | ||||
|
r106 | |||
def import | ||||
if params[:file]=='' | ||||
flash[:notice] = 'Error importing no file' | ||||
redirect_to :action => 'list' and return | ||||
end | ||||
import_from_file(params[:file]) | ||||
end | ||||
protected | ||||
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]] | ||||
|
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 | ||||
|
r106 | end | ||
end | ||||
|
r0 | end | ||