Skip to content

Commit

Permalink
Allow coaches to access all communities
Browse files Browse the repository at this point in the history
This is a fix for pupilfirst#506.
  • Loading branch information
harigopal committed Oct 10, 2020
1 parent a03f527 commit deafcf5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/queries/topics_resolver.rb
Expand Up @@ -22,9 +22,9 @@ def authorized?

return false if community.school_id != current_school.id

course_ids = ([current_user.faculty&.course_ids] + [current_user.course_ids]).flatten
return true if current_user.faculty.present? || current_school_admin.present?

(course_ids & community.course_ids).present? || current_school_admin.present?
(current_user.course_ids & community.course_ids).present?
end

def title_for_search
Expand Down
28 changes: 28 additions & 0 deletions spec/system/community/community_spec.rb
Expand Up @@ -45,6 +45,14 @@
expect(page).to have_text('Please sign in to continue.')
end

scenario 'student from an unlinked course attempts to visit community' do
CommunityCourseConnection.where(course: course).destroy_all

sign_in_user(student_1.user, referrer: community_path(community))

expect(page).to have_text("The page you were looking for doesn't exist")
end

scenario 'an active student visits his community' do
sign_in_user(student_1.user, referrer: community_path(community))

Expand Down Expand Up @@ -641,4 +649,24 @@
expect(find("#topics a:nth-child(1)")).to have_content(topic_2.title)
end
end

context "when the user is a coach who isn't enrolled in one of the community's connected courses" do
before do
CommunityCourseConnection.destroy_all
end

scenario "a coach from a different course can still moderate on unlinked communities" do
sign_in_user(coach.user, referrer: community_path(community))

click_link topic_1.title

# Can mark a reply as solution.
find("div[aria-label='Options for post #{reply_1.id}']").click
click_button 'Mark as solution'

within("div#post-show-#{reply_1.id}") do
expect(page).to have_selector("div[aria-label='Marked as solution icon']")
end
end
end
end

0 comments on commit deafcf5

Please sign in to comment.