mirror of
https://github.com/projekteuler/projekteuler.git
synced 2026-01-26 18:18:51 +01:00
Allow admins to directly set translations
This commit is contained in:
@@ -1,8 +1,3 @@
|
||||
class AdminController < ApplicationController
|
||||
before_action :authenticate!
|
||||
|
||||
def authenticate!
|
||||
authenticate_user!
|
||||
throw(:warden) unless current_user.admin?
|
||||
end
|
||||
before_action :authenticate_admin!
|
||||
end
|
||||
@@ -2,4 +2,9 @@ class ApplicationController < ActionController::Base
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
def authenticate_admin!
|
||||
authenticate_user!
|
||||
throw(:warden) unless current_user.admin?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class TranslationsController < ApplicationController
|
||||
before_action :set_problem, only: [:new, :create]
|
||||
before_action :set_accept, only: [:create]
|
||||
|
||||
# GET /translations/new
|
||||
def new
|
||||
@@ -17,7 +18,12 @@ class TranslationsController < ApplicationController
|
||||
@translation.author = current_user
|
||||
end
|
||||
if @translation.save
|
||||
redirect_to @problem, notice: t('translations.notice.successfully_created')
|
||||
if @accept
|
||||
@problem.set_translation(@translation)
|
||||
redirect_to @problem, notice: t('translations.notice.successfully_created_and_accepted')
|
||||
else
|
||||
redirect_to @problem, notice: t('translations.notice.successfully_created')
|
||||
end
|
||||
else
|
||||
render :new
|
||||
end
|
||||
@@ -32,4 +38,12 @@ class TranslationsController < ApplicationController
|
||||
def set_problem
|
||||
@problem = Problem.find(params[:problem_id])
|
||||
end
|
||||
|
||||
def set_accept
|
||||
if user_signed_in? and current_user.admin?
|
||||
@accept = params.fetch(:accept, false)
|
||||
else
|
||||
@accept = false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -20,4 +20,7 @@
|
||||
<% end %>
|
||||
</div>
|
||||
<%= f.submit %>
|
||||
<% if user_signed_in? and current_user.admin? %>
|
||||
<%= f.button t('.save_and_accept'), type: :submit, name: "accept", value: true, class: "btn-success" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user