Skip to content

Commit e465cf7

Browse files
committed
render correct page after joining self-signup group
fixes #10880 when joining a self-signup group, permissions were being incorrectly cached causing a 'membership pending' page to be shown. test plan: - as a teacher, create a set of course groups, and allow self-signup - as a student, join one of these groups - it should not say 'membership pending' - it should say 'you joined the group' Change-Id: Ic11cdeead8db23293e64faa0dc3c803310e426cc Reviewed-on: https://gerrit.instructure.com/13959 Tested-by: Jenkins <jenkins@instructure.com> Reviewed-by: Cody Cutrer <cody@instructure.com>
1 parent 309ed65 commit e465cf7

3 files changed

Lines changed: 20 additions & 1 deletion

File tree

app/models/group.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ def add_user(user, new_record_state=nil, moderator=nil)
220220
else
221221
member = self.group_memberships.create(attrs)
222222
end
223+
# permissions for this user in the group are probably different now
224+
Rails.cache.delete(permission_cache_key_for(user))
223225
return member
224226
end
225227

spec/integration/groups_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,17 @@
3030
html = Nokogiri::HTML(response.body)
3131
html.css('.floating_links a.add').attribute("href").text.should == "/groups/#{@group.id}/announcements#new"
3232
end
33+
34+
it "should not rendering 'pending' page when joining a self-signup group" do
35+
enable_cache do
36+
course_with_student_logged_in(:active_all => true)
37+
category1 = @course.group_categories.create!(:name => "category 1")
38+
category1.configure_self_signup(true, false)
39+
category1.save!
40+
g1 = @course.groups.create!(:name => "some group", :group_category => category1)
41+
42+
get "/courses/#{@course.id}/groups/#{g1.id}?join=1"
43+
response.body.should_not =~ /This group has received your request to join/
44+
end
45+
end
3346
end

vendor/plugins/adheres_to_policy/lib/adheres_to_policy.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def grants_rights?(user, *sought_rights)
124124
# once
125125
granted_rights = if cache_lookup
126126
# Check and cache all the things!
127-
Rails.cache.fetch(['context_permissions', self, user].cache_key, :expires_in => 1.hour) do
127+
Rails.cache.fetch(permission_cache_key_for(user), :expires_in => 1.hour) do
128128
check_policy(user)
129129
end
130130
else
@@ -149,6 +149,10 @@ def has_rights?(obj, *sought_rights)
149149
obj.grants_rights?(self, *sought_rights)
150150
end
151151

152+
def permission_cache_key_for(user)
153+
['context_permissions', self, user].cache_key
154+
end
155+
152156
end # InstanceMethods
153157
end # AdheresToPolicy
154158
end # Instructure

0 commit comments

Comments
 (0)