Events: implement creation of new contests
This commit is contained in:
@@ -10,7 +10,7 @@ class ContestsController < ApplicationController
|
||||
def index
|
||||
authorize :contest
|
||||
|
||||
@contests = current_user.contests.includes([ :contestants, puzzles: [ :image_attachment ] ]).order(created_at: :desc)
|
||||
@contests = current_user.contests.where(event: nil).includes([ :contestants, puzzles: [ :image_attachment ] ]).order(created_at: :desc)
|
||||
@title = I18n.t("contests.index.title", username: current_user.username)
|
||||
end
|
||||
|
||||
@@ -125,6 +125,9 @@ class ContestsController < ApplicationController
|
||||
authorize :contest
|
||||
|
||||
@contest = Contest.new
|
||||
if params.key?(:event)
|
||||
@contest.event_id = params[:event]
|
||||
end
|
||||
@title = I18n.t("contests.new.title")
|
||||
@nonav = true
|
||||
end
|
||||
@@ -136,6 +139,18 @@ class ContestsController < ApplicationController
|
||||
@contest.lang = @current_user.lang
|
||||
@contest.ranking_mode = "actual"
|
||||
@contest.user_id = current_user.id
|
||||
|
||||
# Check if the provided event_id exists and belongs to the current user. If not, remove
|
||||
# the link to the event.
|
||||
begin
|
||||
event = Event.find(@contest.event_id)
|
||||
if current_user != event.user
|
||||
@contest.event_id = nil
|
||||
end
|
||||
rescue
|
||||
@contest.event_id = nil
|
||||
end
|
||||
|
||||
if @contest.save
|
||||
redirect_to "/contests/#{@contest.id}/settings/general", notice: t("contests.new.notice")
|
||||
else
|
||||
@@ -274,7 +289,7 @@ class ContestsController < ApplicationController
|
||||
end
|
||||
|
||||
def new_contest_params
|
||||
params.expect(contest: [ :name, :duration ])
|
||||
params.expect(contest: [ :name, :duration, :event_id ])
|
||||
end
|
||||
|
||||
def settings_general_params
|
||||
|
||||
Reference in New Issue
Block a user