E1826 Add student view for instructor

From Expertiza_Wiki
Revision as of 22:31, 28 October 2018 by Zmathew (talk | contribs)
Jump to navigation Jump to search

Introduction

Background

The navigation for an instructor follows the below structure.

  • Home
  • Manage...
    • Users
    • Questionnaires
    • Courses
    • Assignments
    • Impersonate User
    • Anonymized View
  • Survey Deployments
  • Assignments
  • Course Evaluation
  • Profile
  • Contact Us

And that for a student follows the below structure.

  • Home
  • Assignments
  • Pending Surveys
  • Profile
  • Contact Us

For an instructor, the menu item 'Assignments' is present in 2 places - in the main menu as 'Assignments' and in the sub-menu as 'Manage.../Assignments' (italicized above). This could potentially be confusing. 'Manage.../Assignments' sub-menu item allows the instructor to create/edit assignments. The menu item 'Assignments' allows an instructor to participate in assignments. This is typically something that the instructor wants to do in a student role and hence there needs to be a student view for instructors to act as students without impersonating them and thus reducing confusion. The same needs to be implemented for admin and super admin as well.

Problem statement

Create a student view for instructors so that they can perform student operations without impersonating them. When an instructor logs in, he/she is in the default view with corresponding menu items (with the exception of the 'Assignments' menu item). There should be an option to switch to and revert back from the student view. When in student view, an instructor is presented with the student menu as listed above.

Implementation

expertiza/app/views/shared/_navigation.html.erb

This file is shared between all views and is responsible for rendering all the elements on the navigation bar including the menu items.

In order to switch between default view and student view, the following code was added. When in default view, the instructor is presented with a link, Open Student View, to switch to student view and when in student view, the Close Student View link can be used to switch back to the default view.

<%  if session[:user] and !session[:user].role.student? and !session[:user].role.ta? %>
  <% if session.key?(:student_view) %>
    <%= link_to "Close Student View", {controller: "role_switch", action: "close_student_view"}, method: :post, :style => "color: white" %>
  <% else %>
    <%= link_to "Open Student View", {controller: "role_switch", action: "open_student_view"}, method: :post, :style => "color: white" %>
  <% end %>
<% end %>

expertiza/app/controllers/role_switch_controller.rb

A new role_switch_controller.rb file has been added. This controller contains the actions to open/close student view.

class RoleSwitchController < ApplicationController
  # check to see if the current action is allowed
  def action_allowed?
    # instructor,admin,superadmin is allowed to perform all the actions in
    # this controller
    ['Super-Administrator',
     'Administrator',
     'Instructor'].include? current_role_name
  end

  # sets student_view in session object and redirects to
  # student_task/list after updating menu list
  def open_student_view
    session[:student_view] = true
    role = Role.student
    session[:menu] = role.cache[:menu]
    redirect_to controller: 'student_task', action: 'list'
  end

  # closes student_view in session object and redirects to
  # tree_display/list after reverting the menu list as per the role
  def close_student_view
    session.delete(:student_view)
    role = session[:user].role
    session[:menu] = role.cache[:menu]
    redirect_to controller: 'tree_display', action: 'list'
  end
end

expertiza/config/routes.rb

New post methods are added in config/routes.rb. The routes are directed to the role switch controller's open_student_view and close_student_view actions.

  resources :role_switch, only: [] do
    collection do
      post  :open_student_view
      post  :close_student_view
    end
  end

expertiza/config/role_[admin|super_admin|instructor].yml

A new menu node with the below format is added under 'Manage...' node in the yml configuration files for admin, superadmin and instructor.

73: &25 !ruby/object:Menu::Node
        content_page_id:
        controller_action_id: 15
        id: 73
        label: Student View
        name: student_view
        parent:
        parent_id: 37
        site_controller_id: 35
        url: "/role_switch/open_student_view"

Manual UI Testing

1. Login as an instructor. Enter 'instructor6' as username and 'password' as password.

2. Click on Open Student View below username to switch to student view.



3. Click on Close Student View below username to come back to default view.


Automated Test Plan

The following lines are added to spec/features/student_view_spec.rb file.

1. Check whether Assignments is absent in the menu in default view and there is an option to Open Student View This test case is to check if the menu item Assignments is absent and 'Open Student View' link is present when an instructor is in default view. Also on clicking the 'Manage...' button the 'Student View' sub-menu item should be listed.

it "can display relevant menu items after login as an admin/instructor/TA", js: true do
    create(:instructor)
    login_as 'instructor6'
    visit '/tree_display/list'
    expect(page).to have_current_path('/tree_display/list')
    expect(page).to have_content('Open Student View')
    expect(page).not_to have_content('Assignments')
    click_button "Manage..."
    expect(page).to have_content('Student View')
end

2. Check whether Assignments is present in the menu in default view and there is an option to Close Student View This test case is to check if the menu item Assignments and link Close Student View are present when the instructor switches to student view. The following lines are to be added:

it "can display relevant menu items when switching to student view", js: true do
    create(:instructor)
    login_as 'instructor6'
    visit '/tree_display/list'
    click_link 'Open Student View'
    expect(page).to have_current_path('/student_task/list')
    expect(page).to have_content('Assignments')
    expect(page).to have_content('Close Student View')
end

External Links

  1. Link to forked repository [[1]]

References

Expertiza

Expertiza Github

Expertiza Documentation

RSpec Documentation