Use admin? or teacher? for permission check instead of internal_user?
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
class AdminOrAuthorPolicy < ApplicationPolicy
|
||||
[:create?, :index?, :new?].each do |action|
|
||||
define_method(action) { @user.internal_user? }
|
||||
define_method(action) { admin? || teacher? }
|
||||
end
|
||||
|
||||
[:destroy?, :edit?, :show?, :update?].each do |action|
|
||||
|
@ -9,7 +9,7 @@ class ExercisePolicy < AdminOrAuthorPolicy
|
||||
end
|
||||
|
||||
def show?
|
||||
@user.internal_user?
|
||||
admin? || teacher?
|
||||
end
|
||||
|
||||
[:clone?, :destroy?, :edit?, :statistics?, :update?, :feedback?].each do |action|
|
||||
@ -24,7 +24,7 @@ class ExercisePolicy < AdminOrAuthorPolicy
|
||||
def resolve
|
||||
if @user.admin?
|
||||
@scope.all
|
||||
elsif @user.internal_user?
|
||||
elsif @user.teacher?
|
||||
@scope.where('user_id = ? OR public = TRUE', @user.id)
|
||||
else
|
||||
@scope.none
|
||||
|
@ -9,7 +9,7 @@ class InterventionPolicy < AdminOrAuthorPolicy
|
||||
end
|
||||
|
||||
def show?
|
||||
@user.internal_user?
|
||||
admin? || teacher?
|
||||
end
|
||||
|
||||
[:clone?, :destroy?, :edit?, :update?].each do |action|
|
||||
@ -24,7 +24,7 @@ class InterventionPolicy < AdminOrAuthorPolicy
|
||||
def resolve
|
||||
if @user.admin?
|
||||
@scope.all
|
||||
elsif @user.internal_user?
|
||||
elsif @user.teacher?
|
||||
@scope.where('user_id = ? OR public = TRUE', @user.id)
|
||||
else
|
||||
@scope.none
|
||||
|
@ -9,7 +9,7 @@ class ProxyExercisePolicy < AdminOrAuthorPolicy
|
||||
end
|
||||
|
||||
def show?
|
||||
@user.internal_user?
|
||||
admin? || teacher?
|
||||
end
|
||||
|
||||
[:clone?, :destroy?, :edit?, :update?].each do |action|
|
||||
@ -24,8 +24,8 @@ class ProxyExercisePolicy < AdminOrAuthorPolicy
|
||||
def resolve
|
||||
if @user.admin?
|
||||
@scope.all
|
||||
elsif @user.internal_user?
|
||||
@scope.where('user_id = ? OR public = TRUE', @user.id)
|
||||
elsif @user.teacher?
|
||||
@scope.where('user_id = ?', @user.id)
|
||||
else
|
||||
@scope.none
|
||||
end
|
||||
|
@ -9,7 +9,7 @@ class SearchPolicy < AdminOrAuthorPolicy
|
||||
end
|
||||
|
||||
def show?
|
||||
@user.internal_user?
|
||||
admin? || teacher?
|
||||
end
|
||||
|
||||
[:clone?, :destroy?, :edit?, :update?].each do |action|
|
||||
@ -24,7 +24,7 @@ class SearchPolicy < AdminOrAuthorPolicy
|
||||
def resolve
|
||||
if @user.admin?
|
||||
@scope.all
|
||||
elsif @user.internal_user?
|
||||
elsif @user.teacher?
|
||||
@scope.where('user_id = ? OR public = TRUE', @user.id)
|
||||
else
|
||||
@scope.none
|
||||
|
@ -9,7 +9,7 @@ class TagPolicy < AdminOrAuthorPolicy
|
||||
end
|
||||
|
||||
def show?
|
||||
@user.internal_user?
|
||||
admin? || teacher?
|
||||
end
|
||||
|
||||
[:clone?, :destroy?, :edit?, :update?].each do |action|
|
||||
@ -24,7 +24,7 @@ class TagPolicy < AdminOrAuthorPolicy
|
||||
def resolve
|
||||
if @user.admin?
|
||||
@scope.all
|
||||
elsif @user.internal_user?
|
||||
elsif @user.teacher?
|
||||
@scope.where('user_id = ? OR public = TRUE', @user.id)
|
||||
else
|
||||
@scope.none
|
||||
|
@ -1,4 +1,4 @@
|
||||
- if current_user.try(:internal_user?)
|
||||
- if current_user.try(:admin?) or current_user.try(:teacher?)
|
||||
ul.breadcrumb
|
||||
- if model = Kernel.const_get(controller_path.classify) rescue nil
|
||||
- object = model.find_by(id: params[:id])
|
||||
|
@ -1,4 +1,4 @@
|
||||
- if current_user.try(:internal_user?)
|
||||
- if current_user.try(:admin?) or current_user.try(:teacher?)
|
||||
ul.nav.navbar-nav
|
||||
li.nav-item.dropdown
|
||||
a.nav-link.dropdown-toggle.mx-3 data-toggle='dropdown' href='#'
|
||||
|
@ -5,10 +5,10 @@
|
||||
= current_user
|
||||
span.caret
|
||||
ul.dropdown-menu.p-0.mt-1 role='menu'
|
||||
- if current_user.internal_user?
|
||||
li = link_to(t('consumers.show.link'), current_user.consumer, class: 'dropdown-item') if current_user.consumer
|
||||
li = link_to(t('internal_users.show.link'), current_user, class: 'dropdown-item')
|
||||
li = link_to(t('request_for_comments.index.all'), request_for_comments_path, class: 'dropdown-item')
|
||||
- if current_user.try(:admin?) or current_user.try(:teacher?)
|
||||
li = link_to(t('consumers.show.link'), current_user.consumer, class: 'dropdown-item') if current_user.consumer and policy(current_user.consumer).show?
|
||||
li = link_to(t('internal_users.show.link'), current_user, class: 'dropdown-item') if policy(current_user).show?
|
||||
li = link_to(t('request_for_comments.index.all'), request_for_comments_path, class: 'dropdown-item') if policy(RequestForComment).index?
|
||||
li = link_to(t('request_for_comments.index.get_my_rfc_activity'), my_rfc_activity_path, class: 'dropdown-item')
|
||||
li = link_to(t('request_for_comments.index.get_my_comment_requests'), my_request_for_comments_path, class: 'dropdown-item')
|
||||
- if current_user.internal_user?
|
||||
|
@ -1,8 +1,8 @@
|
||||
h1 = t('.title', application_name: application_name)
|
||||
|
||||
- if current_user.try(:external_user?)
|
||||
p = t('.text_signed_in_as_external_user', application_name: application_name)
|
||||
- elsif current_user.try(:internal_user?)
|
||||
- if current_user.try(:admin?) or current_user.try(:teacher?)
|
||||
p = t('.text_signed_in_as_internal_user', user_name: current_user.name)
|
||||
- elsif current_user.try(:external_user?)
|
||||
p = t('.text_signed_in_as_external_user', application_name: application_name)
|
||||
- else
|
||||
p == t('.text_signed_out', application_name: application_name, sign_in_path: sign_in_path)
|
||||
|
@ -28,7 +28,7 @@ html lang='en'
|
||||
= render('session')
|
||||
.container data-controller=controller_name
|
||||
= render('flash')
|
||||
= render('breadcrumbs') if current_user.try(:internal_user?)
|
||||
= render('breadcrumbs') if current_user.try(:admin?) or current_user.try(:teacher?)
|
||||
- if (controller_name == "exercises" && action_name == "implement")
|
||||
.container-fluid
|
||||
= yield
|
||||
|
Reference in New Issue
Block a user