Skip to content

Commit

Permalink
Merge pull request #682 from coursemology-collab/wangqiang/sidebar-ab…
Browse files Browse the repository at this point in the history
…ility

Defining sidebar ability
  • Loading branch information
lowjoel committed Dec 15, 2015
2 parents 4a5e024 + ec7a6a0 commit d789ae0
Show file tree
Hide file tree
Showing 15 changed files with 178 additions and 30 deletions.
2 changes: 2 additions & 0 deletions app/controllers/components/course/courses_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def sidebar_items
private

def admin_sidebar_items
return [] unless can?(:manage, current_course)

[
{
title: t('layouts.course_admin.title'),
Expand Down
12 changes: 12 additions & 0 deletions app/controllers/components/course/groups_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class Course::GroupsComponent < SimpleDelegator
include Course::ControllerComponentHost::Component

def sidebar_items
return [] unless can_manage_group?

[
{
key: :groups,
Expand All @@ -12,4 +14,14 @@ def sidebar_items
}
]
end

private

def can_manage_group?
can?(:manage, Course::Group.new(course: current_course)) || manageable_groups.any?
end

def manageable_groups
current_course.groups.accessible_by(current_ability, :manage)
end
end
2 changes: 2 additions & 0 deletions app/controllers/components/course/levels_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class Course::LevelsComponent < SimpleDelegator
include Course::ControllerComponentHost::Component

def sidebar_items
return [] unless can?(:manage, Course::Level.new(course: current_course))

[
{
key: :levels,
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/components/course/users_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class Course::UsersComponent < SimpleDelegator
include Course::ControllerComponentHost::Component

def sidebar_items
return [] unless can?(:manage, CourseUser.new(course: current_course))

[
{
title: t('layouts.course_users.title'),
Expand Down
6 changes: 4 additions & 2 deletions app/views/layouts/course.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
nav.navbar-default role='navigation'
div.sidebar.collapse.navbar-collapse#course-navigation-sidebar
= sidebar_items(controller.sidebar_items(type: :normal))
h5 = t('.administration')
= sidebar_items(controller.sidebar_items(type: :admin))

- if (admin_sidebar_items = controller.sidebar_items(type: :admin)).any?
h5 = t('.administration')
= sidebar_items(admin_sidebar_items)

div.col-lg-10.col-md-9.col-sm-8
= yield
6 changes: 6 additions & 0 deletions spec/features/course/achievement_listing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
expect(page).not_to have_link(nil, href: edit_course_achievement_path(course, achievement))
expect(page).not_to have_content_tag_for(draft_achievement)
end

scenario 'I can view the Achievement Sidebar item' do
visit course_path(course)

expect(page).to have_selector('li', text: 'course.achievements.sidebar_title')
end
end
end
end
26 changes: 26 additions & 0 deletions spec/features/course/admin/admin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
context 'As an Course Manager' do
let(:user) { create(:course_manager, :approved, course: course).user }

scenario 'I can view the Course Admin Sidebar item' do
visit course_path(course)

expect(page).to have_selector('li', text: 'layouts.course_admin.title')
end

scenario 'I can change the course attributes' do
visit course_admin_path(course)

Expand All @@ -31,5 +37,25 @@
expect(course.reload.description).to eq(new_description)
end
end

context 'As a Course Teaching Assistant' do
let(:user) { create(:course_teaching_assistant, :approved, course: course).user }

scenario 'I cannot view the Course Admin Sidebar item' do
visit course_path(course)

expect(page).not_to have_selector('li', text: 'layouts.course_admin.title')
end
end

context 'As a Course Student' do
let(:user) { create(:course_student, :approved, course: course).user }

scenario 'I cannot view the Course Admin Sidebar item' do
visit course_path(course)

expect(page).not_to have_selector('li', text: 'layouts.course_admin.title')
end
end
end
end
6 changes: 6 additions & 0 deletions spec/features/course/announcement_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@
context 'As an Course Student' do
let(:user) { create(:course_student, :approved, course: course).user }

scenario 'I can view the Announcement Sidebar item' do
visit course_path(course)

expect(page).to have_selector('li', text: 'course.announcements.sidebar_title')
end

scenario 'I can see the started announcements' do
visit course_announcements_path(course)
expect(page).not_to have_link(nil, href: new_course_announcement_path(course))
Expand Down
8 changes: 8 additions & 0 deletions spec/features/course/assessment_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,14 @@

context 'As a Course Student' do
let(:user) { create(:course_user, :approved, course: course).user }

scenario 'I can view the Assessment Sidebar item' do
visit course_path(course)

assessment_sidebar = 'activerecord.attributes.course/assessment/category/title.default'
expect(page).to have_selector('li', text: assessment_sidebar)
end

scenario 'I can see assessments' do
category = course.assessment_categories.first
assessment = create(:assessment, course: course, tab: category.tabs.first)
Expand Down
7 changes: 7 additions & 0 deletions spec/features/course/forum/topic_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,13 @@

context 'As a Course Student' do
let(:user) { create(:course_student, :approved, course: course).user }

scenario 'I can view the Forum Sidebar item' do
visit course_path(course)

expect(page).to have_selector('li', text: 'course.forum.forums.sidebar_title')
end

scenario 'I can see shown topics' do
topic = create(:forum_topic, forum: forum)
hidden_topic = create(:forum_topic, forum: forum, hidden: true)
Expand Down
22 changes: 22 additions & 0 deletions spec/features/course/group_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
context 'As a Course manager' do
let(:user) { create(:course_manager, :approved, course: course).user }

scenario 'I can view the Group Sidebar item' do
visit course_path(course)

expect(page).to have_selector('li', text: 'course.groups.sidebar_title')
end

scenario 'I can view all the groups in course' do
visit course_groups_path(course)

Expand Down Expand Up @@ -69,6 +75,12 @@
let(:group) { create(:course_group, course: course) }
let(:user) { create(:course_group_manager, course: course, course_group: group).user }

scenario 'I can view the Group Sidebar item' do
visit course_path(course)

expect(page).to have_selector('li', text: 'course.groups.sidebar_title')
end

scenario 'I can edit my group' do
visit edit_course_group_path(course, group)
new_name = 'New Group'
Expand All @@ -95,5 +107,15 @@
expect(page).to have_selector('div', text: I18n.t('course.groups.destroy.success'))
end
end

context 'As a Course Student' do
let(:user) { create(:course_student, :approved, course: course).user }

scenario 'I cannot view the Group Sidebar item' do
visit course_path(course)

expect(page).not_to have_selector('li', text: 'course.groups.sidebar_title')
end
end
end
end
6 changes: 6 additions & 0 deletions spec/features/course/lesson_plan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
context 'As a Course Student' do
let(:user) { create(:course_student, :approved, course: course).user }

scenario 'I can view the LessonPlan Sidebar item' do
visit course_path(course)

expect(page).to have_selector('li', text: 'course.lesson_plan.items.sidebar_title')
end

scenario 'I can view all lesson plan items grouped by milestone' do
visit course_lesson_plan_path(course)
expect(page).not_to have_link(nil, href: new_course_lesson_plan_event_path(course))
Expand Down
16 changes: 16 additions & 0 deletions spec/features/course/level_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
context 'As a Course Administrator' do
let(:user) { create(:course_manager, :approved, course: course).user }

scenario 'I can view the Level Sidebar item' do
visit course_path(course)

expect(page).to have_selector('li', text: 'course.levels.sidebar_title')
end

scenario 'I can view course levels' do
visit course_levels_path(course)

Expand All @@ -43,5 +49,15 @@
to change(course.levels, :count).by(-1)
end
end

context 'As a Course Student' do
let(:user) { create(:course_student, :approved, course: course).user }

scenario 'I cannot view the Level Sidebar item' do
visit course_path(course)

expect(page).not_to have_selector('li', text: 'course.levels.sidebar_title')
end
end
end
end
6 changes: 6 additions & 0 deletions spec/features/course/material/folder_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@
context 'As a Course Student' do
let(:user) { create(:course_student, :approved, course: course).user }

scenario 'I can view the Material Sidebar item' do
visit course_path(course)

expect(page).to have_selector('li', text: 'course.material.sidebar_title')
end

scenario 'I can view valid subfolders' do
valid_folders = subfolders.select do |f|
f.start_at < Time.zone.now && (f.end_at.nil? || f.end_at > Time.zone.now)
Expand Down
81 changes: 53 additions & 28 deletions spec/features/course/staff_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,58 +5,83 @@

with_tenant(:instance) do
let(:course) { create(:course) }
let(:user) { create(:administrator) }
let!(:course_approved_students) { create_list(:course_student, 2, :approved, course: course) }
let!(:course_unapproved_students) { create_list(:course_student, 2, course: course) }
let!(:course_managers) { create_list(:course_manager, 2, :approved, course: course) }
before { login_as(user, scope: :user) }

context 'when logged in with a Teaching Assistant account' do
context 'As a Course Student' do
let(:user) { create(:course_student, :approved, course: course).user }

scenario 'I cannot view the Users Management Sidebar item' do
visit course_path(course)

expect(page).not_to have_selector('li', text: 'layouts.course_users.title')
end
end

context 'As a Course Teaching Assistant' do
let(:user) { create(:user) }
let!(:course_staff) do
create(:course_teaching_assistant, :approved, course: course, user: user)
end

scenario 'Teaching assistants cannot access the staff list' do
scenario 'I cannot view the Users Management Sidebar item' do
visit course_path(course)

expect(page).not_to have_selector('li', text: 'layouts.course_users.title')
end

scenario 'I cannot access the staff list' do
visit course_users_staff_path(course)
expect(page.status_code).to eq(403)
end
end

scenario 'Course manager can view the list of staff' do
visit course_users_staff_path(course)
context 'As a Course Manager' do
let(:user) { create(:course_manager, :approved, course: course).user }

(course_approved_students + course_unapproved_students).each do |approved_student|
expect(page).not_to have_field('course_user_name', with: approved_student.name)
end
scenario 'I can view the Users Management Sidebar item' do
visit course_path(course)

course_managers.each do |staff|
expect(page).to have_field('course_user_name', with: staff.name)
expect(page).to have_selector('li', text: 'layouts.course_users.title')
end
end

scenario 'Course manager can change staff role' do
staff_to_change = course_managers[Random.rand(course_managers.length)]
visit course_users_staff_path(course)
scenario 'I can view the list of staff' do
visit course_users_staff_path(course)

(course_approved_students + course_unapproved_students).each do |approved_student|
expect(page).not_to have_field('course_user_name', with: approved_student.name)
end

field = find_field('course_user_name', with: staff_to_change.name)
within field.find(:xpath, '../../../..') do
fill_in 'course_user_name', with: staff_to_change.name + '!'
select 'owner', from: 'course_user_role'
find_button('update').click
course_managers.each do |staff|
expect(page).to have_field('course_user_name', with: staff.name)
end
end

expect(page).to have_field('course_user_name', with: staff_to_change.name + '!')
end
scenario 'I can change staff role' do
staff_to_change = course_managers[Random.rand(course_managers.length)]
visit course_users_staff_path(course)

scenario 'Course manager can delete staff' do
staff_to_delete = course_managers[Random.rand(course_managers.length)]
visit course_users_staff_path(course)
field = find_field('course_user_name', with: staff_to_change.name)
within field.find(:xpath, '../../../..') do
fill_in 'course_user_name', with: staff_to_change.name + '!'
select 'owner', from: 'course_user_role'
find_button('update').click
end

expect do
find_link(nil, href: course_user_path(course, staff_to_delete)).click
end.to change { page.all('form.edit_course_user').count }.by(-1)
expect(page).not_to have_field('course_user_name', with: staff_to_delete.name)
expect(page).to have_field('course_user_name', with: staff_to_change.name + '!')
end

scenario 'I can delete staff' do
staff_to_delete = course_managers[Random.rand(course_managers.length)]
visit course_users_staff_path(course)

expect do
find_link(nil, href: course_user_path(course, staff_to_delete)).click
end.to change { page.all('form.edit_course_user').count }.by(-1)
expect(page).not_to have_field('course_user_name', with: staff_to_delete.name)
end
end
end
end

0 comments on commit d789ae0

Please sign in to comment.