fix favoriting for cross-shard logins
- fix id transposition for unfavoriting - don't keep the favorite courses cache after saving - reload the user if they're a shadow so we get the primary updated_at closes #ADMIN-1467 Change-Id: I97ff4937bdb009e2576e2201a8a01f40a8668bf4 Reviewed-on: https://gerrit.instructure.com/165076 Reviewed-by: Cody Cutrer <cody@instructure.com> Tested-by: Jenkins QA-Review: Jeremy Putnam <jeremyp@instructure.com> Product-Review: James Williams <jamesw@instructure.com>
This commit is contained in:
parent
ac48ffc6b0
commit
a8fc7bbcff
|
@ -190,9 +190,8 @@ class FavoritesController < ApplicationController
|
|||
def remove_favorite_course
|
||||
# allow removing a Favorite whose context object no longer exists
|
||||
# but also allow referencing by sis id, if possible
|
||||
courses = api_find_all(Course, [params[:id]])
|
||||
course_id = Shard.relative_id_for(courses.any? ? courses.first.id : params[:id], Shard.current, @current_user.shard)
|
||||
fave = @current_user.favorites.where(:context_type => 'Course', :context_id => course_id).first
|
||||
course = api_find(Course, params[:id])
|
||||
fave = @current_user.favorites.where(:context_type => 'Course', :context_id => course.id).first
|
||||
if fave
|
||||
result = favorite_json(fave, @current_user, session)
|
||||
fave.destroy
|
||||
|
@ -219,9 +218,8 @@ class FavoritesController < ApplicationController
|
|||
# -H 'Authorization: Bearer <ACCESS_TOKEN>'
|
||||
#
|
||||
def remove_favorite_groups
|
||||
group = api_find_all(Group, [params[:id]])
|
||||
group_id= Shard.relative_id_for(group.any? ? group.first.id : params[:id], Shard.current, @current_user.shard)
|
||||
fave = @current_user.favorites.where(:context_type => 'Group', :context_id => group_id).first
|
||||
group = api_find(Group, params[:id])
|
||||
fave = @current_user.favorites.where(:context_type => 'Group', :context_id => group.id).first
|
||||
if fave
|
||||
result = favorite_json(fave, @current_user, session)
|
||||
fave.destroy
|
||||
|
|
|
@ -20,4 +20,10 @@ class Favorite < ActiveRecord::Base
|
|||
belongs_to :user
|
||||
validates_inclusion_of :context_type, :allow_nil => true, :in => ['Course', 'Group'].freeze
|
||||
scope :by, lambda { |type| where(:context_type => type) }
|
||||
|
||||
after_save :touch_user
|
||||
|
||||
def touch_user
|
||||
self.class.connection.after_transaction_commit { user.touch }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -156,6 +156,7 @@ module AuthenticationMethods
|
|||
@current_pseudonym = Pseudonym.where(id: @policy_pseudonym_id).first
|
||||
elsif (@pseudonym_session = PseudonymSession.with_scope(find_options: Pseudonym.eager_load(:user)) { PseudonymSession.find })
|
||||
@current_pseudonym = @pseudonym_session.record
|
||||
@current_pseudonym.user.reload if @current_pseudonym.shard != @current_pseudonym.user.shard
|
||||
|
||||
# if the session was created before the last time the user explicitly
|
||||
# logged out (of any session for any of their pseudonyms), invalidate
|
||||
|
|
|
@ -29,7 +29,8 @@ module Factories
|
|||
:user => user,
|
||||
:login_count => 1,
|
||||
:global_account_id => '10000000000001',
|
||||
:sis_user_id => 'U001'
|
||||
:sis_user_id => 'U001',
|
||||
:shard => Shard.default
|
||||
)
|
||||
# at least one thing cares about the id of the pseudonym... using the
|
||||
# object_id should make it unique (but obviously things will fail if
|
||||
|
|
Loading…
Reference in New Issue