mirror of
https://github.com/ENSL/ensl.org.git
synced 2025-06-01 09:12:00 +00:00
Purged git history and removed sensitive information.
This commit is contained in:
commit
6bcc8dc76b
862 changed files with 25312 additions and 0 deletions
10
app/controllers/about_controller.rb
Normal file
10
app/controllers/about_controller.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
class AboutController < ApplicationController
|
||||
def staff
|
||||
end
|
||||
|
||||
def adminpanel
|
||||
end
|
||||
|
||||
def statistics
|
||||
end
|
||||
end
|
74
app/controllers/application_controller.rb
Normal file
74
app/controllers/application_controller.rb
Normal file
|
@ -0,0 +1,74 @@
|
|||
class ApplicationController < ActionController::Base
|
||||
helper :all
|
||||
helper_method :cuser, :strip, :return_here
|
||||
|
||||
before_filter :update_user
|
||||
before_filter :set_controller_and_action_names
|
||||
|
||||
protect_from_forgery
|
||||
respond_to :html, :js
|
||||
|
||||
include Exceptions
|
||||
|
||||
# Global methods
|
||||
|
||||
def cuser
|
||||
@cuser ||= User.find(session[:user]) if session[:user]
|
||||
end
|
||||
|
||||
def return_here
|
||||
session[:return_to] = request.url
|
||||
end
|
||||
|
||||
def return_to
|
||||
addr = session[:return_to]
|
||||
session[:return_to] = nil
|
||||
redirect_to addr
|
||||
end
|
||||
|
||||
def redirect_to_back
|
||||
if request.env["HTTP_REFERER"]
|
||||
redirect_to request.env["HTTP_REFERER"]
|
||||
else
|
||||
redirect_to "/"
|
||||
end
|
||||
rescue
|
||||
redirect_to "/"
|
||||
end
|
||||
|
||||
def redirect_to_home
|
||||
redirect_to :controller => "articles", :action => "news_index"
|
||||
end
|
||||
|
||||
def rescue_action(exception)
|
||||
case exception
|
||||
when AccessError
|
||||
render :text => t(:access_denied), :layout => true
|
||||
when Error
|
||||
render :text => exception.message, :layout => true
|
||||
when ActiveRecord::StaleObjectError
|
||||
render :text => t(:application_stale)
|
||||
else
|
||||
super exception
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_user
|
||||
if cuser
|
||||
Time.zone = cuser.time_zone
|
||||
cuser.update_attribute :lastvisit, DateTime.now if cuser.lastvisit < 2.minutes.ago
|
||||
|
||||
if cuser.banned? Ban::TYPE_SITE
|
||||
session[:user] = nil
|
||||
@cuser = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def set_controller_and_action_names
|
||||
@current_controller = controller_name
|
||||
@current_action = action_name
|
||||
end
|
||||
end
|
85
app/controllers/articles_controller.rb
Normal file
85
app/controllers/articles_controller.rb
Normal file
|
@ -0,0 +1,85 @@
|
|||
class ArticlesController < ApplicationController
|
||||
before_filter :get_article, :only => [:show, :edit, :update, :cleanup, :destroy]
|
||||
|
||||
def index
|
||||
@categories = Category.ordered.nospecial.domain Category::DOMAIN_ARTICLES
|
||||
end
|
||||
|
||||
def news_index
|
||||
@cat = params[:cat] ? Category.find(params[:cat]) : Article.onlynews.ordered.first.category
|
||||
@news = Article.with_comments.ordered.limited.nodrafts.category @cat
|
||||
@categories = Category.ordered.domain Category::DOMAIN_NEWS
|
||||
@nobody = true
|
||||
end
|
||||
|
||||
def news_archive
|
||||
@news = Article.with_comments.ordered.nodrafts.onlynews
|
||||
end
|
||||
|
||||
def admin
|
||||
raise AccessError unless cuser and cuser.admin?
|
||||
@articles = {"Drafts" => Article.drafts.ordered, "Special" => Article.category(Category::SPECIAL).ordered}
|
||||
end
|
||||
|
||||
def show
|
||||
raise AccessError unless @article.can_show? cuser
|
||||
@article.read_by! cuser if cuser
|
||||
# @article.record_view_count(request.remote_ip, cuser.nil?)
|
||||
@nobody = true
|
||||
end
|
||||
|
||||
def new
|
||||
@article = Article.new
|
||||
@article.text_coding = Article::CODING_HTML
|
||||
raise AccessError unless @article.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @article.can_update? cuser
|
||||
@file = DataFile.new
|
||||
@file.directory_id = Directory::ARTICLES
|
||||
@file.article = @article
|
||||
end
|
||||
|
||||
def create
|
||||
@article = Article.new params[:article]
|
||||
@article.user = cuser
|
||||
raise AccessError unless @article.can_create? cuser
|
||||
|
||||
if @article.save
|
||||
flash[:notice] = t(:articles_create)
|
||||
redirect_to @article
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @article.can_update? cuser, params[:article]
|
||||
if @article.update_attributes params[:article]
|
||||
flash[:notice] = t(:articles_update)
|
||||
redirect_to @article
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def cleanup
|
||||
raise AccessError unless @article.can_update? cuser
|
||||
@article.text = strip(@article.text)
|
||||
@article.save!
|
||||
redirect_to @article
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @article.can_destroy? cuser
|
||||
@article.destroy
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_article
|
||||
@article = Article.find params[:id]
|
||||
end
|
||||
end
|
57
app/controllers/bans_controller.rb
Normal file
57
app/controllers/bans_controller.rb
Normal file
|
@ -0,0 +1,57 @@
|
|||
class BansController < ApplicationController
|
||||
before_filter :get_ban, :only => [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@bans = Ban.ordered
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def refresh
|
||||
Ban.refresh
|
||||
end
|
||||
|
||||
def new
|
||||
@ban = Ban.new
|
||||
raise AccessError unless @ban.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @ban.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@ban = Ban.new(params[:ban])
|
||||
raise AccessError unless @ban.can_create? cuser
|
||||
|
||||
if @ban.save
|
||||
flash[:notice] = t(:bans_create)
|
||||
redirect_to(@ban)
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @ban.can_update? cuser
|
||||
if @ban.update_attributes(params[:ban])
|
||||
flash[:notice] = t(:bans_update)
|
||||
redirect_to(@ban)
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @ban.can_destroy? cuser
|
||||
@ban.destroy
|
||||
redirect_to(bans_url)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_ban
|
||||
@ban = Ban.find(params[:id])
|
||||
end
|
||||
end
|
40
app/controllers/brackets_controller.rb
Normal file
40
app/controllers/brackets_controller.rb
Normal file
|
@ -0,0 +1,40 @@
|
|||
class BracketsController < ApplicationController
|
||||
before_filter :get_bracket, :only => [:show, :edit, :update, :destroy]
|
||||
|
||||
def edit
|
||||
raise AccessError unless @bracket.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@bracket = Bracket.new params[:bracket]
|
||||
raise AccessError unless @bracket.can_create? cuser
|
||||
|
||||
if @bracket.save
|
||||
flash[:notice] = t(:brackets_create)
|
||||
end
|
||||
|
||||
redirect_to edit_contest_path(@bracket.contest)
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @bracket.can_update? cuser
|
||||
|
||||
if @bracket.update_attributes params[:bracket] and @bracket.update_cells(params[:cell])
|
||||
flash[:notice] = t(:brackets_update)
|
||||
end
|
||||
|
||||
render :action => "edit"
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @bracket.can_destroy? cuser
|
||||
@bracket.destroy
|
||||
redirect_to edit_contest_path(@bracket.contest)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_bracket
|
||||
@bracket = Bracket.find(params[:id])
|
||||
end
|
||||
end
|
67
app/controllers/categories_controller.rb
Normal file
67
app/controllers/categories_controller.rb
Normal file
|
@ -0,0 +1,67 @@
|
|||
class CategoriesController < ApplicationController
|
||||
before_filter :get_category, :except => [:index, :new, :create]
|
||||
|
||||
def show
|
||||
if [Category::DOMAIN_ARTICLES, Category::DOMAIN_NEWS].include? @category.domain
|
||||
@articles = Article.with_comments.ordered.limited.nodrafts.category params[:id]
|
||||
Category.find(params[:id]).read_by! cuser if cuser
|
||||
render :partial => "articles/article", :collection => @articles.to_a
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
@categories = Category.ordered
|
||||
end
|
||||
|
||||
def new
|
||||
@category = Category.new
|
||||
raise AccessError unless @category.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @category.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@category = Category.new params[:category]
|
||||
raise AccessError unless @category.can_create? cuser
|
||||
|
||||
if @category.save
|
||||
@category.update_attribute :sort, @category.id
|
||||
flash[:notice] = t(:articles_category)
|
||||
redirect_to :categories
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @category.can_update? cuser
|
||||
if @category.update_attributes params[:category]
|
||||
flash[:notice] = t(:articles_category_update)
|
||||
redirect_to :categories
|
||||
end
|
||||
end
|
||||
|
||||
def up
|
||||
raise AccessError unless @category.can_update? cuser
|
||||
@category.move_up(["domain = ?", @category.domain], "sort")
|
||||
redirect_to :categories
|
||||
end
|
||||
|
||||
def down
|
||||
raise AccessError unless @category.can_update? cuser
|
||||
@category.move_down(["domain = ?", @category.domain], "sort")
|
||||
redirect_to :categories
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @category.can_destroy? cuser
|
||||
@category.destroy
|
||||
redirect_to :categories
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_category
|
||||
@category = Category.find params[:id]
|
||||
end
|
||||
end
|
73
app/controllers/challenges_controller.rb
Normal file
73
app/controllers/challenges_controller.rb
Normal file
|
@ -0,0 +1,73 @@
|
|||
class ChallengesController < ApplicationController
|
||||
before_filter :get_challenge, :only => ['show', 'edit', 'update', 'destroy']
|
||||
|
||||
def index
|
||||
@challenges = Challenge.all
|
||||
end
|
||||
|
||||
def show
|
||||
return_here
|
||||
end
|
||||
|
||||
def refresh
|
||||
Challenge.past.pending.each do |c|
|
||||
c.destroy
|
||||
end
|
||||
|
||||
render :text => t(:challenges_cleared)
|
||||
end
|
||||
|
||||
def new
|
||||
@challenge = Challenge.new
|
||||
@challenge.user = cuser
|
||||
@challenge.contester2 = Contester.active.find params[:id]
|
||||
@challenge.get_contester1
|
||||
raise AccessError unless @challenge.can_create? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@challenge = Challenge.new params[:challenge]
|
||||
@challenge.user = cuser
|
||||
raise AccessError unless @challenge.can_create? cuser
|
||||
|
||||
if @challenge.valid? and @challenge.save
|
||||
flash[:notice] = t(:challenges_create)
|
||||
redirect_to @challenge
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@challenge = Challenge.find params[:id]
|
||||
raise AccessError unless @challenge.can_update? cuser
|
||||
case params[:commit]
|
||||
when "Accept"
|
||||
@challenge.status = Challenge::STATUS_ACCEPTED
|
||||
when "Default time"
|
||||
@challenge.status = Challenge::STATUS_DEFAULT
|
||||
when "Forfeit"
|
||||
@challenge.status = Challenge::STATUS_FORFEIT
|
||||
when "Decline"
|
||||
@challenge.status = Challenge::STATUS_DECLINED
|
||||
end
|
||||
|
||||
if @challenge.update_attributes params[:challenge]
|
||||
flash[:notice] = t(:challenges_update)
|
||||
end
|
||||
|
||||
render :action => "show"
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @challenge.can_destroy? cuser
|
||||
@challenge.destroy
|
||||
return_to
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_challenge
|
||||
@challenge = Challenge.find params[:id]
|
||||
end
|
||||
end
|
55
app/controllers/comments_controller.rb
Normal file
55
app/controllers/comments_controller.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
class CommentsController < ApplicationController
|
||||
before_filter :get_comment, :only => [:raw, 'edit', 'update', 'destroy']
|
||||
respond_to :html, :js
|
||||
|
||||
def index
|
||||
@comments = Comment.recent.filtered
|
||||
end
|
||||
|
||||
def show
|
||||
@comments = Comment.recent5.all :conditions => {:commentable_id => params[:id2], :commentable_type => params[:id]}
|
||||
render :partial => 'list', :layout => false
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @comment.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@comment = Comment.new params[:comment]
|
||||
@comment.user = cuser
|
||||
raise AccessError unless @comment.can_create? cuser
|
||||
|
||||
respond_to do |format|
|
||||
if @comment.save
|
||||
flash[:notice] = t(:comments_create)
|
||||
format.js { render }
|
||||
else
|
||||
flash[:error] = t(:comments_invalid) + @comment.errors.full_messages.to_s
|
||||
format.html { redirect_to(:back)}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @comment.can_update? cuser
|
||||
if @comment.update_attributes params[:comment]
|
||||
flash[:notice] = t(:comments_update)
|
||||
return_to
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @comment.can_destroy? cuser
|
||||
@comment.destroy
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_comment
|
||||
@comment = Comment.find params[:id]
|
||||
end
|
||||
end
|
62
app/controllers/contesters_controller.rb
Normal file
62
app/controllers/contesters_controller.rb
Normal file
|
@ -0,0 +1,62 @@
|
|||
class ContestersController < ApplicationController
|
||||
before_filter :get_contester, :only => ['show', 'edit', 'update', :recover, :destroy, :recalc]
|
||||
|
||||
def show
|
||||
@matches = Match.future.unfinished.ordered.of_contester @contester
|
||||
@results = Match.finished.ordered.of_contester @contester
|
||||
|
||||
raise AccessError unless @contester and @contester.contest and @contester.team
|
||||
|
||||
if @contester.contest.status == Contest::STATUS_CLOSED
|
||||
@members = @contester.team.teamers.distinct.ordered
|
||||
else
|
||||
@members = @contester.team.teamers.active.distinct.ordered
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @contester.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@contester = Contester.new params[:contester]
|
||||
@contester.user = cuser
|
||||
raise AccessError unless @contester.can_create? cuser
|
||||
|
||||
if @contester.save
|
||||
flash[:notice] = t(:contests_join)
|
||||
redirect_to contest_path(@contester.contest_id)
|
||||
else
|
||||
flash[:error] = t(:errors) + @contester.errors.full_messages.to_s
|
||||
redirect_to_back
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @contester.can_update? cuser
|
||||
if @contester.update_attributes params[:contester]
|
||||
flash[:notice] = t(:contests_contester_update)
|
||||
redirect_to @contester
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def recover
|
||||
raise AccessError unless @contester.can_destroy? cuser
|
||||
@contester.recover
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @contester.can_destroy? cuser
|
||||
@contester.destroy
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_contester
|
||||
@contester = Contester.find params[:id]
|
||||
end
|
||||
end
|
110
app/controllers/contests_controller.rb
Normal file
110
app/controllers/contests_controller.rb
Normal file
|
@ -0,0 +1,110 @@
|
|||
class ContestsController < ApplicationController
|
||||
before_filter :get_contest, :only => ['show', 'edit', 'update', 'destroy', 'del_map', 'scores', 'recalc']
|
||||
|
||||
def index
|
||||
#@contests = Contest.all
|
||||
@contests_active = Contest.active
|
||||
@contests_inactive = Contest.inactive
|
||||
end
|
||||
|
||||
def historical
|
||||
case params[:id]
|
||||
when "NS1"
|
||||
@contests = Contest.with_contesters.ordered.where ["name LIKE ? OR name LIKE ?", "S%:%", "%Night%"]
|
||||
else
|
||||
@contests = Contest.with_contesters.ordered.where ["id > ?", "113"]
|
||||
end
|
||||
end
|
||||
|
||||
def current
|
||||
@contests = Contest.active
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
# TODO
|
||||
# @friendly = cuser.active_contesters.of_contest(@contest).active.first if cuser
|
||||
end
|
||||
|
||||
def scores
|
||||
raise AccessError unless @contest.contest_type == Contest::TYPE_LADDER
|
||||
@friendly = params[:friendly] ? @contest.contesters.find(params[:friendly]) : @contest.contesters.first
|
||||
@rounds = [@contest.modulus_even, @contest.modulus_3to1, @contest.modulus_4to0]
|
||||
@rounds.each_index do |key|
|
||||
if params["rounds"] and params["rounds"]["#{key}"]
|
||||
@rounds[key] = params["rounds"]["#{key}"].to_f
|
||||
end
|
||||
end
|
||||
@weight = params[:weight] ? params[:weight].to_f : @contest.weight
|
||||
end
|
||||
|
||||
def recalc
|
||||
@contest.recalculate
|
||||
render :text => t(:score_recalc), :layout => true
|
||||
end
|
||||
|
||||
def new
|
||||
@contest = Contest.new
|
||||
raise AccessError unless @contest.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @contest.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@contest = Contest.new params[:contest]
|
||||
raise AccessError unless @contest.can_create? cuser
|
||||
|
||||
if @contest.save
|
||||
flash[:notice] = t(:contests_create)
|
||||
redirect_to @contest
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @contest.can_update? cuser
|
||||
if params[:commit] == "Save"
|
||||
if @contest.update_attributes(params[:contest])
|
||||
flash[:notice] = t(:contests_update)
|
||||
redirect_to @contest
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
elsif params[:commit] == "Add map"
|
||||
@contest.maps << Map.find(params[:map])
|
||||
render :action => "edit"
|
||||
elsif params[:commit] == "Add team"
|
||||
contester = Contester.new
|
||||
contester.team = Team.find params[:team]
|
||||
contester.contest = @contest
|
||||
contester.active = true
|
||||
if contester.valid?
|
||||
contester.save(false)
|
||||
else
|
||||
@contest.errors.add_to_base contester.errors.full_messages.to_s
|
||||
end
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def del_map
|
||||
raise AccessError unless @contest.can_update? cuser
|
||||
@contest.maps.delete(Map.find(params[:id2]))
|
||||
render :action => "edit"
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @contest.can_destroy? cuser
|
||||
@contest.destroy
|
||||
redirect_to contests_url
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_contest
|
||||
@contest = Contest.find params[:id]
|
||||
end
|
||||
end
|
105
app/controllers/data_files_controller.rb
Normal file
105
app/controllers/data_files_controller.rb
Normal file
|
@ -0,0 +1,105 @@
|
|||
class DataFilesController < ApplicationController
|
||||
before_filter :get_file, :only => ['show', 'edit', 'update', 'destroy', 'rate', :addFile, :delFile]
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def admin
|
||||
raise AccessError unless cuser and cuser.admin?
|
||||
@files = []
|
||||
DataFile.all.each do |f|
|
||||
@files << f unless File.exists?(f.path)
|
||||
end
|
||||
@movies = []
|
||||
DataFile.movies.each do |f|
|
||||
@movies << f unless f.movie or f.preview or (f.related and f.related.movie)
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@file = DataFile.new
|
||||
@file.directory = Directory.find params[:id]
|
||||
raise AccessError unless @file.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @file.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@file = DataFile.new params[:data_file]
|
||||
@file.size = 0
|
||||
raise AccessError unless @file.can_create? cuser
|
||||
|
||||
if @file.save
|
||||
flash[:notice] = t(:files_create)
|
||||
if @file.article
|
||||
redirect_to @file.article
|
||||
elsif @file.movie
|
||||
redirect_to @file.movie
|
||||
else
|
||||
redirect_to @file
|
||||
end
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @file.can_update? cuser
|
||||
if @file.update_attributes params[:data_file]
|
||||
flash[:notice] = t(:files_update)
|
||||
redirect_to(@file)
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def addFile
|
||||
raise AccessError unless @file.can_update? cuser
|
||||
@related = @file.directory.files.not(@file).find params[:data_file][:related_id]
|
||||
@related.related = @file
|
||||
@related.save
|
||||
redirect_to edit_data_file_url(@file)
|
||||
end
|
||||
|
||||
def delFile
|
||||
raise AccessError unless @file.can_update? cuser
|
||||
@related = @file.related_files.first params[:related_id]
|
||||
@related.related = nil
|
||||
@related.save
|
||||
redirect_to edit_data_file_url(@file)
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @file.can_destroy? cuser
|
||||
@file.destroy
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
def rate
|
||||
raise AccessError unless cuser
|
||||
if params[:id2].to_i > 0 and params[:id2].to_i <= 5
|
||||
@file.rate_it(params[:id2], cuser.id)
|
||||
end
|
||||
head :ok
|
||||
end
|
||||
|
||||
def trash
|
||||
raise AccessError unless cuser and cuser.admin?
|
||||
@result = ""
|
||||
DataFile.all.each do |file|
|
||||
unless File.exists?(file.path)
|
||||
file.destroy
|
||||
@result << file.to_s + "<br />"
|
||||
end
|
||||
end
|
||||
render :text => @result, :layout => true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_file
|
||||
@file = DataFile.find params[:id]
|
||||
end
|
||||
end
|
61
app/controllers/directories_controller.rb
Normal file
61
app/controllers/directories_controller.rb
Normal file
|
@ -0,0 +1,61 @@
|
|||
class DirectoriesController < ApplicationController
|
||||
before_filter :get_directory, :except => [:new, :create]
|
||||
|
||||
def show
|
||||
if @directory.hidden
|
||||
@files = @directory.files
|
||||
render :partial => "data_files/list", :layout => true
|
||||
else
|
||||
@directories = Directory.ordered.filtered.all :conditions => {:parent_id => 1}
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@directory = Directory.new
|
||||
@directory.parent = Directory.find params[:id]
|
||||
raise AccessError unless @directory.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @directory.can_update? cuser
|
||||
end
|
||||
|
||||
def refresh
|
||||
@directory.process_dir
|
||||
render :text => t(:directories_update)
|
||||
end
|
||||
|
||||
def create
|
||||
@directory = Directory.new params[:directory]
|
||||
raise AccessError unless @directory.can_create? cuser
|
||||
|
||||
if @directory.save
|
||||
flash[:notice] = t(:directories_create)
|
||||
redirect_to(@directory)
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @directory.can_update? cuser
|
||||
if @directory.update_attributes(params[:directory])
|
||||
flash[:notice] = t(:directories_update)
|
||||
redirect_to @directory
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @directory.can_destroy? cuser
|
||||
@directory.destroy
|
||||
redirect_to directories_url
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_directory
|
||||
@directory = Directory.find params[:id]
|
||||
end
|
||||
end
|
35
app/controllers/forumers_controller.rb
Normal file
35
app/controllers/forumers_controller.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
class ForumersController < ApplicationController
|
||||
def create
|
||||
@forumer = Forumer.new params[:forumer]
|
||||
raise AccessError unless @forumer.can_create? cuser
|
||||
|
||||
if @forumer.save
|
||||
flash[:notice] = t(:groups_added)
|
||||
else
|
||||
flash[:error] = @forumer.errors.full_messages.to_s
|
||||
end
|
||||
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
def update
|
||||
@forumer = Forumer.find params[:id]
|
||||
raise AccessError unless @forumer.can_update? cuser
|
||||
|
||||
if @forumer.update_attributes params[:forumer]
|
||||
flash[:notice] = t(:groups_acl_update)
|
||||
else
|
||||
flash[:error] = @forumer.errors.full_messages.to_s
|
||||
end
|
||||
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
def destroy
|
||||
@forumer = Forumer.find params[:id]
|
||||
raise AccessError unless @forumer.can_destroy? cuser
|
||||
|
||||
@forumer.destroy
|
||||
redirect_to_back
|
||||
end
|
||||
end
|
70
app/controllers/forums_controller.rb
Normal file
70
app/controllers/forums_controller.rb
Normal file
|
@ -0,0 +1,70 @@
|
|||
class ForumsController < ApplicationController
|
||||
before_filter :get_forum, :only => [:show, :edit, :update, :up, :down, :destroy]
|
||||
|
||||
def index
|
||||
@categories = Category.domain(Category::DOMAIN_FORUMS).ordered
|
||||
@nobody = true
|
||||
end
|
||||
|
||||
def show
|
||||
raise AccessError unless @forum.can_show? cuser
|
||||
@topics = @forum.topics.all
|
||||
@forum.read_by! cuser if cuser
|
||||
@nobody = true
|
||||
end
|
||||
|
||||
def new
|
||||
@forum = Forum.new
|
||||
raise AccessError unless @forum.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @forum.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@forum = Forum.new(params[:forum])
|
||||
raise AccessError unless @forum.can_create? cuser
|
||||
|
||||
if @forum.save
|
||||
flash[:notice] = t(:forums_create)
|
||||
redirect_to(@forum)
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @forum.can_update? cuser
|
||||
if @forum.update_attributes(params[:forum])
|
||||
flash[:notice] = t(:forums_update)
|
||||
redirect_to(@forum)
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def up
|
||||
raise AccessError unless @forum.can_update? cuser
|
||||
@forum.move_up :category_id => @forum.category.id
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
def down
|
||||
raise AccessError unless @forum.can_update? cuser
|
||||
@forum.move_down :category_id => @forum.category.id
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @forum.can_destroy? cuser
|
||||
@forum.destroy
|
||||
redirect_to(forums_url)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_forum
|
||||
@forum = Forum.find(params[:id])
|
||||
end
|
||||
end
|
47
app/controllers/gatherers_controller.rb
Normal file
47
app/controllers/gatherers_controller.rb
Normal file
|
@ -0,0 +1,47 @@
|
|||
class GatherersController < ApplicationController
|
||||
before_filter :get_gatherer, :except => [:create]
|
||||
|
||||
def create
|
||||
Gather.transaction do
|
||||
Gatherer.transaction do
|
||||
@gatherer = Gatherer.new params[:gatherer]
|
||||
@gatherer.gather.lock!
|
||||
raise AccessError unless @gatherer.can_create? cuser, params[:gatherer]
|
||||
|
||||
if @gatherer.save
|
||||
flash[:notice] = t(:gathers_join)
|
||||
else
|
||||
flash[:error] = @gatherer.errors.full_messages.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
redirect_to @gatherer.gather
|
||||
end
|
||||
|
||||
def update
|
||||
@gatherer = Gatherer.find params[:gatherer][:id]
|
||||
raise AccessError unless @gatherer.can_update? cuser, params[:gatherer]
|
||||
|
||||
if @gatherer.update_attributes params[:gatherer]
|
||||
flash[:notice] = t(:gatherers_update)
|
||||
else
|
||||
flash[:error] = @gatherer.errors.full_messages.to_s
|
||||
end
|
||||
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @gatherer.can_destroy? cuser
|
||||
|
||||
@gatherer.destroy
|
||||
redirect_to @gatherer.gather
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_gatherer
|
||||
@gatherer = Gatherer.find params[:id]
|
||||
end
|
||||
end
|
75
app/controllers/gathers_controller.rb
Normal file
75
app/controllers/gathers_controller.rb
Normal file
|
@ -0,0 +1,75 @@
|
|||
class GathersController < ApplicationController
|
||||
before_filter :get_gather, :except => [:latest, :index, :create]
|
||||
respond_to :html, :js
|
||||
|
||||
def index
|
||||
@gathers = Gather.ordered.limit(50).all
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def latest
|
||||
@gather = Gather.last(params[:game])
|
||||
redirect_to @gather
|
||||
end
|
||||
|
||||
def edit
|
||||
@gather.admin = true
|
||||
end
|
||||
|
||||
def create
|
||||
@gather = Gather.new
|
||||
@gather.category_id = params[:gather][:category_id]
|
||||
raise AccessError unless @gather.can_create? cuser
|
||||
|
||||
if @gather.save
|
||||
flash[:notice] = t(:gather_create)
|
||||
end
|
||||
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
def update
|
||||
@gather = Gather.basic.find(params[:id])
|
||||
raise AccessError unless @gather.can_update? cuser
|
||||
|
||||
Gatherer.transaction do
|
||||
Gather.transaction do
|
||||
if @gather.update_attributes params[:gather]
|
||||
flash[:notice] = 'Gather was successfully updated.'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
redirect_to @gather
|
||||
end
|
||||
|
||||
def pick
|
||||
@gatherer = @gather.gatherers.find(params[:player])
|
||||
raise AccessError unless @gatherer.can_update? cuser, params
|
||||
|
||||
Gatherer.transaction do
|
||||
Gather.transaction do
|
||||
if @gatherer.update_attribute :team, @gatherer.gather.turn
|
||||
flash[:notice] = t(:gathers_user_pick)
|
||||
else
|
||||
flash[:error] = @gatherer.errors.full_messages.to_s
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
redirect_to @gather
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_gather
|
||||
Gather.transaction do
|
||||
@gather = Gather.basic.find(params[:id], :lock => true)
|
||||
@gather.refresh cuser
|
||||
end
|
||||
|
||||
@gatherer = @gather.gatherers.of_user(cuser).first if cuser
|
||||
end
|
||||
end
|
35
app/controllers/groupers_controller.rb
Normal file
35
app/controllers/groupers_controller.rb
Normal file
|
@ -0,0 +1,35 @@
|
|||
class GroupersController < ApplicationController
|
||||
def create
|
||||
@grouper = Grouper.new params[:grouper]
|
||||
raise AccessError unless @grouper.can_create? cuser
|
||||
|
||||
if @grouper.save
|
||||
flash[:notice] = t(:groups_user_add)
|
||||
else
|
||||
flash[:error] = @grouper.errors.full_messages.to_s
|
||||
end
|
||||
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
def update
|
||||
@grouper = Grouper.find params[:id]
|
||||
raise AccessError unless @grouper.can_update? cuser
|
||||
|
||||
if @grouper.update_attributes params[:grouper]
|
||||
flash[:notice] = t(:groups_user_update)
|
||||
else
|
||||
flash[:error] = @grouper.errors.full_messages.to_s
|
||||
end
|
||||
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
def destroy
|
||||
@grouper = Grouper.find params[:id]
|
||||
raise AccessError unless @grouper.can_destroy? cuser
|
||||
|
||||
@grouper.destroy
|
||||
redirect_to_back
|
||||
end
|
||||
end
|
71
app/controllers/groups_controller.rb
Normal file
71
app/controllers/groups_controller.rb
Normal file
|
@ -0,0 +1,71 @@
|
|||
class GroupsController < ApplicationController
|
||||
before_filter :get_group, :except => [:index, :new, :create]
|
||||
|
||||
def index
|
||||
@groups = Group.all
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
@group = Group.new
|
||||
raise AccessError unless @group.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
@group.users.all
|
||||
raise AccessError unless @group.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@group = Group.new params[:group]
|
||||
@group.founder = cuser
|
||||
raise AccessError unless @group.can_create? cuser
|
||||
if @group.save
|
||||
flash[:notice] = t(:groups_create)
|
||||
redirect_to @group
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @group.can_update? cuser
|
||||
if @group.update_attributes params[:group]
|
||||
flash[:notice] = t(:groups_update)
|
||||
redirect_to @group
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @group.can_destroy? cuser
|
||||
@group.destroy
|
||||
redirect_to groups_url
|
||||
end
|
||||
|
||||
def addUser
|
||||
@user = User.first :conditions => {:username => params[:username]}
|
||||
raise AccessError unless @group.can_update? cuser
|
||||
raise Error, t(:duplicate_user) if @group.users.include? @user
|
||||
|
||||
@group.users << @user if @user
|
||||
redirect_to edit_group_url(@group, :groupTab => "groupTabMembers")
|
||||
end
|
||||
|
||||
def delUser
|
||||
@user = User.find params[:id2]
|
||||
raise AccessError unless @group.can_update? cuser
|
||||
|
||||
@group.users.delete @user
|
||||
redirect_to edit_group_url(@group, :groupTab => "groupTabMembers")
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_group
|
||||
@group = Group.find params[:id]
|
||||
end
|
||||
end
|
72
app/controllers/issues_controller.rb
Normal file
72
app/controllers/issues_controller.rb
Normal file
|
@ -0,0 +1,72 @@
|
|||
class IssuesController < ApplicationController
|
||||
before_filter :get_issue, :only => [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
raise AccessError unless cuser and cuser.admin?
|
||||
|
||||
sort = case params['sort']
|
||||
when "title" then "title"
|
||||
when "status" then "status"
|
||||
when "assigned" then "assigned_id"
|
||||
when "category" then "category_id"
|
||||
else "created_at DESC"
|
||||
end
|
||||
|
||||
@open = Issue.with_status(Issue::STATUS_OPEN).all :order => sort
|
||||
@solved = Issue.with_status(Issue::STATUS_SOLVED).all :order => sort
|
||||
@rejected = Issue.with_status(Issue::STATUS_REJECTED).all :order => sort
|
||||
end
|
||||
|
||||
def show
|
||||
raise AccessError unless @issue.can_show? cuser
|
||||
@issue.read_by! cuser
|
||||
end
|
||||
|
||||
def new
|
||||
@issue = Issue.new
|
||||
raise AccessError unless @issue.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @issue.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@issue = Issue.new(params[:issue])
|
||||
@issue.author = cuser if cuser
|
||||
raise AccessError unless @issue.can_create? cuser
|
||||
|
||||
if @issue.save
|
||||
flash[:notice] = t(:issues_create)
|
||||
if cuser
|
||||
redirect_to(@issue)
|
||||
else
|
||||
redirect_to_home
|
||||
end
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @issue.can_update? cuser
|
||||
if @issue.update_attributes(params[:issue])
|
||||
flash[:notice] = t(:issues_update)
|
||||
redirect_to(@issue)
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @issue.can_destroy? cuser
|
||||
@issue.destroy
|
||||
redirect_to(issues_url)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_issue
|
||||
@issue = Issue.find params[:id]
|
||||
end
|
||||
end
|
22
app/controllers/locks_controller.rb
Normal file
22
app/controllers/locks_controller.rb
Normal file
|
@ -0,0 +1,22 @@
|
|||
class LocksController < ApplicationController
|
||||
def create
|
||||
@lock = Lock.new params[:lock]
|
||||
raise AccessError unless @lock.can_create? cuser
|
||||
|
||||
if @lock.save
|
||||
flash[:notice] = t(:topics_locked)
|
||||
else
|
||||
flash[:error] = @lock.errors.full_messages.to_s
|
||||
end
|
||||
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
def destroy
|
||||
@lock = Lock.find params[:id]
|
||||
raise AccessError unless @lock.can_destroy? cuser
|
||||
|
||||
@lock.destroy
|
||||
redirect_to_back
|
||||
end
|
||||
end
|
85
app/controllers/log_events_controller.rb
Normal file
85
app/controllers/log_events_controller.rb
Normal file
|
@ -0,0 +1,85 @@
|
|||
class LogEventsController < ApplicationController
|
||||
# GET /log_events
|
||||
# GET /log_events.xml
|
||||
def index
|
||||
@log_events = LogEvent.all
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
format.xml { render :xml => @log_events }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /log_events/1
|
||||
# GET /log_events/1.xml
|
||||
def show
|
||||
@log_event = LogEvent.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
format.html # show.html.erb
|
||||
format.xml { render :xml => @log_event }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /log_events/new
|
||||
# GET /log_events/new.xml
|
||||
def new
|
||||
@log_event = LogEvent.new
|
||||
|
||||
respond_to do |format|
|
||||
format.html # new.html.erb
|
||||
format.xml { render :xml => @log_event }
|
||||
end
|
||||
end
|
||||
|
||||
# GET /log_events/1/edit
|
||||
def edit
|
||||
@log_event = LogEvent.find(params[:id])
|
||||
end
|
||||
|
||||
# POST /log_events
|
||||
# POST /log_events.xml
|
||||
def create
|
||||
@log_event = LogEvent.new(params[:log_event])
|
||||
|
||||
respond_to do |format|
|
||||
if @log_event.save
|
||||
flash[:notice] = t(:logevent_create)
|
||||
format.html { redirect_to(@log_event) }
|
||||
format.xml { render :xml => @log_event, :status => :created, :location => @log_event }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
format.xml { render :xml => @log_event.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PUT /log_events/1
|
||||
# PUT /log_events/1.xml
|
||||
def update
|
||||
@log_event = LogEvent.find(params[:id])
|
||||
|
||||
respond_to do |format|
|
||||
if @log_event.update_attributes(params[:log_event])
|
||||
flash[:notice] = t(:logevent_update)
|
||||
format.html { redirect_to(@log_event) }
|
||||
format.xml { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
format.xml { render :xml => @log_event.errors, :status => :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /log_events/1
|
||||
# DELETE /log_events/1.xml
|
||||
def destroy
|
||||
@log_event = LogEvent.find(params[:id])
|
||||
@log_event.destroy
|
||||
|
||||
respond_to do |format|
|
||||
format.html { redirect_to(log_events_url) }
|
||||
format.xml { head :ok }
|
||||
end
|
||||
end
|
||||
end
|
42
app/controllers/log_files_controller.rb
Normal file
42
app/controllers/log_files_controller.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
class LogFilesController < ApplicationController
|
||||
def index
|
||||
LogFile.process
|
||||
render :text => "Ok"
|
||||
end
|
||||
|
||||
def handle
|
||||
LogFile.find(params[:id]).deal
|
||||
render :text => "Ok"
|
||||
end
|
||||
|
||||
def refresh
|
||||
LogFile.unhandled.each do |lf|
|
||||
lf.deal
|
||||
end
|
||||
end
|
||||
|
||||
def fix
|
||||
Rounder.find_in_batches(:batch_size => 100) do |rounders|
|
||||
rounders.each do |r|
|
||||
r.team_id = nil
|
||||
if r.user and t = Teamer.historic(r.user, r.round.start).first
|
||||
r.team_id = t.team_id
|
||||
end
|
||||
r.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def pix
|
||||
Round.all.each do |r|
|
||||
r.team1_id = nil
|
||||
r.team2_id = nil
|
||||
[1, 2].each do |team|
|
||||
if s = r.rounders.team(team).stats.first
|
||||
r["team#{team}_id"] = s["team_id"]
|
||||
end
|
||||
end
|
||||
r.save
|
||||
end
|
||||
end
|
||||
end
|
53
app/controllers/maps_controller.rb
Normal file
53
app/controllers/maps_controller.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
class MapsController < ApplicationController
|
||||
before_filter :get_map, :only => [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
@maps = Map.basic
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
@map = Map.new
|
||||
raise AccessError unless @map.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @map.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@map = Map.new params[:map]
|
||||
raise AccessError unless @map.can_create? cuser
|
||||
|
||||
if @map.save
|
||||
flash[:notice] = t(:maps_create)
|
||||
redirect_to @map
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @map.can_update? cuser
|
||||
if @map.update_attributes(params[:map])
|
||||
flash[:notice] = t(:maps_update)
|
||||
redirect_to @map
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @map.can_destroy? cuser
|
||||
@map.destroy
|
||||
redirect_to(maps_url)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_map
|
||||
@map = Map.find params[:id]
|
||||
end
|
||||
end
|
105
app/controllers/matches_controller.rb
Normal file
105
app/controllers/matches_controller.rb
Normal file
|
@ -0,0 +1,105 @@
|
|||
class MatchesController < ApplicationController
|
||||
before_filter :get_match, :except => [:index, :new, :create]
|
||||
|
||||
def index
|
||||
@matches = Match.active
|
||||
end
|
||||
|
||||
def show
|
||||
@ownpred = @match.predictions.first :conditions => {:user_id => cuser.id} if cuser
|
||||
@newpred = @match.predictions.build
|
||||
end
|
||||
|
||||
def new
|
||||
@match = Match.new
|
||||
@match.contest = Contest.find params[:id]
|
||||
raise AccessError unless @match.can_create? cuser
|
||||
end
|
||||
|
||||
def extra
|
||||
end
|
||||
|
||||
def score
|
||||
raise AccessError unless @match.can_update? cuser, [:matchers_attributes]
|
||||
@contester = @match.contester1.team.is_leader?(cuser) ? @match.contester1 : @match.contester2
|
||||
@n = 0
|
||||
end
|
||||
|
||||
def ref
|
||||
raise AccessError unless @match.can_update? cuser, [:report]
|
||||
@n = 0
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @match.can_update? cuser, [:contester1_id]
|
||||
end
|
||||
|
||||
def create
|
||||
@match = Match.new params[:match]
|
||||
raise AccessError unless @match.can_create? cuser
|
||||
|
||||
if @match.save
|
||||
flash[:notice] = t(:matches_create)
|
||||
redirect_to :controller => "contests", :action => "edit", :id => @match.contest
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @match.can_update? cuser, params[:match]
|
||||
if params[:match][:matchers_attributes]
|
||||
params[:match][:matchers_attributes].each do |key, matcher|
|
||||
matcher['_destroy'] = matcher['_destroy'] == "keep" ? false : true
|
||||
if matcher['user_id'] == ""
|
||||
params[:match][:matchers_attributes].delete key
|
||||
elsif matcher['user_id'].to_i == 0
|
||||
matcher['user_id'] = User.find_by_username(matcher['user_id']).id
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if @match.update_attributes params[:match]
|
||||
respond_to do |format|
|
||||
format.xml { head :ok }
|
||||
format.html do
|
||||
flash[:notice] = t(:matches_update)
|
||||
#redirect_to_back
|
||||
redirect_to @match
|
||||
end
|
||||
end
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def hltv
|
||||
raise AccessError unless @match.can_update? cuser, [:hltv]
|
||||
|
||||
if params[:commit].include? t(:hltv_send)
|
||||
@match.hltv_record params[:addr], params[:pwd]
|
||||
flash[:notice] = t(:hltv_recording)
|
||||
elsif params[:commit].include? t(:hltv_move)
|
||||
sleep(90) if params[:wait] == "1"
|
||||
@match.hltv_move params[:addr], params[:pwd]
|
||||
flash[:notice] = t(:hltv_moved)
|
||||
elsif params[:commit].include? t(:hltv_stop)
|
||||
sleep(90) if params[:wait] == "1"
|
||||
@match.hltv_stop
|
||||
flash[:notice] = t(:hltv_stopped)
|
||||
end
|
||||
redirect_to :action => "show"
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @match.can_destroy? cuser
|
||||
@match.destroy
|
||||
redirect_to :controller => "contests", :action => "edit", :id => @match.contest
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_match
|
||||
@match = Match.find params[:id]
|
||||
end
|
||||
end
|
49
app/controllers/messages_controller.rb
Normal file
49
app/controllers/messages_controller.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
class MessagesController < ApplicationController
|
||||
before_filter :get_message, :only => [:show, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
raise AccessError unless cuser
|
||||
end
|
||||
|
||||
def show
|
||||
raise AccessError unless @message.can_show? cuser
|
||||
@message.read_by! cuser
|
||||
@messages = @message.thread
|
||||
end
|
||||
|
||||
def new
|
||||
@message = Message.new
|
||||
raise AccessError unless @message.can_create? cuser
|
||||
|
||||
case params[:id]
|
||||
when "User"
|
||||
@message.recipient = User.find(params[:id2])
|
||||
when "Team"
|
||||
@message.recipient = Team.find(params[:id2])
|
||||
when "Group"
|
||||
@message.recipient = Group.find(params[:id2])
|
||||
else
|
||||
raise Error, "Illegible recipient"
|
||||
end
|
||||
@message.title = params[:title]
|
||||
end
|
||||
|
||||
def create
|
||||
@message = Message.new(params[:message])
|
||||
@message.sender = @message.sender_raw == "" ? cuser : cuser.active_teams.find(@message.sender_raw)
|
||||
raise AccessError unless @message.can_create? cuser
|
||||
|
||||
if @message.save
|
||||
flash[:notice] = t(:message_create)
|
||||
redirect_to(@message)
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_message
|
||||
@message = Message.find(params[:id])
|
||||
end
|
||||
end
|
97
app/controllers/movies_controller.rb
Normal file
97
app/controllers/movies_controller.rb
Normal file
|
@ -0,0 +1,97 @@
|
|||
class MoviesController < ApplicationController
|
||||
before_filter :get_movie, :except => [:index, :new, :create]
|
||||
|
||||
def index
|
||||
@movies = []
|
||||
order = case params[:order]
|
||||
when "date" then "data_files.created_at DESC"
|
||||
when "author" then "users.username ASC"
|
||||
when "ratings" then "total_ratings DESC"
|
||||
else "total_ratings DESC"
|
||||
end
|
||||
|
||||
if params[:filter]
|
||||
Movie.index(order).each do |movie|
|
||||
if movie.file and movie.file.average_rating_round >= params[:filter].to_i
|
||||
@movies << movie
|
||||
end
|
||||
end
|
||||
else
|
||||
@movies = Movie.index(order)
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@movie.read_by! cuser if cuser
|
||||
@movie.record_view_count(request.remote_ip, cuser.nil?)
|
||||
redirect_to @movie.file.related if @movie.file and @movie.file.related
|
||||
end
|
||||
|
||||
def refresh
|
||||
@movie.update_status
|
||||
end
|
||||
|
||||
def new
|
||||
@movie = Movie.new
|
||||
raise AccessError unless @movie.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @movie.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@movie = Movie.new(params[:movie])
|
||||
raise AccessError unless @movie.can_create? cuser
|
||||
|
||||
if @movie.save
|
||||
flash[:notice] = t(:movies_create)
|
||||
redirect_to(@movie)
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @movie.can_update? cuser
|
||||
|
||||
if @movie.update_attributes(params[:movie])
|
||||
flash[:notice] = t(:movies_update)
|
||||
redirect_to(@movie)
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def preview
|
||||
raise AccessError unless @movie.can_update? cuser
|
||||
x = params[:x].to_i <= 1280 ? params[:x].to_i : 800
|
||||
y = params[:y].to_i <= 720 ? params[:y].to_i : 600
|
||||
render :text => t(:executed) + "<br />" + @movie.make_preview(x, y), :layout => true
|
||||
end
|
||||
|
||||
def snapshot
|
||||
raise AccessError unless @movie.can_update? cuser
|
||||
secs = params[:secs].to_i > 0 ? params[:secs].to_i : 5
|
||||
render :text => t(:executed) + "<br />" + @movie.make_snapshot(secs), :layout => true
|
||||
end
|
||||
|
||||
def download
|
||||
raise AccessError unless cuser.admin?
|
||||
@movie.stream_ip = params[:ip]
|
||||
@movie.stream_port = params[:port]
|
||||
render :text => t(:executed) + "<br />" + @movie.make_stream, :layout => true
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @movie.can_destroy? cuser
|
||||
@movie.destroy
|
||||
redirect_to(movies_url)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_movie
|
||||
@movie = Movie.find(params[:id])
|
||||
end
|
||||
end
|
43
app/controllers/options_controller.rb
Normal file
43
app/controllers/options_controller.rb
Normal file
|
@ -0,0 +1,43 @@
|
|||
class PollsController < ApplicationController
|
||||
before_filter :get_poll, :except => [:index, :new, :create]
|
||||
respond_to :js
|
||||
|
||||
def add
|
||||
end
|
||||
|
||||
def create
|
||||
@poll = Poll.new params[:poll]
|
||||
@poll.user = cuser
|
||||
raise AccessError unless @poll.can_create? cuser
|
||||
|
||||
if @poll.save
|
||||
flash[:notice] = t(:polls_create)
|
||||
redirect_to @poll
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @poll.can_update? cuser
|
||||
|
||||
if @poll.update_attributes params[:poll]
|
||||
flash[:notice] = t(:polls_update)
|
||||
redirect_to @poll
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @poll.can_destroy? cuser
|
||||
@poll.destroy
|
||||
redirect_to polls_url
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_poll
|
||||
@poll = Poll.find params[:id]
|
||||
end
|
||||
end
|
128
app/controllers/plugin_controller.rb
Normal file
128
app/controllers/plugin_controller.rb
Normal file
|
@ -0,0 +1,128 @@
|
|||
class PluginController < ApplicationController
|
||||
def esi
|
||||
buffer = []
|
||||
out = []
|
||||
buffer << Time.now.utc.to_i
|
||||
buffer << "1.2"
|
||||
buffer << params[:ch] ? params[:ch] : ""
|
||||
out << "#ESI#"
|
||||
out << Verification.verify(buffer.join)
|
||||
out << buffer.join("\r")
|
||||
render_out out
|
||||
end
|
||||
|
||||
def user
|
||||
buffer = []
|
||||
out = []
|
||||
|
||||
if ban = Ban.first(:conditions => ["expiry > UTC_TIMESTAMP() AND steamid = ? AND ban_type = ?", params[:id], Ban::TYPE_SERVER])
|
||||
out << "#USER#"
|
||||
out << "BANNED"
|
||||
out << ban.expiry.utc.to_i
|
||||
out << ban.reason
|
||||
out << "\r\r\r\r\r\r\r"
|
||||
elsif user = User.first(:conditions => {:steamid => params[:id]})
|
||||
teamer = (user.team ? user.teamers.active.of_team(user.team).first : nil)
|
||||
icon = 0
|
||||
rank = "User"
|
||||
if Group.find(Group::DONORS).users.exists?(user)
|
||||
rank = "Donor"
|
||||
icon = icon | 1
|
||||
end
|
||||
if Group.find(Group::CHAMPIONS).users.exists?(user)
|
||||
icon = icon | 2
|
||||
end
|
||||
if user.ref?
|
||||
rank = "Referee"
|
||||
icon = icon | 4
|
||||
end
|
||||
if user.admin?
|
||||
rank = "Admin"
|
||||
icon = icon | 8
|
||||
end
|
||||
|
||||
buffer << user.steamid
|
||||
buffer << user.username
|
||||
buffer << user.lastip
|
||||
buffer << (user.team ? Verification.uncrap(user.team.to_s) : "No Team")
|
||||
buffer << user.id
|
||||
buffer << user.team_id
|
||||
buffer << rank
|
||||
buffer << (teamer ? teamer.ranks[teamer.rank] : "")
|
||||
buffer << icon
|
||||
buffer << params[:ch] ? params[:ch] : ""
|
||||
buffer << (user.can_play? ? "1" : "0")
|
||||
|
||||
out << "#USER#"
|
||||
out << Verification.verify(buffer.join)
|
||||
out << buffer.join("\r")
|
||||
else
|
||||
out << "#FAIL#"
|
||||
end
|
||||
|
||||
render_out out
|
||||
end
|
||||
|
||||
#def admin
|
||||
# areq = AdminRequest.new
|
||||
# areq.addr = params[:addr]
|
||||
# areq.pwd = params[:pwd]
|
||||
# areq.msg = params[:msg]
|
||||
# areq.player = params[:player]
|
||||
# areq.user_id = params[:user]
|
||||
# areq.save!
|
||||
# render :text => "Ok"
|
||||
#end
|
||||
|
||||
def ban
|
||||
ban = Ban.new
|
||||
ban.steamid = params[:id]
|
||||
ban.ts = params[:ts]
|
||||
ban.sign = params[:sign]
|
||||
ban.expiry = DateTime.now.ago(-(params[:len].to_i*60))
|
||||
ban.addr = params[:addr]
|
||||
ban.reason = params[:reason]
|
||||
ban.ban_type = Ban::TYPE_SERVER
|
||||
ban.save!
|
||||
|
||||
render :text => "Ok"
|
||||
end
|
||||
|
||||
def hltv_req
|
||||
if params[:game].to_i > 0
|
||||
if match = Match.first(:conditions => {:id => params[:game]})
|
||||
match.hltv_record params[:addr], params[:pwd]
|
||||
hltv = match.hltv
|
||||
else
|
||||
render :text => t(:matches_notfound)
|
||||
end
|
||||
else
|
||||
hltv = Server.hltvs.active.unreserved_now.unreserved_hltv_around(DateTime.now).first unless hltv
|
||||
render :text => t(:hltv_notavailable) unless hltv
|
||||
|
||||
hltv.recording = params[:game]
|
||||
hltv.reservation = params[:addr]
|
||||
hltv.pwd = params[:pwd]
|
||||
hltv.save!
|
||||
end
|
||||
|
||||
render :text => t(:hltv_sent)
|
||||
end
|
||||
|
||||
def hltv_move
|
||||
Server.move params[:addr], params[:newaddr], params[:newpwd]
|
||||
render :text => t(:hltv_movedd) + params[:newaddr]
|
||||
end
|
||||
|
||||
def hltv_stop
|
||||
Server.stop params[:addr]
|
||||
render :text => t(:hltv_stopped)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def render_out out
|
||||
@text = out.join("\r")
|
||||
render :layout => false
|
||||
end
|
||||
end
|
56
app/controllers/polls_controller.rb
Normal file
56
app/controllers/polls_controller.rb
Normal file
|
@ -0,0 +1,56 @@
|
|||
class PollsController < ApplicationController
|
||||
before_filter :get_poll, :except => [:index, :new, :create]
|
||||
|
||||
def index
|
||||
@polls = Poll.all
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
@poll = Poll.new
|
||||
@poll.options.build
|
||||
raise AccessError unless @poll.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @poll.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@poll = Poll.new params[:poll]
|
||||
@poll.user = cuser
|
||||
raise AccessError unless @poll.can_create? cuser
|
||||
|
||||
if @poll.save
|
||||
flash[:notice] = t(:polls_create)
|
||||
redirect_to @poll
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @poll.can_update? cuser
|
||||
|
||||
if @poll.update_attributes params[:poll]
|
||||
flash[:notice] = t(:polls_update)
|
||||
redirect_to @poll
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @poll.can_destroy? cuser
|
||||
@poll.destroy
|
||||
redirect_to polls_url
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_poll
|
||||
@poll = Poll.find params[:id]
|
||||
end
|
||||
end
|
72
app/controllers/posts_controller.rb
Normal file
72
app/controllers/posts_controller.rb
Normal file
|
@ -0,0 +1,72 @@
|
|||
class PostsController < ApplicationController
|
||||
before_filter :get_post, :except => [:new, :create]
|
||||
respond_to :html, :js
|
||||
|
||||
def quote
|
||||
raise AccessError unless @post.can_show? cuser
|
||||
end
|
||||
|
||||
def new
|
||||
@post = Post.new
|
||||
@post.topic = Topic.find(params[:id])
|
||||
raise AccessError unless @post.can_create? cuser
|
||||
render :layout => "forums"
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @post.can_update? cuser
|
||||
render :layout => "forums"
|
||||
end
|
||||
|
||||
def create
|
||||
@post = Post.new(params[:post])
|
||||
@post.user = cuser
|
||||
raise AccessError unless @post.can_create? cuser
|
||||
|
||||
respond_to do |format|
|
||||
if @post.save
|
||||
flash[:notice] = t(:posts_create)
|
||||
format.js { render }
|
||||
else
|
||||
flash[:error] = t(:posts_invalid) + @post.errors.full_messages.to_s
|
||||
format.html { return_to }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @post.can_update? cuser, params[:post]
|
||||
if @post.update_attributes(params[:post])
|
||||
flash[:notice] = t(:posts_update)
|
||||
redirect_to @post.topic
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def trash
|
||||
raise AccessError unless @post.can_destroy? cuser
|
||||
@post.trash
|
||||
if Topic.exists? @post.topic
|
||||
redirect_to @post.topic
|
||||
else
|
||||
redirect_to @post.topic.forum
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @post.can_destroy? cuser
|
||||
@post.destroy
|
||||
if Topic.exists? @post.topic
|
||||
redirect_to @post.topic
|
||||
else
|
||||
redirect_to @post.topic.forum
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_post
|
||||
@post = Post.find(params[:id])
|
||||
end
|
||||
end
|
15
app/controllers/predictions_controller.rb
Normal file
15
app/controllers/predictions_controller.rb
Normal file
|
@ -0,0 +1,15 @@
|
|||
class PredictionsController < ApplicationController
|
||||
def create
|
||||
@prediction = Prediction.new params[:prediction]
|
||||
@prediction.user = cuser
|
||||
raise AccessError unless @prediction.can_create? cuser
|
||||
|
||||
if @prediction.save
|
||||
flash[:notice] = t(:predictions_create)
|
||||
else
|
||||
flash[:error] = @prediction.errors.full_messages.to_s
|
||||
end
|
||||
|
||||
redirect_to @prediction.match
|
||||
end
|
||||
end
|
26
app/controllers/rounds_controller.rb
Normal file
26
app/controllers/rounds_controller.rb
Normal file
|
@ -0,0 +1,26 @@
|
|||
class RoundsController < ApplicationController
|
||||
def index
|
||||
sort = case params['sort']
|
||||
when "start" then "start"
|
||||
when "server" then "server_id"
|
||||
when "team1" then "team1_id"
|
||||
when "team2" then "team2_id"
|
||||
when "map" then "map_name"
|
||||
when "commander" then "commander_id"
|
||||
end
|
||||
|
||||
@rounds = Round.basic.paginate \
|
||||
:order => sort,
|
||||
:page => params[:page],
|
||||
:per_page => 30
|
||||
|
||||
if params[:ajax]
|
||||
render :partial => "list", :layout => false
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@round = Round.find(params[:id])
|
||||
end
|
||||
end
|
78
app/controllers/servers_controller.rb
Normal file
78
app/controllers/servers_controller.rb
Normal file
|
@ -0,0 +1,78 @@
|
|||
class ServersController < ApplicationController
|
||||
before_filter :get_server, :except => [:index, :refresh, :new, :create]
|
||||
|
||||
def refresh
|
||||
Server.refresh
|
||||
render :text => t(:servers_updated)
|
||||
end
|
||||
|
||||
def index
|
||||
@servers = Server.hlds.active.ordered.all :include => :user
|
||||
@ns2 = Server.ns2.active.ordered.all :include => :user
|
||||
@hltvs = Server.hltvs.active.ordered.all :include => :user
|
||||
@officials = Server.ns2.active.ordered.where ["name LIKE ?", "%NSL%"]
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
@server = Server.new
|
||||
raise AccessError unless @server.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @server.can_update? cuser
|
||||
end
|
||||
|
||||
def admin
|
||||
@result = @server.execute params[:query] if params[:query]
|
||||
raise AccessError unless @server.can_update? cuser
|
||||
|
||||
if request.xhr?
|
||||
render :partial => "response", :layout => false
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@server = Server.new params[:server]
|
||||
@server.user = cuser
|
||||
raise AccessError unless @server.can_create? cuser
|
||||
|
||||
if @server.save
|
||||
flash[:notice] = t(:server_create)
|
||||
redirect_to @server
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @server.can_update? cuser
|
||||
|
||||
if @server.update_attributes params[:server]
|
||||
flash[:notice] = t(:server_update)
|
||||
redirect_to @server
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def default
|
||||
raise AccessError unless @server.can_update? cuser
|
||||
@server.default_record
|
||||
render :text => "Ok"
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @server.can_destroy? cuser
|
||||
@server.destroy
|
||||
redirect_to(servers_url)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_server
|
||||
@server = Server.find params[:id]
|
||||
end
|
||||
end
|
39
app/controllers/shoutmsgs_controller.rb
Normal file
39
app/controllers/shoutmsgs_controller.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
class ShoutmsgsController < ApplicationController
|
||||
respond_to :html, :js
|
||||
|
||||
def index
|
||||
@shoutmsgs = Shoutmsg.lastXXX.typebox
|
||||
end
|
||||
|
||||
def show
|
||||
if params[:id2]
|
||||
@shoutmsgs = Shoutmsg.recent.of_object(params[:id], params[:id2]).reverse
|
||||
else
|
||||
@shoutmsgs = Shoutmsg.recent.box
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@shoutmsg = Shoutmsg.new params[:shoutmsg]
|
||||
@shoutmsg.user = cuser
|
||||
raise AccessError unless @shoutmsg.can_create? cuser
|
||||
|
||||
unless @shoutmsg.save
|
||||
flash[:error] = t(:invalid_message)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@shoutmsg = Shoutmsg.find params[:id]
|
||||
raise AccessError unless @shoutmsg.can_destroy? cuser
|
||||
@shoutmsg.destroy
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def render_shoutmsgs shoutable_type = nil, shoutable_id = nil
|
||||
|
||||
end
|
||||
end
|
23
app/controllers/teamers_controller.rb
Normal file
23
app/controllers/teamers_controller.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
class TeamersController < ApplicationController
|
||||
def create
|
||||
@teamer = Teamer.new params[:teamer]
|
||||
raise AccessError unless @teamer.can_create? cuser, params[:teamer]
|
||||
@teamer.user = cuser unless cuser.admin?
|
||||
|
||||
if @teamer.save
|
||||
flash[:notice] = t(:applying_team) + @teamer.team.to_s
|
||||
else
|
||||
flash[:error] = @teamer.errors.full_messages.to_s
|
||||
end
|
||||
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
def destroy
|
||||
@teamer = Teamer.find params[:id]
|
||||
raise AccessError unless @teamer.can_destroy? cuser
|
||||
|
||||
@teamer.destroy
|
||||
redirect_to_back
|
||||
end
|
||||
end
|
72
app/controllers/teams_controller.rb
Normal file
72
app/controllers/teams_controller.rb
Normal file
|
@ -0,0 +1,72 @@
|
|||
class TeamsController < ApplicationController
|
||||
before_filter :get_team, :only => ['show', 'edit', 'update', 'destroy', 'recover']
|
||||
|
||||
def index
|
||||
@teams = Team.with_teamers_num(0).ordered
|
||||
end
|
||||
|
||||
def show
|
||||
end
|
||||
|
||||
def new
|
||||
@team = Team.new
|
||||
raise AccessError unless @team.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @team.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@team = Team.new params[:team]
|
||||
@team.founder = cuser
|
||||
raise AccessError unless @team.can_create? cuser
|
||||
|
||||
if @team.save
|
||||
flash[:notice] = t(:teams_create)
|
||||
redirect_to @team
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @team.can_update? cuser
|
||||
if @team.update_attributes params[:team]
|
||||
if params[:rank]
|
||||
@team.teamers.present.each do |member|
|
||||
rank = params[:rank]["#{member.id}"]
|
||||
if cuser.admin? or (rank.to_i <= cuser.teamers.active.of_team(@team).first.rank)
|
||||
if member.rank == Teamer::RANK_JOINER
|
||||
member.user.update_attribute :team, @team
|
||||
end
|
||||
member.update_attribute :rank, rank
|
||||
member.update_attribute :comment, params[:comment]["#{member.id}"]
|
||||
end
|
||||
end
|
||||
end
|
||||
flash[:notice] = t(:teams_update)
|
||||
redirect_to edit_team_path(@team)
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @team.can_destroy? cuser
|
||||
@team.destroy
|
||||
redirect_to(teams_url)
|
||||
end
|
||||
|
||||
def recover
|
||||
raise AccessError unless @team.can_destroy? cuser
|
||||
@team.recover
|
||||
redirect_to(teams_url)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_team
|
||||
@team = Team.find params[:id]
|
||||
end
|
||||
end
|
81
app/controllers/topics_controller.rb
Normal file
81
app/controllers/topics_controller.rb
Normal file
|
@ -0,0 +1,81 @@
|
|||
class TopicsController < ApplicationController
|
||||
before_filter :get_topic, :only => [:show, :reply, :edit, :update, :destroy]
|
||||
|
||||
def index
|
||||
render :partial => true, :locals => {:page => params[:p].to_i}
|
||||
end
|
||||
|
||||
def show
|
||||
raise AccessError unless @topic.can_show? cuser
|
||||
@posts = @topic.posts.basic.paginate \
|
||||
:page => params[:page],
|
||||
:per_page => Topic::POSTS_PAGE
|
||||
|
||||
return_here
|
||||
@topic.record_view_count(request.remote_ip, cuser.nil?)
|
||||
@topic.read_by! cuser if cuser
|
||||
@topic.forum.read_by! cuser if cuser
|
||||
@newpost = Post.new
|
||||
@newpost.topic = @topic
|
||||
@newpost.user = cuser
|
||||
@lock = (@topic.lock ? @topic.lock : Lock.new(:lockable => @topic))
|
||||
render :layout => "forums"
|
||||
end
|
||||
|
||||
def reply
|
||||
@post = @topic.posts.build
|
||||
raise AccessError unless @post.can_create? cuser
|
||||
if request.xhr?
|
||||
render "quickreply", :layout => false
|
||||
else
|
||||
render :layout => "forums"
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@topic = Topic.new
|
||||
@topic.forum = Forum.find(params[:id])
|
||||
raise AccessError unless @topic.can_create? cuser
|
||||
render :layout => "forums"
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @topic.can_update? cuser
|
||||
render :layout => "forums"
|
||||
end
|
||||
|
||||
def create
|
||||
@topic = Topic.new(params[:topic])
|
||||
@topic.user = cuser
|
||||
raise AccessError unless @topic.can_create? cuser
|
||||
|
||||
if @topic.save
|
||||
flash[:notice] = t(:topics_create)
|
||||
redirect_to(@topic)
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @topic.can_update? cuser
|
||||
if @topic.update_attributes(params[:topic])
|
||||
flash[:notice] = t(:topics_update)
|
||||
redirect_to(@topic)
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @topic.can_destroy? cuser
|
||||
@topic.destroy
|
||||
redirect_to(topics_url)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_topic
|
||||
@topic = Topic.find(params[:id])
|
||||
end
|
||||
end
|
29
app/controllers/tweets_controller.rb
Normal file
29
app/controllers/tweets_controller.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
require 'rss/2.0'
|
||||
require 'open-uri'
|
||||
|
||||
class TweetsController < ApplicationController
|
||||
def index
|
||||
@tweets = Tweet.all :order => "created_at DESC"
|
||||
@nobody = true
|
||||
end
|
||||
|
||||
def show
|
||||
@tweet = Tweet.find(params[:id])
|
||||
end
|
||||
|
||||
def refresh
|
||||
open('http://twitter.com/statuses/user_timeline/16676427.rss') do |http|
|
||||
RSS::Parser.parse(http.read, false).items.each do |item|
|
||||
unless Tweet.first :conditions => {:link => item.link}
|
||||
tweet = Tweet.new
|
||||
tweet.link = item.link
|
||||
tweet.msg = item.title.gsub(/NS2: /, "")
|
||||
tweet.created_at = DateTime.parse item.pubDate.to_s
|
||||
tweet.save
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
render :text => t(:tweets_refresh)
|
||||
end
|
||||
end
|
130
app/controllers/users_controller.rb
Normal file
130
app/controllers/users_controller.rb
Normal file
|
@ -0,0 +1,130 @@
|
|||
class UsersController < ApplicationController
|
||||
before_filter :get_user, :only => [:show, :history, :popup, :agenda, :edit, :update, :destroy]
|
||||
respond_to :html, :js
|
||||
|
||||
def index
|
||||
@users = User.search(params[:search]).paginate(:per_page => 40, :page => params[:page])
|
||||
end
|
||||
|
||||
def show
|
||||
@page = "general"
|
||||
respond_to do |format|
|
||||
format.js do
|
||||
pages = ["general", "favorites", "computer", "articles", "movies", "teams", "matches", "predictions", "comments"]
|
||||
if pages.include?(params[:page])
|
||||
@page = params[:page]
|
||||
end
|
||||
end
|
||||
format.html {}
|
||||
end
|
||||
end
|
||||
|
||||
def agenda
|
||||
@teamer = Teamer.new
|
||||
@teamer.user = @user
|
||||
end
|
||||
|
||||
def history
|
||||
raise AccessError unless cuser and cuser.admin?
|
||||
end
|
||||
|
||||
def popup
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def new
|
||||
@user = User.new
|
||||
@user.profile = Profile.new
|
||||
@user.lastip = request.env['REMOTE_ADDR']
|
||||
@user.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @user.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@user = User.new params[:user]
|
||||
@user.lastvisit = Date.today
|
||||
@user.lastip = request.env['REMOTE_ADDR']
|
||||
|
||||
raise AccessError unless @user.can_create? cuser
|
||||
|
||||
if @user.valid? and @user.save
|
||||
@user.profile = Profile.new
|
||||
@user.profile.user = @user
|
||||
@user.profile.save()
|
||||
redirect_to :action => :show, :id => @user.id
|
||||
save_session @user
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @user.can_update? cuser
|
||||
if @user.update_attributes params[:user]
|
||||
flash[:notice] = t(:users_update)
|
||||
redirect_to_back
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @user.can_destroy? cuser
|
||||
@user.destroy
|
||||
redirect_to users_url
|
||||
end
|
||||
|
||||
def login
|
||||
return unless request.post?
|
||||
|
||||
if u = User.authenticate(params[:login][:username], params[:login][:password])
|
||||
raise Error, t(:accounts_locked) if u.banned? Ban::TYPE_SITE
|
||||
|
||||
flash[:notice] = t(:login_successful)
|
||||
save_session u
|
||||
|
||||
if session[:return_to]
|
||||
return_to
|
||||
else
|
||||
redirect_to_back
|
||||
end
|
||||
else
|
||||
flash[:error] = t(:login_unsuccessful)
|
||||
redirect_to_back
|
||||
end
|
||||
end
|
||||
|
||||
def logout
|
||||
if request.post?
|
||||
session[:user] = nil
|
||||
flash[:notice] = t(:login_out)
|
||||
redirect_to :root
|
||||
end
|
||||
end
|
||||
|
||||
def forgot
|
||||
if request.post?
|
||||
if u = User.first(:conditions => {:username => params[:username], :email => params[:email]}) and u.send_new_password
|
||||
flash[:notice] = t(:passwords_sent)
|
||||
else
|
||||
flash[:error] = t(:incorrect_information)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_user
|
||||
@user = User.find(params[:id])
|
||||
end
|
||||
|
||||
def save_session user
|
||||
session[:user] = user.id
|
||||
user.lastip = request.ip
|
||||
user.lastvisit = DateTime.now
|
||||
user.save()
|
||||
end
|
||||
end
|
32
app/controllers/versions_controller.rb
Normal file
32
app/controllers/versions_controller.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
class VersionsController < ApplicationController
|
||||
before_filter :get_article
|
||||
|
||||
def index
|
||||
@versions = @article.versions
|
||||
render "articles/history"
|
||||
end
|
||||
|
||||
def show
|
||||
@version = @article.versions.find params[:id]
|
||||
@nobody = true
|
||||
render "articles/version"
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @article.can_update? cuser
|
||||
@version = @article.versions.find params[:id]
|
||||
@nobody = true
|
||||
|
||||
if @article.revert_to! @version.version
|
||||
flash[:notice] = t(:articles_revert, :version => @version.version)
|
||||
end
|
||||
|
||||
redirect_to @article
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_article
|
||||
@article = Article.find(params[:article_id])
|
||||
end
|
||||
end
|
13
app/controllers/votes_controller.rb
Normal file
13
app/controllers/votes_controller.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
class VotesController < ApplicationController
|
||||
def create
|
||||
@vote = Vote.new params[:vote]
|
||||
@vote.user = cuser
|
||||
raise AccessError unless @vote.can_create? cuser
|
||||
|
||||
if @vote.save
|
||||
flash[:notice] = t(:votes_success)
|
||||
end
|
||||
|
||||
redirect_to_back
|
||||
end
|
||||
end
|
48
app/controllers/weeks_controller.rb
Normal file
48
app/controllers/weeks_controller.rb
Normal file
|
@ -0,0 +1,48 @@
|
|||
class WeeksController < ApplicationController
|
||||
before_filter :get_week, :except => [:new, :create]
|
||||
|
||||
def new
|
||||
@week = Week.new
|
||||
@week.contest = Contest.find params[:id]
|
||||
raise AccessError unless @week.can_create? cuser
|
||||
end
|
||||
|
||||
def edit
|
||||
raise AccessError unless @week.can_update? cuser
|
||||
end
|
||||
|
||||
def create
|
||||
@week = Week.new(params[:week])
|
||||
raise AccessError unless @week.can_create? cuser
|
||||
|
||||
if @week.save
|
||||
flash[:notice] = t(:weeks_create)
|
||||
redirect_to @week.contest
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
raise AccessError unless @week.can_update? cuser
|
||||
|
||||
if @week.update_attributes(params[:week])
|
||||
flash[:notice] = t(:weeks_update)
|
||||
redirect_to @week.contest
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
raise AccessError unless @week.can_destroy? cuser
|
||||
@week.destroy
|
||||
redirect_to_back
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_week
|
||||
@week = Week.find params[:id]
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue