Skip to content

Commit

Permalink
Show explicit messages when karma is too low to write contents
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Feb 18, 2017
1 parent 21c869a commit f94cf20
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions app/controllers/application_controller.rb
Expand Up @@ -17,6 +17,11 @@ def error_403
render file: "#{Rails.public_path}/errors/403.html", status: 403, layout: false
end

def not_enough_karma(content_type)
@content_type = content_type
render 'users/not_enough_karma', status: 403
end

def seo_filter
request.session_options[:secure] = request.ssl?
headers["X-Served-By"] = Process.pid.to_s
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/diaries_controller.rb
Expand Up @@ -19,11 +19,13 @@ def index
def new
@diary = current_user.diaries.build
@diary.cc_licensed = true
return not_enough_karma('journaux') unless @diary.creatable_by?(current_account)
enforce_create_permission(@diary)
end

def create
@diary = current_user.diaries.build
return not_enough_karma('journaux') unless @diary.creatable_by?(current_account)
enforce_create_permission(@diary)
@diary.attributes = diary_params
if !preview_mode && @diary.save
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/wiki_pages_controller.rb
Expand Up @@ -34,13 +34,15 @@ def show
def new
@wiki_page = WikiPage.new
@wiki_page.title = params[:title]
return not_enough_karma('pages de wiki') unless @wiki_page.creatable_by?(current_account)
enforce_create_permission(@wiki_page)
end

def create
@wiki_page = WikiPage.new
@wiki_page.attributes = wiki_params :title
@wiki_page.user_id = current_account.user_id
return not_enough_karma('pages de wiki') unless @wiki_page.creatable_by?(current_account)
enforce_create_permission(@wiki_page)
if !preview_mode && @wiki_page.save
redirect_to @wiki_page, notice: "Nouvelle page de wiki créée"
Expand All @@ -53,10 +55,12 @@ def create

def edit
@wiki_page.wiki_body = @wiki_page.versions.first.body
return not_enough_karma('pages de wiki') unless @wiki_page.updatable_by?(current_account)
enforce_update_permission(@wiki_page)
end

def update
return not_enough_karma('pages de wiki') unless @wiki_page.updatable_by?(current_account)
enforce_update_permission(@wiki_page)
@wiki_page.attributes = wiki_params
@wiki_page.user_id = current_account.user_id
Expand Down
5 changes: 5 additions & 0 deletions app/views/users/not_enough_karma.html.haml
@@ -0,0 +1,5 @@
=h1 "Karma insuffisant"
%p
En raison d'un #{link_to "karma trop faible", "/aide#aide-karma"},
ce compte n'est pas actuellement autorisé à écrire des #{@content_type} sur le site.
%img(src="/images/403.png" alt="")

0 comments on commit f94cf20

Please sign in to comment.