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