remove require_user_for_context from lib/authentication_methods

this method was a thin wrapper around get_context that redirected to the root
page if a context didn't exist.  Ostensibly it also showed the http error as in
flash message if a context did exist but the user didn't, or didn't belong to
the context, but this branch of code never worked due to a state vs
workflow_state bug that rendered the if statement always false.

Change-Id: I5a7353ddf3e1fc082324384a5ea3d3b6196c0dfd
Reviewed-on: https://gerrit.instructure.com/8499
Reviewed-by: Cody Cutrer <cody@instructure.com>
Tested-by: Hudson <hudson@instructure.com>
This commit is contained in:
Simon Williams 2012-02-03 15:51:16 -07:00
parent df068f8b19
commit ce0bd8924a
10 changed files with 9 additions and 42 deletions

View File

@ -17,7 +17,7 @@
#
class AnnouncementsController < ApplicationController
before_filter :require_user_for_context, :except => :public_feed
before_filter :require_context, :except => :public_feed
before_filter { |c| c.active_tab = "announcements" }
def index

View File

@ -20,7 +20,7 @@
#
# API for accessing Assignment Group and Assignment information.
class AssignmentGroupsController < ApplicationController
before_filter :require_user_for_context
before_filter :require_context
include Api::V1::Assignment

View File

@ -17,7 +17,7 @@
#
class ContextController < ApplicationController
before_filter :require_user_for_context, :except => [:inbox, :inbox_item, :destroy_inbox_item, :mark_inbox_as_read, :create_media_object, :kaltura_notifications, :media_object_redirect, :media_object_inline, :media_object_thumbnail, :object_snippet, :discussion_replies]
before_filter :require_context, :except => [:inbox, :inbox_item, :destroy_inbox_item, :mark_inbox_as_read, :create_media_object, :kaltura_notifications, :media_object_redirect, :media_object_inline, :media_object_thumbnail, :object_snippet, :discussion_replies]
before_filter :require_user, :only => [:inbox, :inbox_item, :report_avatar_image, :discussion_replies]
protect_from_forgery :except => [:kaltura_notifications, :object_snippet]
@ -278,8 +278,6 @@ class ContextController < ApplicationController
end
def roster
get_context
if authorized_action(@context, @current_user, [:read_roster, :manage_students, :manage_admin_users])
log_asset_access("roster:#{@context.asset_string}", "roster", "other")
if @context.is_a?(Course)
@ -306,14 +304,12 @@ class ContextController < ApplicationController
end
def prior_users
get_context
if authorized_action(@context, @current_user, [:manage_students, :manage_admin_users, :read_prior_roster])
@prior_memberships = @context.enrollments.scoped(:conditions => {:workflow_state => 'completed'}, :include => :user).to_a.once_per(&:user_id).sort_by{|e| [e.rank_sortable(true), e.user.sortable_name.downcase] }
end
end
def roster_user_services
get_context
if authorized_action(@context, @current_user, :read_roster)
@users = @context.users.order_by_sortable_name
@users_hash = {}
@ -330,7 +326,6 @@ class ContextController < ApplicationController
end
def roster_user_usage
get_context
if authorized_action(@context, @current_user, :read_reports)
@user = @context.users.find(params[:user_id])
@accesses = AssetUserAccess.for_user(@user).for_context(@context).most_recent.paginate(:page => params[:page], :per_page => 50)
@ -342,7 +337,6 @@ class ContextController < ApplicationController
end
def roster_user
get_context
if authorized_action(@context, @current_user, :read_roster)
if @context.is_a?(Course)
@membership = @context.enrollments.find_by_user_id(params[:id])

View File

@ -23,7 +23,7 @@ require 'set'
# API for accessing course information.
class CoursesController < ApplicationController
before_filter :require_user, :only => [:index]
before_filter :require_user_for_context, :only => [:roster, :locks, :switch_role]
before_filter :require_context, :only => [:roster, :locks, :switch_role]
include Api::V1::Course
@ -370,7 +370,6 @@ class CoursesController < ApplicationController
end
def roster
get_context
if authorized_action(@context, @current_user, :read_roster)
log_asset_access("roster:#{@context.asset_string}", "roster", "other")
@students = @context.participating_students.find(:all, :order => User.sortable_name_order_by_clause)

View File

@ -1,5 +1,5 @@
class Gradebook2Controller < ApplicationController
before_filter :require_user_for_context
before_filter :require_context
add_crumb("Gradebook") { |c| c.send :named_context_url, c.instance_variable_get("@context"), :context_grades_url }
before_filter { |c| c.active_tab = "grades" }

View File

@ -17,7 +17,7 @@
#
class GradebookUploadsController < ApplicationController
before_filter :require_user_for_context
before_filter :require_context
def new
if authorized_action(@context, @current_user, :manage_grades)
@gradebook_upload = @context.build_gradebook_upload

View File

@ -19,7 +19,7 @@
class GradebooksController < ApplicationController
include ActionView::Helpers::NumberHelper
before_filter :require_user_for_context, :except => :public_feed
before_filter :require_context, :except => :public_feed
add_crumb("Grades", :except => :public_feed) { |c| c.send :named_context_url, c.instance_variable_get("@context"), :context_grades_url }
before_filter { |c| c.active_tab = "grades" }

View File

@ -17,7 +17,7 @@
#
class OutcomeGroupsController < ApplicationController
before_filter :require_user_for_context
before_filter :require_context
def create
if authorized_action(@context, @current_user, :manage_outcomes)

View File

@ -17,7 +17,7 @@
#
class OutcomesController < ApplicationController
before_filter :require_user_for_context, :except => [:build_outcomes]
before_filter :require_context, :except => [:build_outcomes]
add_crumb(proc { t "#crumbs.outcomes", "Outcomes" }, :except => [:destroy, :build_outcomes]) { |c| c.send :named_context_url, c.instance_variable_get("@context"), :context_outcomes_path }
before_filter { |c| c.active_tab = "outcomes" }

View File

@ -168,32 +168,6 @@ module AuthenticationMethods
end
private :load_user
def require_user_for_context
get_context
if !@context
redirect_to '/'
return false
elsif @context.state == 'available'
if !@current_user
respond_to do |format|
store_location
flash[:notice] = I18n.t('lib.auth.errors.not_authenticated', "You must be logged in to access this page")
format.html {redirect_to login_url}
format.json {render :json => {:errors => {:message => I18n.t('lib.auth.errors.not_authenticated', "You must be logged in to access this page")}}, :status => :unauthorized}
end
return false;
elsif !@context.users.include?(@current_user)
respond_to do |format|
flash[:notice] = I18n.t('lib.auth.errors.not_authorized', "You are not authorized to view this page")
format.html {redirect_to "/"}
format.json {render :json => {:errors => {:message => I18n.t('lib.auth.errors.not_authorized', "You are not authorized to view this page")}}, :status => :unauthorized}
end
return false
end
end
end
protected :require_user_for_context
def require_user
unless @current_pseudonym && @current_user
respond_to do |format|