eliminated naming clash with Sorcery

This commit is contained in:
Hauke Klement
2015-02-23 10:39:04 +01:00
parent 2180c3878e
commit 466f8967e2
11 changed files with 35 additions and 15 deletions

View File

@ -26,7 +26,7 @@ class SessionsController < ApplicationController
end end
def destroy def destroy
if current_user.external? if current_user.external_user?
clear_lti_session_data clear_lti_session_data
else else
logout logout

View File

@ -16,12 +16,8 @@ module User
define_method("#{role}?") { try(:role) == role } define_method("#{role}?") { try(:role) == role }
end end
def external? [ExternalUser, InternalUser].each do |klass|
is_a?(ExternalUser) define_method("#{klass.name.underscore}?") { is_a?(klass) }
end
def internal?
is_a?(InternalUser)
end end
def to_s def to_s

View File

@ -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? } define_method(action) { @user.internal_user? }
end end
[:destroy?, :edit?, :show?, :update?].each do |action| [:destroy?, :edit?, :show?, :update?].each do |action|

View File

@ -21,7 +21,7 @@ class ExercisePolicy < AdminOrAuthorPolicy
def resolve def resolve
if @user.admin? if @user.admin?
@scope.all @scope.all
elsif @user.internal? elsif @user.internal_user?
@scope.where("user_id = #{@user.id} OR public = TRUE OR (team_id IS NOT NULL AND team_id IN (SELECT t.id FROM teams t JOIN internal_users_teams iut ON t.id = iut.team_id WHERE iut.internal_user_id = #{@user.id}))") @scope.where("user_id = #{@user.id} OR public = TRUE OR (team_id IS NOT NULL AND team_id IN (SELECT t.id FROM teams t JOIN internal_users_teams iut ON t.id = iut.team_id WHERE iut.internal_user_id = #{@user.id}))")
else else
@scope.none @scope.none

View File

@ -1,6 +1,6 @@
class TeamPolicy < ApplicationPolicy class TeamPolicy < ApplicationPolicy
[:create?, :index?, :new?].each do |action| [:create?, :index?, :new?].each do |action|
define_method(action) { @user.internal? } define_method(action) { @user.internal_user? }
end end
[:destroy?, :edit?, :show?, :update?].each do |action| [:destroy?, :edit?, :show?, :update?].each do |action|

View File

@ -1,4 +1,4 @@
- if current_user.try(:internal?) - if current_user.try(:internal_user?)
ul.breadcrumb ul.breadcrumb
- if model = Kernel.const_get(controller_name.classify) rescue nil - if model = Kernel.const_get(controller_name.classify) rescue nil
- object = model.find_by(id: params[:id]) - object = model.find_by(id: params[:id])

View File

@ -1,4 +1,4 @@
- if current_user.try(:internal?) - if current_user.try(:internal_user?)
ul.nav.navbar-nav ul.nav.navbar-nav
li.dropdown li.dropdown
a.dropdown-toggle data-toggle='dropdown' href='#' a.dropdown-toggle data-toggle='dropdown' href='#'

View File

@ -1,5 +1,5 @@
- if current_user - if current_user
- if current_user.internal? - if current_user.internal_user?
li.dropdown li.dropdown
a.dropdown-toggle data-toggle='dropdown' href='#' a.dropdown-toggle data-toggle='dropdown' href='#'
i.glyphicon.glyphicon-user i.glyphicon.glyphicon-user

View File

@ -129,7 +129,7 @@ describe SessionsController do
context 'with an internal user' do context 'with an internal user' do
before(:each) do before(:each) do
allow(user).to receive(:external?).and_return(false) allow(user).to receive(:external_user?).and_return(false)
allow(user).to receive(:forget_me!) allow(user).to receive(:forget_me!)
delete :destroy delete :destroy
end end
@ -146,7 +146,7 @@ describe SessionsController do
context 'with an external user' do context 'with an external user' do
before(:each) do before(:each) do
allow(user).to receive(:external?).and_return(true) allow(user).to receive(:external_user?).and_return(true)
delete :destroy delete :destroy
end end

View File

@ -17,6 +17,18 @@ describe ExternalUser do
end end
end end
describe '#external_user?' do
it 'is true' do
expect(user.external_user?).to be true
end
end
describe '#internal_user?' do
it 'is false' do
expect(user.internal_user?).to be false
end
end
describe '#teacher?' do describe '#teacher?' do
it 'is false' do it 'is false' do
expect(FactoryGirl.build(:external_user).teacher?).to be false expect(FactoryGirl.build(:external_user).teacher?).to be false

View File

@ -56,6 +56,18 @@ describe InternalUser do
end end
end end
describe '#external_user?' do
it 'is false' do
expect(user.external_user?).to be false
end
end
describe '#internal_user?' do
it 'is true' do
expect(user.internal_user?).to be true
end
end
describe '#teacher?' do describe '#teacher?' do
it 'is only true for teachers' do it 'is only true for teachers' do
expect(FactoryGirl.build(:admin).teacher?).to be false expect(FactoryGirl.build(:admin).teacher?).to be false