diff --git a/app/controllers/ajax/answer_controller.rb b/app/controllers/ajax/answer_controller.rb index 89051d0e..34e3324e 100644 --- a/app/controllers/ajax/answer_controller.rb +++ b/app/controllers/ajax/answer_controller.rb @@ -8,7 +8,7 @@ class Ajax::AnswerController < ApplicationController answer = Answer.find(params[:answer]) - unless answer.user == current_user || privileged? + unless privileged? answer.user @status = :nopriv @message = "check yuor privlegs" @success = false diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 581c63bf..994d1d5b 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -5,12 +5,8 @@ class ApplicationController < ActionController::Base before_filter :configure_permitted_parameters, if: :devise_controller? - def privileged? - if current_user && current_user.admin? - true - else - false - end + def privileged?(user) + (current_user == user && current_user.admin?) ? true : false end protected diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 80b666e4..78773e32 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -46,11 +46,7 @@ module ApplicationHelper count.count end - def privileged? - if current_user && current_user.admin? - true - else - false - end + def privileged?(user) + (current_user == user && current_user.admin?) ? true : false end end diff --git a/app/views/shared/_answerbox.html.haml b/app/views/shared/_answerbox.html.haml index 083b12d0..21e9eead 100644 --- a/app/views/shared/_answerbox.html.haml +++ b/app/views/shared/_answerbox.html.haml @@ -6,6 +6,6 @@ %hr/ %p= a.content %br/ - - if privileged? + - if privileged? a.user %button.btn.btn-danger{name: 'ab-destroy', 'data-a-id' => a.id} Delete \ No newline at end of file