CSC/ECE 517 Fall 2021 - E2138. Auto-generate submission directory names based on assignment

From Expertiza_Wiki
Jump to navigation Jump to search

This wiki page describes the changes made under E2138, in order to auto-generate submission directory names based on assignment names for Fall 2021, CSC/ECE 517.

Overview

About Expertiza

Expertiza is an open source project based on Ruby on Rails framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.

Issues for this project

When instructors give an assignment a name, submission directories should be auto-generated based on the assignment name, and also be unique. A number of issues existed when a previous team worked on this assignment (E2054), including

  • Issue #1: The directory name should be auto-generated from the assignment name.
  • Issue #2: It should be done by changing spaces in the names to underscores. E.g., the directory for Program 1 is by default "Program_1".
  • Issue #3: A check should be added to prevent two assignments in the same course from having the same name.
  • Issue #4: Verify or add if not present - a check to stop two assignments from sharing the same directory.
  • Issue #5: On changing the name of an assignment while creating it, the code shouldn't throw a NoMethodError.

Project implementation

Submitted work and demonstration of project

Files involved

  • app/controllers/impersonate_controller.rb - refactored the codes related to the issues mentioned above.
  • spec/controllers/impersonate_controller_spec.rb - implemented and added some related tests.

Changes made to code

  • The following code was modified in app/controllers/impersonate_controller.rb, in order to refactor to:
    • make the code more readable.
    • properly delete unused variable.

In function overwrite_session

Before

  def overwrite_session
    # If not impersonatable, then original user's session remains
    if params[:impersonate].nil?
      # E1991 : check whether instructor is currently in anonymized view
      user = User.anonymized_view?(session[:ip]) ? User.real_user_from_anonymized_name(params[:user][:name]) : user = User.find_by(name: params[:user][:name])
      session[:super_user] = session[:user] if session[:super_user].nil?
      AuthController.clear_user_info(session, nil)
      session[:original_user] = @original_user
      session[:impersonate] = true
      session[:user] = user
    else
      # If some user is to be impersonated, their session details are overwritten onto the current to impersonate
      if !params[:impersonate][:name].empty?
        # E1991 : check whether instructor is currently in anonymized view
        user = User.anonymized_view?(session[:ip]) ? User.real_user_from_anonymized_name(params[:impersonate][:name]) : user = user = User.find_by(name: params[:impersonate][:name])
        AuthController.clear_user_info(session, nil)
        session[:user] = user
        session[:impersonate] =  true
        session[:original_user] = @original_user
      else
        # E1991 : check whether instructor is currently in anonymized view
        user = User.anonymized_view?(session[:ip]) ? User.real_user_from_anonymized_name(params[:user][:name]) : user = User.find_by(name: params[:user][:name])
        AuthController.clear_user_info(session, nil)
        session[:user] = session[:super_user]
        user = session[:user]
        session[:super_user] = nil
      end
    end
  end

After

   def overwrite_session
    # If not impersonatable, then original user's session remains
    if params[:impersonate].nil?
      # E1991 : check whether instructor is currently in anonymized view
      if User.anonymized_view?(session[:ip])
        user = User.real_user_from_anonymized_name(params[:user][:name])
      else
        user = User.find_by(name: params[:user][:name])
      end
      session[:super_user] = session[:user] if session[:super_user].nil?
      AuthController.clear_user_info(session, nil)
      session[:original_user] = @original_user
      session[:impersonate] = true
      session[:user] = user
      # If some user is to be impersonated, their session details are overwritten onto the current to impersonate
    elsif !params[:impersonate][:name].empty?
      # E1991 : check whether instructor is currently in anonymized view
      if User.anonymized_view?(session[:ip])
        user = User.real_user_from_anonymized_name(params[:impersonate][:name])
      else
        user = User.find_by(name: params[:impersonate][:name])
      end
      AuthController.clear_user_info(session, nil)
      session[:user] = user
      session[:impersonate] =  true
      session[:original_user] = @original_user
    else
      # E1991 : check whether instructor is currently in anonymized view
      AuthController.clear_user_info(session, nil)
      session[:user] = session[:super_user]
      session[:super_user] = nil
    end
  end

Test Plan

Manual UI Testing

The following steps must be performed to test the project UI:

Step 1: Log in as an Instructor, with Username - instructor6, Password - password




Step 2: Create a new assignment. Assignment is named as "Test Assignment", under course CSC/ECE 517 Fall 2020. The directory name gets auto generated with replacing space by underscore in assignment name.




Step 3: Assignment gets successfully created. Assignment is named as "Test Assignment" and gets saved in the directory "Test_assignment", under course CSC/ECE 517 Fall 2020




Step 4: Try saving another assignment with same name. Following error is observed. br>



RSpec Testing

The following RSpec tests are corrected in the assignments_contoller_spec.rb file Before

    context 'when assignment_form is saved successfully' do
      it 'redirects to assignment#edit page' do
        allow(assignment_form).to receive(:assignment).and_return(assignment)
        allow(Assignment).to receive(:find_by).with(any_args).and_return(false)
        allow(Assignment).to receive(:find_by).with(any_args).and_return(false)
        allow(assignment_form).to receive(:save).and_return(true)
        allow(assignment_form).to receive(:create_assignment_node).and_return(double('node'))
        allow(assignment_form).to receive(:update).with(any_args).and_return(true)
        allow(assignment).to receive(:id).and_return(1)
        allow(Assignment).to receive(:find_by).with(course_id:1, name:'test assignment').and_return(assignment)
        allow_any_instance_of(AssignmentsController).to receive(:undo_link)
           .with('Assignment "test assignment" has been created successfully. ').and_return(true)
        post :create, @params
        expect(response).to redirect_to('/assignments/1/edit')
      end
    end

After

 context 'when assignment_form is saved successfully' do
      it 'redirects to assignment#edit page' do
        allow(assignment_form).to receive(:assignment).and_return(assignment)
        allow(Assignment).to receive(:find_by).with(any_args).and_return(false)
        allow(Assignment).to receive(:find_by).with(any_args).and_return(false)
        allow(assignment_form).to receive(:save).and_return(true)
        allow(assignment_form).to receive(:create_assignment_node).and_return(double('node'))
        allow(assignment_form).to receive(:update).with(any_args).and_return(true)
        allow(assignment).to receive(:id).and_return(1)
        allow(Assignment).to receive(:find_by).with(course_id:1, name:'test assignment').and_return(assignment)
        allow_any_instance_of(AssignmentsController).to receive(:undo_link)
           .with('Assignment "test assignment" has been created successfully. ').and_return(true)
        post :create, @params
        expect(response).to redirect_to('/assignments/1/edit')
      end
    end

Team Information

Mentor: Nicholas Himes (nnhimes)


Henry Chen (hchen34)

Saurabh Nanda (snanda2)

Snehapriyaa Mathiyalaghan (smathiy)