E1826 Add student view for instructor: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(6 intermediate revisions by the same user not shown)
Line 33: Line 33:
This file is shared between all views and is responsible for rendering all the elements on the navigation bar including the menu items.
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.
In order to switch between default view of the user 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.
<pre>
<pre>
<% if session[:user] and !session[:user].role.student? and !session[:user].role.ta? %>
<% if session[:user] and !session[:user].role.student? %>
   <% if session.key?(:student_view) %>
   <% if session.key?(:student_view) %>
    <%= link_to "Close Student View", {controller: "role_switch", action: "close_student_view"}, method: :post, :style => "color: white" %>
  <%= link_to "Close Student View", {controller: "role_switch", action: "close_student_view"}, method: :post, :style => "color: white" %>
   <% else %>
   <% else %>
    <%= link_to "Open Student View", {controller: "role_switch", action: "open_student_view"}, method: :post, :style => "color: white" %>
  <%= link_to "Open Student View", {controller: "role_switch", action: "open_student_view"}, method: :post, :style => "color: white" %>
  <% end %>
   <% end %>
   <% end %>
<% end %>
</pre>
</pre>
=== expertiza/app/controllers/role_switch_controller.rb ===
=== expertiza/app/controllers/role_switch_controller.rb ===


Line 50: Line 51:
   # check to see if the current action is allowed
   # check to see if the current action is allowed
   def action_allowed?
   def action_allowed?
    # instructor,admin,superadmin is allowed to perform all the actions in
    # this controller
     ['Super-Administrator',
     ['Super-Administrator',
     'Administrator',
     'Administrator',
    'Teaching Assistant',
     'Instructor'].include? current_role_name
     'Instructor'].include? current_role_name
   end
   end
Line 70: Line 70:
   def close_student_view
   def close_student_view
     session.delete(:student_view)
     session.delete(:student_view)
     role = session[:user].role
     role = Role.find(session[:user].role_id)
     session[:menu] = role.cache[:menu]
     session[:menu] = role.cache[:menu]
     redirect_to controller: 'tree_display', action: 'list'
     redirect_to controller: 'tree_display', action: 'list'
Line 88: Line 88:
     end
     end
   end
   end
</pre>
=== 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 , teaching assistants and instructor.
<pre>
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"
</pre>
</pre>


Line 106: Line 122:


== Automated Test Plan ==
== 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'''''   
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 when an instructor is in default view. The following lines can be added to a spec/features file:
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.


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


2. '''Check whether ''Manage content'' and ''Survey Deployments'' are hidden in student view.'''
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 items ''Manage content'' and ''Survey Deployments'' are hidden when the instructor switches to student view. The following lines are to be added:
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:


<pre>
<pre>
it "can display relevant menu items when switching to student view", js: true do
it "can display relevant menu items when switching to student view", js: true do
     create(:instructor)
     create(:instructor)
    create(:role_of_student)
     login_as 'instructor6'
     login_as 'instructor6'
     visit '/tree_display/list'
     visit '/tree_display/list'
     click_link 'Swtich to Student View'
     click_link 'Open Student View'
     expect(page).to have_current_path('/student_task/list')
     expect(page).to have_current_path('/student_task/list')
     expect(page).to have_content('Assignments')
     expect(page).to have_content('Assignments')
     expect(page).to have_content('Course Evaluation')
     expect(page).to have_content('Close Student View')
    expect(page).not_to have_content('Manage content')
    expect(page).not_to have_content('Survey Deployments')
end
end
</pre>
</pre>

Latest revision as of 03:56, 10 November 2018

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 of the user 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? %>
  <% 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?
    ['Super-Administrator',
     'Administrator',
     'Teaching Assistant',
     '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 = Role.find(session[:user].role_id)
    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 , teaching assistants 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)
    create(:role_of_student)
    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)
    create(:role_of_student)
    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