<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aamajumd</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Aamajumd"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Aamajumd"/>
	<updated>2026-09-18T08:58:16Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=142165</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=142165"/>
		<updated>2021-11-30T01:21:45Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza final project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
* review_response_map.rb  &amp;lt;--------- 92.5% coverage&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map.rb &amp;lt;------ 23.08% coverage&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
* response_map.rb &amp;lt;----------------- 74.47% coverage&lt;br /&gt;
&lt;br /&gt;
This project aims to get all the response maps to at least a 80% level of coverage for every Response Map file by writing unit tests for each uncovered method listed in the next section.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
* Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
* Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
* Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
* Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
== Test Files Involved ==&lt;br /&gt;
There are 4 test files involved in this project:&lt;br /&gt;
* review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* response_map_spec.rb&lt;br /&gt;
of these files, only review_response_map_spec.rb currently exists; the rest will be added.&lt;br /&gt;
&lt;br /&gt;
== Methods Tested Per File ==&lt;br /&gt;
&lt;br /&gt;
=== review_response_map_spec.rb ===&lt;br /&gt;
Currently this file is 92.5% covered and there are no plans to cover it further.&lt;br /&gt;
&lt;br /&gt;
=== metareview_response_map_spec.rb ===&lt;br /&gt;
The functions for metareview_response_map.rb that will be tested are:&lt;br /&gt;
====get_all_versions====&lt;br /&gt;
This returns a sorted array of all the different versions of what is being reviewed in this response map. This means for a test, we will need to create a reviewer, a reviewee, several types of reviews of different versions to be sorted correctly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# return all the versions available for a response map.&lt;br /&gt;
  # a person who is doing meta review has to be able to see all the versions of review.&lt;br /&gt;
  def get_all_versions&lt;br /&gt;
    if self.review_mapping.response&lt;br /&gt;
      @sorted_array = []&lt;br /&gt;
      @prev = Response.all&lt;br /&gt;
      @prev.each do |element|&lt;br /&gt;
        @sorted_array &amp;lt;&amp;lt; element if element.map_id == self.review_mapping.map_id&lt;br /&gt;
      end&lt;br /&gt;
      @sorted = @sorted_array.sort {|m1, m2| m1.version_num || if m2.version_num&lt;br /&gt;
                                                                  m1.version_num &amp;lt;=&amp;gt; m2.version_num&lt;br /&gt;
                                                                else&lt;br /&gt;
                                                                  m1.version_num ? -1 : 1&lt;br /&gt;
                                                                end }&lt;br /&gt;
      # return all the lists in ascending order.&lt;br /&gt;
      @sorted&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====contributor====&lt;br /&gt;
Returns the team associated with the ReviewResponseMap that is to be metareviewed. We will need to create a ReviewResponseMap that has a team associated with it. Then we must create MetareviewResponseMap that points to a created ReviewResponseMap via the reviewed_object_id attribute. We will test if it indeed returns the team associated with ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First, find the &amp;quot;ReviewResponseMap&amp;quot; to be metareviewed;&lt;br /&gt;
  # Second, find the team in the &amp;quot;ReviewResponseMap&amp;quot; record.&lt;br /&gt;
  def contributor&lt;br /&gt;
    team_review_map = ReviewResponseMap.find(self.reviewed_object_id)&lt;br /&gt;
    AssignmentTeam.find(team_review_map.reviewee_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====questionnaire====&lt;br /&gt;
Returns all questionnaires associated to the assignment of this MetareviewResponseMap that is of type 'MetareviewQuestionnaire'. We will need to create a valid MetareviewResponseMap including at least one MetareviewQuestionnaire that can be returned.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire&lt;br /&gt;
    self.assignment.questionnaires.find_by(type: 'MetareviewQuestionnaire')&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====get_title====&lt;br /&gt;
Returns string &amp;quot;Metareview&amp;quot;. We will test if this string is the same as typed out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def get_title&lt;br /&gt;
    &amp;quot;Metareview&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====exports====&lt;br /&gt;
This function takes 3 parameters: csv (the csv file that will contain the exported metareview information), parent_id (the assignment ID containing the requested metareviews), and _options. The function sends all the information about the metareviews to a csv file. We will test that the information is properly exported to the csv file.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.export(csv, parent_id, _options)&lt;br /&gt;
    mappings = Assignment.find(parent_id).metareview_mappings&lt;br /&gt;
    mappings = mappings.sort_by {|a| [a.review_mapping.reviewee.name, a.reviewee.name, a.reviewer.name] }&lt;br /&gt;
    mappings.each do |map|&lt;br /&gt;
      csv &amp;lt;&amp;lt; [&lt;br /&gt;
        map.review_mapping.reviewee.name,&lt;br /&gt;
        map.reviewee.name,&lt;br /&gt;
        map.reviewer.name&lt;br /&gt;
      ]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====export_fields====&lt;br /&gt;
Takes a parameter called &amp;quot;_options&amp;quot; that returns the three field columns associated with metareviews to be exported for use by other controllers. We will test to see that these three columns are properly returned.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.export_fields(_options)&lt;br /&gt;
    fields = [&amp;quot;contributor&amp;quot;, &amp;quot;reviewed by&amp;quot;, &amp;quot;metareviewed by&amp;quot;]&lt;br /&gt;
    fields&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====import====&lt;br /&gt;
This function takes 3 parameters: row_hash (represents the hash of the metareview data we want to import), session, and id (representing the id of the assignment we want to import metareview data for). The function imports the data from the hash map, and if the information is input correctly, the data is extracted from the hash and creates a metareview for the requested assignment, otherwise it flashes an error saying the data was input incorrectly. We will test to make sure the imported data is properly converted into a metareview.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-import.jpg]]&lt;br /&gt;
&lt;br /&gt;
====email====&lt;br /&gt;
This function takes 3 parameters: defn, _participant (the user who will be receiving the email), and assignment (the assignment associated with the metareview). The function sends an email to the participant when they have a new metareview to complete. We will test to make sure the email is sent to the correct participant.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def email(defn, _participant, assignment)&lt;br /&gt;
    defn[:body][:type] = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
    reviewee_user = Participant.find(reviewee_id)&lt;br /&gt;
    defn[:body][:obj_name] = assignment.name&lt;br /&gt;
    defn[:body][:first_name] = User.find(reviewee_user.user_id).fullname&lt;br /&gt;
    defn[:to] = User.find(reviewee_user.user_id).email&lt;br /&gt;
    Mailer.sync_message(defn).deliver&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== teammate_review_response_map_spec.rb ===&lt;br /&gt;
The functions for teammate_review_response_map.rb that will be tested are:&lt;br /&gt;
==== questionnaire ====&lt;br /&gt;
This function searches for a TeammateReviewQuestionnaire object and returns it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def questionnaire&lt;br /&gt;
    self.assignment.questionnaires.find_by(type: 'TeammateReviewQuestionnaire')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== get_title ====&lt;br /&gt;
This function returns the string &amp;quot;Teammate Review&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_title&lt;br /&gt;
    &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== teammate_response_report ====&lt;br /&gt;
This function returns the teammate response report given the reviewer ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.teammate_response_report(id)&lt;br /&gt;
    TeammateReviewResponseMap.select(&amp;quot;DISTINCT reviewer_id&amp;quot;).where(&amp;quot;reviewed_object_id = ?&amp;quot;, id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== email ====&lt;br /&gt;
This function sends a notification email to a student who has been reviewed by their teammate.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Send Teammate Review Emails&lt;br /&gt;
  # Refactored from email method in response.rb&lt;br /&gt;
  def email(defn, participant, assignment)&lt;br /&gt;
    defn[:body][:type] = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
    participant = AssignmentParticipant.find(reviewee_id)&lt;br /&gt;
    topic_id = SignedUpTeam.topic_id(participant.parent_id, participant.user_id)&lt;br /&gt;
    defn[:body][:obj_name] = assignment.name&lt;br /&gt;
    user = User.find(participant.user_id)&lt;br /&gt;
    defn[:body][:first_name] = user.fullname&lt;br /&gt;
    defn[:to] = user.email&lt;br /&gt;
    Mailer.sync_message(defn).deliver&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== response_map_spec.rb ===&lt;br /&gt;
The functions for response_map.rb that will be tested are:&lt;br /&gt;
==== self.assessments_for(team) ====&lt;br /&gt;
Gets all submitted Review Responses or all regular Responses for a team, sorts the responses by version, and returns the latest Responses.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-assessments_for.png]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # return latest versions of the responses&lt;br /&gt;
  def self.assessments_for(team)&lt;br /&gt;
    responses = []&lt;br /&gt;
    # stime = Time.now&lt;br /&gt;
    if team&lt;br /&gt;
      @array_sort = []&lt;br /&gt;
      @sort_to = []&lt;br /&gt;
      maps = where(reviewee_id: team.id)&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        next if map.response.empty?&lt;br /&gt;
        @all_resp = Response.where(map_id: map.map_id).last&lt;br /&gt;
        if map.type.eql?('ReviewResponseMap')&lt;br /&gt;
          # If its ReviewResponseMap then only consider those response which are submitted.&lt;br /&gt;
          @array_sort &amp;lt;&amp;lt; @all_resp if @all_resp.is_submitted&lt;br /&gt;
        else&lt;br /&gt;
          @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
        end&lt;br /&gt;
        # sort all versions in descending order and get the latest one.&lt;br /&gt;
        # @sort_to=@array_sort.sort { |m1, m2| (m1.version_num and m2.version_num) ? m2.version_num &amp;lt;=&amp;gt; m1.version_num : (m1.version_num ? -1 : 1) }&lt;br /&gt;
        @sort_to = @array_sort.sort # { |m1, m2| (m1.updated_at and m2.updated_at) ? m2.updated_at &amp;lt;=&amp;gt; m1.updated_at : (m1.version_num ? -1 : 1) }&lt;br /&gt;
        responses &amp;lt;&amp;lt; @sort_to[0] unless @sort_to[0].nil?&lt;br /&gt;
        @array_sort.clear&lt;br /&gt;
        @sort_to.clear&lt;br /&gt;
      end&lt;br /&gt;
      responses = responses.sort {|a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== comparator ====&lt;br /&gt;
Compares two Responses version numbers and returns a -1,0, or 1 depending on which version number is greater. If there is no version number for the first response, -1 is returned, otherwise 1 is returned.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def comparator(m1, m2)&lt;br /&gt;
    if m1.version_num and m2.version_num&lt;br /&gt;
      m2.version_num &amp;lt;=&amp;gt; m1.version_num&lt;br /&gt;
    elsif m1.version_num&lt;br /&gt;
      -1&lt;br /&gt;
    else&lt;br /&gt;
      1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== self.reviewer_assessments_for(team, reviewer) ====&lt;br /&gt;
Gets the Responses for a team reviewed by a specific reviewer and returns the latest response.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # return latest versions of the response given by reviewer&lt;br /&gt;
  def self.reviewer_assessments_for(team, reviewer)&lt;br /&gt;
    # get_reviewer may return an AssignmentParticipant or an AssignmentTeam&lt;br /&gt;
    map = where(reviewee_id: team.id, reviewer_id: reviewer.get_reviewer.id)&lt;br /&gt;
    Response.where(map_id: map).sort {|m1, m2| self.comparator(m1, m2) }[0]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== metareviewed_by? ====&lt;br /&gt;
Returns whether the Response Map has been metareviewed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Evaluates whether this response_map was metareviewed by metareviewer&lt;br /&gt;
  # @param[in] metareviewer AssignmentParticipant object&lt;br /&gt;
  def metareviewed_by?(metareviewer)&lt;br /&gt;
    MetareviewResponseMap.where(reviewee_id: self.reviewer.id, reviewer_id: metareviewer.id, reviewed_object_id: self.id).count &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== assign_metareviewer ====&lt;br /&gt;
This function is in charge of assigning a metareviewer to this review (i.e. a reviewer to review the review).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Assigns a metareviewer to this review (response)&lt;br /&gt;
  # @param[in] metareviewer AssignmentParticipant object&lt;br /&gt;
  def assign_metareviewer(metareviewer)&lt;br /&gt;
    MetareviewResponseMap.create(reviewed_object_id: self.id,&lt;br /&gt;
                                 reviewer_id: metareviewer.id, reviewee_id: reviewer.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== find_team_member ====&lt;br /&gt;
This function returns the team that the reviewer is part of.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def find_team_member&lt;br /&gt;
    # ACS Have metareviews done for all teams&lt;br /&gt;
    if self.type.to_s == &amp;quot;MetareviewResponseMap&amp;quot;&lt;br /&gt;
        review_mapping = ResponseMap.find_by(id: map.reviewed_object_id)&lt;br /&gt;
        team = AssignmentTeam.find_by(id: review_mapping.reviewee_id)&lt;br /&gt;
    else&lt;br /&gt;
        team = AssignmentTeam.find(self.reviewee_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/models/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141606</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141606"/>
		<updated>2021-11-14T20:20:14Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza final project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
* review_response_map.rb  &amp;lt;--------- 92.5% coverage&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map.rb &amp;lt;------ 23.08% coverage&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
* response_map.rb &amp;lt;----------------- 74.47% coverage&lt;br /&gt;
&lt;br /&gt;
This project aims to get all the response maps to at least a 90% level of coverage for every Response Map file by writing unit tests for each uncovered method listed in the next section.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
* Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
* Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
* Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
* Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
== Test Files Involved ==&lt;br /&gt;
There are 4 test files involved in this project:&lt;br /&gt;
* review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* response_map_spec.rb&lt;br /&gt;
of these files, only review_response_map_spec.rb currently exists; the rest will be added.&lt;br /&gt;
&lt;br /&gt;
== Methods Tested Per File ==&lt;br /&gt;
&lt;br /&gt;
=== review_response_map_spec.rb ===&lt;br /&gt;
Currently this file is 92.5% covered and there are no plans to cover it further.&lt;br /&gt;
&lt;br /&gt;
=== metareview_response_map_spec.rb ===&lt;br /&gt;
The functions for metareview_response_map.rb that will be tested are:&lt;br /&gt;
====get_all_versions====&lt;br /&gt;
This returns a sorted array of all the different versions of what is being reviewed in this response map. This means for a test, we will need to create a reviewer, a reviewee, several types of reviews of different versions to be sorted correctly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# return all the versions available for a response map.&lt;br /&gt;
  # a person who is doing meta review has to be able to see all the versions of review.&lt;br /&gt;
  def get_all_versions&lt;br /&gt;
    if self.review_mapping.response&lt;br /&gt;
      @sorted_array = []&lt;br /&gt;
      @prev = Response.all&lt;br /&gt;
      @prev.each do |element|&lt;br /&gt;
        @sorted_array &amp;lt;&amp;lt; element if element.map_id == self.review_mapping.map_id&lt;br /&gt;
      end&lt;br /&gt;
      @sorted = @sorted_array.sort {|m1, m2| m1.version_num || if m2.version_num&lt;br /&gt;
                                                                  m1.version_num &amp;lt;=&amp;gt; m2.version_num&lt;br /&gt;
                                                                else&lt;br /&gt;
                                                                  m1.version_num ? -1 : 1&lt;br /&gt;
                                                                end }&lt;br /&gt;
      # return all the lists in ascending order.&lt;br /&gt;
      @sorted&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====contributor====&lt;br /&gt;
Returns the team associated with the ReviewResponseMap that is to be metareviewed. We will need to create a ReviewResponseMap that has a team associated with it. Then we must create MetareviewResponseMap that points to a created ReviewResponseMap via the reviewed_object_id attribute. We will test if it indeed returns the team associated with ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First, find the &amp;quot;ReviewResponseMap&amp;quot; to be metareviewed;&lt;br /&gt;
  # Second, find the team in the &amp;quot;ReviewResponseMap&amp;quot; record.&lt;br /&gt;
  def contributor&lt;br /&gt;
    team_review_map = ReviewResponseMap.find(self.reviewed_object_id)&lt;br /&gt;
    AssignmentTeam.find(team_review_map.reviewee_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====questionnaire====&lt;br /&gt;
Returns all questionnaires associated to the assignment of this MetareviewResponseMap that is of type 'MetareviewQuestionnaire'. We will need to create a valid MetareviewResponseMap including at least one MetareviewQuestionnaire that can be returned.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire&lt;br /&gt;
    self.assignment.questionnaires.find_by(type: 'MetareviewQuestionnaire')&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====get_title====&lt;br /&gt;
Returns string &amp;quot;Metareview&amp;quot;. We will test if this string is the same as typed out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def get_title&lt;br /&gt;
    &amp;quot;Metareview&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====exports====&lt;br /&gt;
This function takes 3 parameters: csv (the csv file that will contain the exported metareview information), parent_id (the assignment ID containing the requested metareviews), and _options. The function sends all the information about the metareviews to a csv file. We will test that the information is properly exported to the csv file.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.export(csv, parent_id, _options)&lt;br /&gt;
    mappings = Assignment.find(parent_id).metareview_mappings&lt;br /&gt;
    mappings = mappings.sort_by {|a| [a.review_mapping.reviewee.name, a.reviewee.name, a.reviewer.name] }&lt;br /&gt;
    mappings.each do |map|&lt;br /&gt;
      csv &amp;lt;&amp;lt; [&lt;br /&gt;
        map.review_mapping.reviewee.name,&lt;br /&gt;
        map.reviewee.name,&lt;br /&gt;
        map.reviewer.name&lt;br /&gt;
      ]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====export_fields====&lt;br /&gt;
Takes a parameter called &amp;quot;_options&amp;quot; that returns the three field columns associated with metareviews to be exported for use by other controllers. We will test to see that these three columns are properly returned.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.export_fields(_options)&lt;br /&gt;
    fields = [&amp;quot;contributor&amp;quot;, &amp;quot;reviewed by&amp;quot;, &amp;quot;metareviewed by&amp;quot;]&lt;br /&gt;
    fields&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====import====&lt;br /&gt;
This function takes 3 parameters: row_hash (represents the hash of the metareview data we want to import), session, and id (representing the id of the assignment we want to import metareview data for). The function imports the data from the hash map, and if the information is input correctly, the data is extracted from the hash and creates a metareview for the requested assignment, otherwise it flashes an error saying the data was input incorrectly. We will test to make sure the imported data is properly converted into a metareview.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-import.jpg]]&lt;br /&gt;
&lt;br /&gt;
====email====&lt;br /&gt;
This function takes 3 parameters: defn, _participant (the user who will be receiving the email), and assignment (the assignment associated with the metareview). The function sends an email to the participant when they have a new metareview to complete. We will test to make sure the email is sent to the correct participant.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def email(defn, _participant, assignment)&lt;br /&gt;
    defn[:body][:type] = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
    reviewee_user = Participant.find(reviewee_id)&lt;br /&gt;
    defn[:body][:obj_name] = assignment.name&lt;br /&gt;
    defn[:body][:first_name] = User.find(reviewee_user.user_id).fullname&lt;br /&gt;
    defn[:to] = User.find(reviewee_user.user_id).email&lt;br /&gt;
    Mailer.sync_message(defn).deliver&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== teammate_review_response_map_spec.rb ===&lt;br /&gt;
The functions for teammate_review_response_map.rb that will be tested are:&lt;br /&gt;
==== questionnaire ====&lt;br /&gt;
This function searches for a TeammateReviewQuestionnaire object and returns it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def questionnaire&lt;br /&gt;
    self.assignment.questionnaires.find_by(type: 'TeammateReviewQuestionnaire')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== get_title ====&lt;br /&gt;
This function returns the string &amp;quot;Teammate Review&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_title&lt;br /&gt;
    &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== teammate_response_report ====&lt;br /&gt;
This function returns the teammate response report given the reviewer ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.teammate_response_report(id)&lt;br /&gt;
    TeammateReviewResponseMap.select(&amp;quot;DISTINCT reviewer_id&amp;quot;).where(&amp;quot;reviewed_object_id = ?&amp;quot;, id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== email ====&lt;br /&gt;
This function sends a notification email to a student who has been reviewed by their teammate.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Send Teammate Review Emails&lt;br /&gt;
  # Refactored from email method in response.rb&lt;br /&gt;
  def email(defn, participant, assignment)&lt;br /&gt;
    defn[:body][:type] = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
    participant = AssignmentParticipant.find(reviewee_id)&lt;br /&gt;
    topic_id = SignedUpTeam.topic_id(participant.parent_id, participant.user_id)&lt;br /&gt;
    defn[:body][:obj_name] = assignment.name&lt;br /&gt;
    user = User.find(participant.user_id)&lt;br /&gt;
    defn[:body][:first_name] = user.fullname&lt;br /&gt;
    defn[:to] = user.email&lt;br /&gt;
    Mailer.sync_message(defn).deliver&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== response_map_spec.rb ===&lt;br /&gt;
The functions for response_map.rb that will be tested are:&lt;br /&gt;
==== self.assessments_for(team) ====&lt;br /&gt;
Gets all submitted Review Responses or all regular Responses for a team, sorts the responses by version, and returns the latest Responses.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-assessments_for.png]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # return latest versions of the responses&lt;br /&gt;
  def self.assessments_for(team)&lt;br /&gt;
    responses = []&lt;br /&gt;
    # stime = Time.now&lt;br /&gt;
    if team&lt;br /&gt;
      @array_sort = []&lt;br /&gt;
      @sort_to = []&lt;br /&gt;
      maps = where(reviewee_id: team.id)&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        next if map.response.empty?&lt;br /&gt;
        @all_resp = Response.where(map_id: map.map_id).last&lt;br /&gt;
        if map.type.eql?('ReviewResponseMap')&lt;br /&gt;
          # If its ReviewResponseMap then only consider those response which are submitted.&lt;br /&gt;
          @array_sort &amp;lt;&amp;lt; @all_resp if @all_resp.is_submitted&lt;br /&gt;
        else&lt;br /&gt;
          @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
        end&lt;br /&gt;
        # sort all versions in descending order and get the latest one.&lt;br /&gt;
        # @sort_to=@array_sort.sort { |m1, m2| (m1.version_num and m2.version_num) ? m2.version_num &amp;lt;=&amp;gt; m1.version_num : (m1.version_num ? -1 : 1) }&lt;br /&gt;
        @sort_to = @array_sort.sort # { |m1, m2| (m1.updated_at and m2.updated_at) ? m2.updated_at &amp;lt;=&amp;gt; m1.updated_at : (m1.version_num ? -1 : 1) }&lt;br /&gt;
        responses &amp;lt;&amp;lt; @sort_to[0] unless @sort_to[0].nil?&lt;br /&gt;
        @array_sort.clear&lt;br /&gt;
        @sort_to.clear&lt;br /&gt;
      end&lt;br /&gt;
      responses = responses.sort {|a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== comparator ====&lt;br /&gt;
Compares two Responses version numbers and returns a -1,0, or 1 depending on which version number is greater. If there is no version number for the first response, -1 is returned, otherwise 1 is returned.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def comparator(m1, m2)&lt;br /&gt;
    if m1.version_num and m2.version_num&lt;br /&gt;
      m2.version_num &amp;lt;=&amp;gt; m1.version_num&lt;br /&gt;
    elsif m1.version_num&lt;br /&gt;
      -1&lt;br /&gt;
    else&lt;br /&gt;
      1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== self.reviewer_assessments_for(team, reviewer) ====&lt;br /&gt;
Gets the Responses for a team reviewed by a specific reviewer and returns the latest response.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # return latest versions of the response given by reviewer&lt;br /&gt;
  def self.reviewer_assessments_for(team, reviewer)&lt;br /&gt;
    # get_reviewer may return an AssignmentParticipant or an AssignmentTeam&lt;br /&gt;
    map = where(reviewee_id: team.id, reviewer_id: reviewer.get_reviewer.id)&lt;br /&gt;
    Response.where(map_id: map).sort {|m1, m2| self.comparator(m1, m2) }[0]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== metareviewed_by? ====&lt;br /&gt;
Returns whether the Response Map has been metareviewed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Evaluates whether this response_map was metareviewed by metareviewer&lt;br /&gt;
  # @param[in] metareviewer AssignmentParticipant object&lt;br /&gt;
  def metareviewed_by?(metareviewer)&lt;br /&gt;
    MetareviewResponseMap.where(reviewee_id: self.reviewer.id, reviewer_id: metareviewer.id, reviewed_object_id: self.id).count &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== assign_metareviewer ====&lt;br /&gt;
This function is in charge of assigning a metareviewer to this review (i.e. a reviewer to review the review).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Assigns a metareviewer to this review (response)&lt;br /&gt;
  # @param[in] metareviewer AssignmentParticipant object&lt;br /&gt;
  def assign_metareviewer(metareviewer)&lt;br /&gt;
    MetareviewResponseMap.create(reviewed_object_id: self.id,&lt;br /&gt;
                                 reviewer_id: metareviewer.id, reviewee_id: reviewer.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== find_team_member ====&lt;br /&gt;
This function returns the team that the reviewer is part of.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def find_team_member&lt;br /&gt;
    # ACS Have metareviews done for all teams&lt;br /&gt;
    if self.type.to_s == &amp;quot;MetareviewResponseMap&amp;quot;&lt;br /&gt;
        review_mapping = ResponseMap.find_by(id: map.reviewed_object_id)&lt;br /&gt;
        team = AssignmentTeam.find_by(id: review_mapping.reviewee_id)&lt;br /&gt;
    else&lt;br /&gt;
        team = AssignmentTeam.find(self.reviewee_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/models/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141605</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141605"/>
		<updated>2021-11-14T20:02:44Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Running Tests */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
* review_response_map.rb  &amp;lt;--------- 92.5% coverage&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map.rb &amp;lt;------ 23.08% coverage&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
* response_map.rb &amp;lt;----------------- 74.47% coverage&lt;br /&gt;
&lt;br /&gt;
This project aims to get all the response maps to at least a 90% level of coverage for every Response Map file by writing unit tests for each uncovered method listed in the next section.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
* Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
* Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
* Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
* Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
== Test Files Involved ==&lt;br /&gt;
There are 4 test files involved in this project:&lt;br /&gt;
* review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* response_map_spec.rb&lt;br /&gt;
of these files, only review_response_map_spec.rb currently exists; the rest will be added.&lt;br /&gt;
&lt;br /&gt;
== Methods Tested Per File ==&lt;br /&gt;
&lt;br /&gt;
=== review_response_map_spec.rb ===&lt;br /&gt;
Currently this file is 92.5% covered and there are no plans to cover it further.&lt;br /&gt;
&lt;br /&gt;
=== metareview_response_map_spec.rb ===&lt;br /&gt;
The functions for metareview_response_map.rb that will be tested are:&lt;br /&gt;
====get_all_versions====&lt;br /&gt;
This returns a sorted array of all the different versions of what is being reviewed in this response map. This means for a test, we will need to create a reviewer, a reviewee, several types of reviews of different versions to be sorted correctly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# return all the versions available for a response map.&lt;br /&gt;
  # a person who is doing meta review has to be able to see all the versions of review.&lt;br /&gt;
  def get_all_versions&lt;br /&gt;
    if self.review_mapping.response&lt;br /&gt;
      @sorted_array = []&lt;br /&gt;
      @prev = Response.all&lt;br /&gt;
      @prev.each do |element|&lt;br /&gt;
        @sorted_array &amp;lt;&amp;lt; element if element.map_id == self.review_mapping.map_id&lt;br /&gt;
      end&lt;br /&gt;
      @sorted = @sorted_array.sort {|m1, m2| m1.version_num || if m2.version_num&lt;br /&gt;
                                                                  m1.version_num &amp;lt;=&amp;gt; m2.version_num&lt;br /&gt;
                                                                else&lt;br /&gt;
                                                                  m1.version_num ? -1 : 1&lt;br /&gt;
                                                                end }&lt;br /&gt;
      # return all the lists in ascending order.&lt;br /&gt;
      @sorted&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====contributor====&lt;br /&gt;
Returns the team associated with the ReviewResponseMap that is to be metareviewed. We will need to create a ReviewResponseMap that has a team associated with it. Then we must create MetareviewResponseMap that points to a created ReviewResponseMap via the reviewed_object_id attribute. We will test if it indeed returns the team associated with ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First, find the &amp;quot;ReviewResponseMap&amp;quot; to be metareviewed;&lt;br /&gt;
  # Second, find the team in the &amp;quot;ReviewResponseMap&amp;quot; record.&lt;br /&gt;
  def contributor&lt;br /&gt;
    team_review_map = ReviewResponseMap.find(self.reviewed_object_id)&lt;br /&gt;
    AssignmentTeam.find(team_review_map.reviewee_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====questionnaire====&lt;br /&gt;
Returns all questionnaires associated to the assignment of this MetareviewResponseMap that is of type 'MetareviewQuestionnaire'. We will need to create a valid MetareviewResponseMap including at least one MetareviewQuestionnaire that can be returned.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire&lt;br /&gt;
    self.assignment.questionnaires.find_by(type: 'MetareviewQuestionnaire')&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====get_title====&lt;br /&gt;
Returns string &amp;quot;Metareview&amp;quot;. We will test if this string is the same as typed out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def get_title&lt;br /&gt;
    &amp;quot;Metareview&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====exports====&lt;br /&gt;
This function takes 3 parameters: csv (the csv file that will contain the exported metareview information), parent_id (the assignment ID containing the requested metareviews), and _options. The function sends all the information about the metareviews to a csv file. We will test that the information is properly exported to the csv file.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.export(csv, parent_id, _options)&lt;br /&gt;
    mappings = Assignment.find(parent_id).metareview_mappings&lt;br /&gt;
    mappings = mappings.sort_by {|a| [a.review_mapping.reviewee.name, a.reviewee.name, a.reviewer.name] }&lt;br /&gt;
    mappings.each do |map|&lt;br /&gt;
      csv &amp;lt;&amp;lt; [&lt;br /&gt;
        map.review_mapping.reviewee.name,&lt;br /&gt;
        map.reviewee.name,&lt;br /&gt;
        map.reviewer.name&lt;br /&gt;
      ]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====export_fields====&lt;br /&gt;
Takes a parameter called &amp;quot;_options&amp;quot; that returns the three field columns associated with metareviews to be exported for use by other controllers. We will test to see that these three columns are properly returned.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.export_fields(_options)&lt;br /&gt;
    fields = [&amp;quot;contributor&amp;quot;, &amp;quot;reviewed by&amp;quot;, &amp;quot;metareviewed by&amp;quot;]&lt;br /&gt;
    fields&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====import====&lt;br /&gt;
This function takes 3 parameters: row_hash (represents the hash of the metareview data we want to import), session, and id (representing the id of the assignment we want to import metareview data for). The function imports the data from the hash map, and if the information is input correctly, the data is extracted from the hash and creates a metareview for the requested assignment, otherwise it flashes an error saying the data was input incorrectly. We will test to make sure the imported data is properly converted into a metareview.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-import.jpg]]&lt;br /&gt;
&lt;br /&gt;
====email====&lt;br /&gt;
This function takes 3 parameters: defn, _participant (the user who will be receiving the email), and assignment (the assignment associated with the metareview). The function sends an email to the participant when they have a new metareview to complete. We will test to make sure the email is sent to the correct participant.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def email(defn, _participant, assignment)&lt;br /&gt;
    defn[:body][:type] = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
    reviewee_user = Participant.find(reviewee_id)&lt;br /&gt;
    defn[:body][:obj_name] = assignment.name&lt;br /&gt;
    defn[:body][:first_name] = User.find(reviewee_user.user_id).fullname&lt;br /&gt;
    defn[:to] = User.find(reviewee_user.user_id).email&lt;br /&gt;
    Mailer.sync_message(defn).deliver&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== teammate_review_response_map_spec.rb ===&lt;br /&gt;
The functions for teammate_review_response_map.rb that will be tested are:&lt;br /&gt;
==== questionnaire ====&lt;br /&gt;
This function searches for a TeammateReviewQuestionnaire object and returns it.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def questionnaire&lt;br /&gt;
    self.assignment.questionnaires.find_by(type: 'TeammateReviewQuestionnaire')&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== get_title ====&lt;br /&gt;
This function returns the string &amp;quot;Teammate Review&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def get_title&lt;br /&gt;
    &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== teammate_response_report ====&lt;br /&gt;
This function returns the teammate response report given the reviewer ID.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.teammate_response_report(id)&lt;br /&gt;
    TeammateReviewResponseMap.select(&amp;quot;DISTINCT reviewer_id&amp;quot;).where(&amp;quot;reviewed_object_id = ?&amp;quot;, id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== email ====&lt;br /&gt;
This function sends a notification email to a student who has been reviewed by their teammate.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Send Teammate Review Emails&lt;br /&gt;
  # Refactored from email method in response.rb&lt;br /&gt;
  def email(defn, participant, assignment)&lt;br /&gt;
    defn[:body][:type] = &amp;quot;Teammate Review&amp;quot;&lt;br /&gt;
    participant = AssignmentParticipant.find(reviewee_id)&lt;br /&gt;
    topic_id = SignedUpTeam.topic_id(participant.parent_id, participant.user_id)&lt;br /&gt;
    defn[:body][:obj_name] = assignment.name&lt;br /&gt;
    user = User.find(participant.user_id)&lt;br /&gt;
    defn[:body][:first_name] = user.fullname&lt;br /&gt;
    defn[:to] = user.email&lt;br /&gt;
    Mailer.sync_message(defn).deliver&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== response_map_spec.rb ===&lt;br /&gt;
The functions for response_map.rb that will be tested are:&lt;br /&gt;
==== self.assessments_for(team) ====&lt;br /&gt;
Gets all submitted Review Responses or all regular Responses for a team, sorts the responses by version, and returns the latest Responses.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-assessments_for.png]]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # return latest versions of the responses&lt;br /&gt;
  def self.assessments_for(team)&lt;br /&gt;
    responses = []&lt;br /&gt;
    # stime = Time.now&lt;br /&gt;
    if team&lt;br /&gt;
      @array_sort = []&lt;br /&gt;
      @sort_to = []&lt;br /&gt;
      maps = where(reviewee_id: team.id)&lt;br /&gt;
      maps.each do |map|&lt;br /&gt;
        next if map.response.empty?&lt;br /&gt;
        @all_resp = Response.where(map_id: map.map_id).last&lt;br /&gt;
        if map.type.eql?('ReviewResponseMap')&lt;br /&gt;
          # If its ReviewResponseMap then only consider those response which are submitted.&lt;br /&gt;
          @array_sort &amp;lt;&amp;lt; @all_resp if @all_resp.is_submitted&lt;br /&gt;
        else&lt;br /&gt;
          @array_sort &amp;lt;&amp;lt; @all_resp&lt;br /&gt;
        end&lt;br /&gt;
        # sort all versions in descending order and get the latest one.&lt;br /&gt;
        # @sort_to=@array_sort.sort { |m1, m2| (m1.version_num and m2.version_num) ? m2.version_num &amp;lt;=&amp;gt; m1.version_num : (m1.version_num ? -1 : 1) }&lt;br /&gt;
        @sort_to = @array_sort.sort # { |m1, m2| (m1.updated_at and m2.updated_at) ? m2.updated_at &amp;lt;=&amp;gt; m1.updated_at : (m1.version_num ? -1 : 1) }&lt;br /&gt;
        responses &amp;lt;&amp;lt; @sort_to[0] unless @sort_to[0].nil?&lt;br /&gt;
        @array_sort.clear&lt;br /&gt;
        @sort_to.clear&lt;br /&gt;
      end&lt;br /&gt;
      responses = responses.sort {|a, b| a.map.reviewer.fullname &amp;lt;=&amp;gt; b.map.reviewer.fullname }&lt;br /&gt;
    end&lt;br /&gt;
    responses&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== comparator ====&lt;br /&gt;
Compares two Responses version numbers and returns a -1,0, or 1 depending on which version number is greater. If there is no version number for the first response, -1 is returned, otherwise 1 is returned.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def comparator(m1, m2)&lt;br /&gt;
    if m1.version_num and m2.version_num&lt;br /&gt;
      m2.version_num &amp;lt;=&amp;gt; m1.version_num&lt;br /&gt;
    elsif m1.version_num&lt;br /&gt;
      -1&lt;br /&gt;
    else&lt;br /&gt;
      1&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== self.reviewer_assessments_for(team, reviewer) ====&lt;br /&gt;
Gets the Responses for a team reviewed by a specific reviewer and returns the latest response.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # return latest versions of the response given by reviewer&lt;br /&gt;
  def self.reviewer_assessments_for(team, reviewer)&lt;br /&gt;
    # get_reviewer may return an AssignmentParticipant or an AssignmentTeam&lt;br /&gt;
    map = where(reviewee_id: team.id, reviewer_id: reviewer.get_reviewer.id)&lt;br /&gt;
    Response.where(map_id: map).sort {|m1, m2| self.comparator(m1, m2) }[0]&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== metareviewed_by? ====&lt;br /&gt;
Returns whether the Response Map has been metareviewed&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Evaluates whether this response_map was metareviewed by metareviewer&lt;br /&gt;
  # @param[in] metareviewer AssignmentParticipant object&lt;br /&gt;
  def metareviewed_by?(metareviewer)&lt;br /&gt;
    MetareviewResponseMap.where(reviewee_id: self.reviewer.id, reviewer_id: metareviewer.id, reviewed_object_id: self.id).count &amp;gt; 0&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== assign_metareviewer ====&lt;br /&gt;
This function is in charge of assigning a metareviewer to this review (i.e. a reviewer to review the review).&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # Assigns a metareviewer to this review (response)&lt;br /&gt;
  # @param[in] metareviewer AssignmentParticipant object&lt;br /&gt;
  def assign_metareviewer(metareviewer)&lt;br /&gt;
    MetareviewResponseMap.create(reviewed_object_id: self.id,&lt;br /&gt;
                                 reviewer_id: metareviewer.id, reviewee_id: reviewer.id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== find_team_member ====&lt;br /&gt;
This function returns the team that the reviewer is part of.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def find_team_member&lt;br /&gt;
    # ACS Have metareviews done for all teams&lt;br /&gt;
    if self.type.to_s == &amp;quot;MetareviewResponseMap&amp;quot;&lt;br /&gt;
        review_mapping = ResponseMap.find_by(id: map.reviewed_object_id)&lt;br /&gt;
        team = AssignmentTeam.find_by(id: review_mapping.reviewee_id)&lt;br /&gt;
    else&lt;br /&gt;
        team = AssignmentTeam.find(self.reviewee_id)&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/models/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141425</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141425"/>
		<updated>2021-11-09T03:28:00Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* metareview_response_map_spec.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
* review_response_map.rb  &amp;lt;--------- 92.5% coverage&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map.rb &amp;lt;------ 23.08% coverage&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
* response_map.rb &amp;lt;----------------- 74.47% coverage&lt;br /&gt;
&lt;br /&gt;
This project aims to get all the response maps to at least a 90% level of coverage for every Response Map file by writing unit tests for each uncovered method listed in the next section.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
* Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
* Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
* Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
* Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
== Test Files Involved ==&lt;br /&gt;
There are 4 test files involved in this project:&lt;br /&gt;
* review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* response_map_spec.rb&lt;br /&gt;
of these files, only review_response_map_spec.rb currently exists; the rest will be added.&lt;br /&gt;
&lt;br /&gt;
== Methods Tested Per File ==&lt;br /&gt;
&lt;br /&gt;
=== review_response_map_spec.rb ===&lt;br /&gt;
Currently this file is 92.5% covered and there are no plans to cover it further.&lt;br /&gt;
&lt;br /&gt;
=== metareview_response_map_spec.rb ===&lt;br /&gt;
The functions for metareview_response_map.rb that will be tested are:&lt;br /&gt;
====get_all_versions====&lt;br /&gt;
This returns a sorted array of all the different versions of what is being reviewed in this response map. This means for a test, we will need to create a reviewer, a reviewee, several types of reviews of different versions to be sorted correctly.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# return all the versions available for a response map.&lt;br /&gt;
  # a person who is doing meta review has to be able to see all the versions of review.&lt;br /&gt;
  def get_all_versions&lt;br /&gt;
    if self.review_mapping.response&lt;br /&gt;
      @sorted_array = []&lt;br /&gt;
      @prev = Response.all&lt;br /&gt;
      @prev.each do |element|&lt;br /&gt;
        @sorted_array &amp;lt;&amp;lt; element if element.map_id == self.review_mapping.map_id&lt;br /&gt;
      end&lt;br /&gt;
      @sorted = @sorted_array.sort {|m1, m2| m1.version_num || if m2.version_num&lt;br /&gt;
                                                                  m1.version_num &amp;lt;=&amp;gt; m2.version_num&lt;br /&gt;
                                                                else&lt;br /&gt;
                                                                  m1.version_num ? -1 : 1&lt;br /&gt;
                                                                end }&lt;br /&gt;
      # return all the lists in ascending order.&lt;br /&gt;
      @sorted&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====contributor====&lt;br /&gt;
Returns the team associated with the ReviewResponseMap that is to be metareviewed. We will need to create a ReviewResponseMap that has a team associated with it. Then we must create MetareviewResponseMap that points to a created ReviewResponseMap via the reviewed_object_id attribute. We will test if it indeed returns the team associated with ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
# First, find the &amp;quot;ReviewResponseMap&amp;quot; to be metareviewed;&lt;br /&gt;
  # Second, find the team in the &amp;quot;ReviewResponseMap&amp;quot; record.&lt;br /&gt;
  def contributor&lt;br /&gt;
    team_review_map = ReviewResponseMap.find(self.reviewed_object_id)&lt;br /&gt;
    AssignmentTeam.find(team_review_map.reviewee_id)&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====questionnaire====&lt;br /&gt;
Returns all questionnaires associated to the assignment of this MetareviewResponseMap that is of type 'MetareviewQuestionnaire'. We will need to create a valid MetareviewResponseMap including at least one MetareviewQuestionnaire that can be returned.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def questionnaire&lt;br /&gt;
    self.assignment.questionnaires.find_by(type: 'MetareviewQuestionnaire')&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====get_title====&lt;br /&gt;
Returns string &amp;quot;Metareview&amp;quot;. We will test if this string is the same as typed out.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def get_title&lt;br /&gt;
    &amp;quot;Metareview&amp;quot;&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====exports====&lt;br /&gt;
This function takes 3 parameters: csv (the csv file that will contain the exported metareview information), parent_id (the assignment ID containing the requested metareviews), and _options. The function sends all the information about the metareviews to a csv file. We will test that the information is properly exported to the csv file.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.export(csv, parent_id, _options)&lt;br /&gt;
    mappings = Assignment.find(parent_id).metareview_mappings&lt;br /&gt;
    mappings = mappings.sort_by {|a| [a.review_mapping.reviewee.name, a.reviewee.name, a.reviewer.name] }&lt;br /&gt;
    mappings.each do |map|&lt;br /&gt;
      csv &amp;lt;&amp;lt; [&lt;br /&gt;
        map.review_mapping.reviewee.name,&lt;br /&gt;
        map.reviewee.name,&lt;br /&gt;
        map.reviewer.name&lt;br /&gt;
      ]&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====export_fields====&lt;br /&gt;
Takes a parameter called &amp;quot;_options&amp;quot; that returns the three field columns associated with metareviews to be exported for use by other controllers. We will test to see that these three columns are properly returned.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def self.export_fields(_options)&lt;br /&gt;
    fields = [&amp;quot;contributor&amp;quot;, &amp;quot;reviewed by&amp;quot;, &amp;quot;metareviewed by&amp;quot;]&lt;br /&gt;
    fields&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====import====&lt;br /&gt;
This function takes 3 parameters: row_hash (represents the hash of the metareview data we want to import), session, and id (representing the id of the assignment we want to import metareview data for). The function imports the data from the hash map, and if the information is input correctly, the data is extracted from the hash and creates a metareview for the requested assignment, otherwise it flashes an error saying the data was input incorrectly. We will test to make sure the imported data is properly converted into a metareview.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-import.jpg]]&lt;br /&gt;
&lt;br /&gt;
====email====&lt;br /&gt;
This function takes 3 parameters: defn, _participant (the user who will be receiving the email), and assignment (the assignment associated with the metareview). The function sends an email to the participant when they have a new metareview to complete. We will test to make sure the email is sent to the correct participant.&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def email(defn, _participant, assignment)&lt;br /&gt;
    defn[:body][:type] = &amp;quot;Metareview&amp;quot;&lt;br /&gt;
    reviewee_user = Participant.find(reviewee_id)&lt;br /&gt;
    defn[:body][:obj_name] = assignment.name&lt;br /&gt;
    defn[:body][:first_name] = User.find(reviewee_user.user_id).fullname&lt;br /&gt;
    defn[:to] = User.find(reviewee_user.user_id).email&lt;br /&gt;
    Mailer.sync_message(defn).deliver&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== teammate_review_response_map_spec.rb ===&lt;br /&gt;
The functions for teammate_review_response_map.rb that will be tested are:&lt;br /&gt;
==== questionnaire ====&lt;br /&gt;
This function searches for a TeammateReviewQuestionnaire object and returns it.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate review response map-questionnaire.PNG]]&lt;br /&gt;
&lt;br /&gt;
==== get_title ====&lt;br /&gt;
This function returns the string &amp;quot;Teammate Review&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-get_title.png]]&lt;br /&gt;
&lt;br /&gt;
==== teammate_response_report ====&lt;br /&gt;
This function returns the teammate response report given the reviewer ID.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-teammate_response_report.PNG]]&lt;br /&gt;
&lt;br /&gt;
==== email ====&lt;br /&gt;
This function sends a notification email to a student who has been reviewed by their teammate.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-email.png]]&lt;br /&gt;
&lt;br /&gt;
=== response_map_spec.rb ===&lt;br /&gt;
The functions for response_map.rb that will be tested are:&lt;br /&gt;
==== self.assessments_for(team) ====&lt;br /&gt;
Gets all submitted Review Responses or all regular Responses for a team, sorts the responses by version, and returns the latest Responses.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-assessments_for.png]]&lt;br /&gt;
&lt;br /&gt;
==== comparator ====&lt;br /&gt;
Compares two Responses version numbers and returns a -1,0, or 1 depending on which version number is greater. If there is no version number for the first response, -1 is returned, otherwise 1 is returned.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-comparator.png]]&lt;br /&gt;
&lt;br /&gt;
==== self.reviewer_assessments_for(team, reviewer) ====&lt;br /&gt;
Gets the Responses for a team reviewed by a specific reviewer and returns the latest response.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-reviewer_assessments_for.png]]&lt;br /&gt;
&lt;br /&gt;
==== metareviewed_by? ====&lt;br /&gt;
Returns whether the Response Map has been metareviewed&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-metareviewed_by.png]]&lt;br /&gt;
&lt;br /&gt;
==== assign_metareviewer ====&lt;br /&gt;
This function is in charge of assigning a metareviewer to this review (i.e. a reviewer to review the review).&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-response_map-assign_metareviewer.png]]&lt;br /&gt;
&lt;br /&gt;
==== find_team_member ====&lt;br /&gt;
This function returns the team that the reviewer is part of.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-response_map-find_team_member.png]]&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141263</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141263"/>
		<updated>2021-11-08T20:31:36Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Methods Tested Per File */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
* review_response_map.rb  &amp;lt;--------- 92.5% coverage&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map.rb &amp;lt;------ 23.08% coverage&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
* response_map.rb &amp;lt;----------------- 74.47% coverage&lt;br /&gt;
&lt;br /&gt;
This project aims to get all the response maps to at least a 90% level of coverage for every Response Map file by writing unit tests for each uncovered method listed in the next section.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
* Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
* Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
* Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
* Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
== Test Files Involved ==&lt;br /&gt;
There are 4 test files involved in this project:&lt;br /&gt;
* review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* response_map_spec.rb&lt;br /&gt;
of these files, only review_response_map_spec.rb currently exists; the rest will be added.&lt;br /&gt;
&lt;br /&gt;
== Methods Tested Per File ==&lt;br /&gt;
&lt;br /&gt;
=== review_response_map_spec.rb ===&lt;br /&gt;
Currently this file is 92.5% covered and there are no plans to cover it further.&lt;br /&gt;
&lt;br /&gt;
=== metareview_response_map_spec.rb ===&lt;br /&gt;
The functions for metareview_response_map.rb that will be tested are:&lt;br /&gt;
====get_all_versions====&lt;br /&gt;
This returns a sorted array of all the different versions of what is being reviewed in this response map. This means for a test, we will need to create a reviewer, a reviewee, several types of reviews of different versions to be sorted correctly.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-get all versions.PNG]]&lt;br /&gt;
&lt;br /&gt;
====contributor====&lt;br /&gt;
Returns the team associated with the ReviewResponseMap that is to be metareviewed. We will need to create a ReviewResponseMap that has a team associated with it. Then we must create MetareviewResponseMap that points to a created ReviewResponseMap via the reviewed_object_id attribute. We will test if it indeed returns the team associated with ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-contributor.PNG]]&lt;br /&gt;
&lt;br /&gt;
====questionnaire====&lt;br /&gt;
Returns all questionnaires associated to the assignment of this MetareviewResponseMap that is of type 'MetareviewQuestionnaire'. We will need to create a valid MetareviewResponseMap including at least one MetareviewQuestionnaire that can be returned.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-questionnaire.PNG]]&lt;br /&gt;
&lt;br /&gt;
====get_title====&lt;br /&gt;
Returns string &amp;quot;Metareview&amp;quot;. We will test if this string is the same as typed out.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-get title.PNG]]&lt;br /&gt;
&lt;br /&gt;
====exports====&lt;br /&gt;
This function takes 3 parameters: csv (the csv file that will contain the exported metareview information), parent_id (the assignment ID containing the requested metareviews), and _options. The function sends all the information about the metareviews to a csv file. We will test that the information is properly exported to the csv file.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-export.jpg]]&lt;br /&gt;
&lt;br /&gt;
====export_fields====&lt;br /&gt;
Takes a parameter called &amp;quot;_options&amp;quot; that returns the three field columns associated with metareviews to be exported for use by other controllers. We will test to see that these three columns are properly returned.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-export_fields.jpg]]&lt;br /&gt;
&lt;br /&gt;
====import====&lt;br /&gt;
This function takes 3 parameters: row_hash (represents the hash of the metareview data we want to import), session, and id (representing the id of the assignment we want to import metareview data for). The function imports the data from the hash map, and if the information is input correctly, the data is extracted from the hash and creates a metareview for the requested assignment, otherwise it flashes an error saying the data was input incorrectly. We will test to make sure the imported data is properly converted into a metareview.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-import.jpg]]&lt;br /&gt;
&lt;br /&gt;
====email====&lt;br /&gt;
This function takes 3 parameters: defn, _participant (the user who will be receiving the email), and assignment (the assignment associated with the metareview). The function sends an email to the participant when they have a new metareview to complete. We will test to make sure the email is sent to the correct participant.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-email.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== teammate_review_response_map_spec.rb ===&lt;br /&gt;
The functions for teammate_review_response_map.rb that will be tested are:&lt;br /&gt;
==== questionnaire ====&lt;br /&gt;
This function searches for a TeammateReviewQuestionnaire object and returns it.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate review response map-questionnaire.PNG]]&lt;br /&gt;
&lt;br /&gt;
==== get_title ====&lt;br /&gt;
This function returns the string &amp;quot;Teammate Review&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-get_title.png]]&lt;br /&gt;
&lt;br /&gt;
==== teammate_response_report ====&lt;br /&gt;
This function returns the teammate response report given the reviewer ID.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-teammate_response_report.PNG]]&lt;br /&gt;
&lt;br /&gt;
==== email ====&lt;br /&gt;
This function sends a notification email to a student who has been reviewed by their teammate.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-email.png]]&lt;br /&gt;
&lt;br /&gt;
=== response_map_spec.rb ===&lt;br /&gt;
The functions for response_map.rb that will be tested are:&lt;br /&gt;
* self.assessments_for(team)&lt;br /&gt;
* comparator&lt;br /&gt;
* self.reviewer_assessments_for(team, reviewer)&lt;br /&gt;
* metareviewed_by?&lt;br /&gt;
==== assign_metareviewer ====&lt;br /&gt;
This function is in charge of assigning a metareviewer to this review (i.e. a reviewer to review the review).&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-response_map-assign_metareviewer.png]]&lt;br /&gt;
&lt;br /&gt;
==== find_team_member ====&lt;br /&gt;
This function returns the team that the reviewer is part of.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-response_map-find_team_member.png]]&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141262</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141262"/>
		<updated>2021-11-08T20:30:18Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* metareview_response_map_spec.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
* review_response_map.rb  &amp;lt;--------- 92.5% coverage&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map.rb &amp;lt;------ 23.08% coverage&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
* response_map.rb &amp;lt;----------------- 74.47% coverage&lt;br /&gt;
&lt;br /&gt;
This project aims to get all the response maps to at least a 90% level of coverage for every Response Map file by writing unit tests for each uncovered method listed in the next section.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
* Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
* Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
* Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
* Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
== Test Files Involved ==&lt;br /&gt;
There are 4 test files involved in this project:&lt;br /&gt;
* review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* response_map_spec.rb&lt;br /&gt;
of these files, only review_response_map_spec.rb currently exists; the rest will be added.&lt;br /&gt;
&lt;br /&gt;
== Methods Tested Per File ==&lt;br /&gt;
&lt;br /&gt;
=== review_response_map_spec.rb ===&lt;br /&gt;
Currently this file is 92.5% covered and there are no plans to cover it further.&lt;br /&gt;
&lt;br /&gt;
=== metareview_response_map_spec.rb ===&lt;br /&gt;
The functions for metareview_response_map.rb that will be tested are:&lt;br /&gt;
====get_all_versions====&lt;br /&gt;
This returns a sorted array of all the different versions of what is being reviewed in this response map. This means for a test, we will need to create a reviewer, a reviewee, several types of reviews of different versions to be sorted correctly.&lt;br /&gt;
[[File:E2170-get all versions.PNG]]&lt;br /&gt;
&lt;br /&gt;
====contributor====&lt;br /&gt;
Returns the team associated with the ReviewResponseMap that is to be metareviewed. We will need to create a ReviewResponseMap that has a team associated with it. Then we must create MetareviewResponseMap that points to a created ReviewResponseMap via the reviewed_object_id attribute. We will test if it indeed returns the team associated with ReviewResponseMap.&lt;br /&gt;
[[File:E2170-contributor.PNG]]&lt;br /&gt;
&lt;br /&gt;
====questionnaire====&lt;br /&gt;
Returns all questionnaires associated to the assignment of this MetareviewResponseMap that is of type 'MetareviewQuestionnaire'. We will need to create a valid MetareviewResponseMap including at least one MetareviewQuestionnaire that can be returned.&lt;br /&gt;
[[File:E2170-questionnaire.PNG]]&lt;br /&gt;
&lt;br /&gt;
====get_title====&lt;br /&gt;
Returns string &amp;quot;Metareview&amp;quot;. We will test if this string is the same as typed out.&lt;br /&gt;
[[File:E2170-get title.PNG]]&lt;br /&gt;
&lt;br /&gt;
====exports====&lt;br /&gt;
This function takes 3 parameters: csv (the csv file that will contain the exported metareview information), parent_id (the assignment ID containing the requested metareviews), and _options. The function sends all the information about the metareviews to a csv file. We will test that the information is properly exported to the csv file.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-export.jpg]]&lt;br /&gt;
&lt;br /&gt;
====export_fields====&lt;br /&gt;
Takes a parameter called &amp;quot;_options&amp;quot; that returns the three field columns associated with metareviews to be exported for use by other controllers. We will test to see that these three columns are properly returned.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-export_fields.jpg]]&lt;br /&gt;
&lt;br /&gt;
====import====&lt;br /&gt;
This function takes 3 parameters: row_hash (represents the hash of the metareview data we want to import), session, and id (representing the id of the assignment we want to import metareview data for). The function imports the data from the hash map, and if the information is input correctly, the data is extracted from the hash and creates a metareview for the requested assignment, otherwise it flashes an error saying the data was input incorrectly. We will test to make sure the imported data is properly converted into a metareview.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-import.jpg]]&lt;br /&gt;
&lt;br /&gt;
====email====&lt;br /&gt;
This function takes 3 parameters: defn, _participant (the user who will be receiving the email), and assignment (the assignment associated with the metareview). The function sends an email to the participant when they have a new metareview to complete. We will test to make sure the email is sent to the correct participant.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-email.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== teammate_review_response_map_spec.rb ===&lt;br /&gt;
The functions for teammate_review_response_map.rb that will be tested are:&lt;br /&gt;
==== questionnaire ====&lt;br /&gt;
This function searches for a TeammateReviewQuestionnaire object and returns it.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate review response map-questionnaire.PNG]]&lt;br /&gt;
&lt;br /&gt;
==== get_title ====&lt;br /&gt;
This function returns the string &amp;quot;Teammate Review&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-get_title.png]]&lt;br /&gt;
&lt;br /&gt;
==== teammate_response_report ====&lt;br /&gt;
This function returns the teammate response report given the reviewer ID.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-teammate_response_report.PNG]]&lt;br /&gt;
&lt;br /&gt;
==== email ====&lt;br /&gt;
This function sends a notification email to a student who has been reviewed by their teammate.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-email.png]]&lt;br /&gt;
&lt;br /&gt;
=== response_map_spec.rb ===&lt;br /&gt;
The functions for response_map.rb that will be tested are:&lt;br /&gt;
* self.assessments_for(team)&lt;br /&gt;
* comparator&lt;br /&gt;
* self.reviewer_assessments_for(team, reviewer)&lt;br /&gt;
* metareviewed_by?&lt;br /&gt;
==== assign_metareviewer ====&lt;br /&gt;
This function is in charge of assigning a metareviewer to this review (i.e. a reviewer to review the review).&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-response_map-assign_metareviewer.png]]&lt;br /&gt;
&lt;br /&gt;
==== find_team_member ====&lt;br /&gt;
This function returns the team that the reviewer is part of.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-response_map-find_team_member.png]]&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E2170-get_title.PNG&amp;diff=141261</id>
		<title>File:E2170-get title.PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E2170-get_title.PNG&amp;diff=141261"/>
		<updated>2021-11-08T20:29:57Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E2170-questionnaire.PNG&amp;diff=141260</id>
		<title>File:E2170-questionnaire.PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E2170-questionnaire.PNG&amp;diff=141260"/>
		<updated>2021-11-08T20:29:33Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E2170-get_all_versions.PNG&amp;diff=141259</id>
		<title>File:E2170-get all versions.PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E2170-get_all_versions.PNG&amp;diff=141259"/>
		<updated>2021-11-08T20:29:03Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:E2170-contributor.PNG&amp;diff=141257</id>
		<title>File:E2170-contributor.PNG</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:E2170-contributor.PNG&amp;diff=141257"/>
		<updated>2021-11-08T20:27:16Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141255</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141255"/>
		<updated>2021-11-08T20:11:16Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* metareview_response_map_spec.rb */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
* review_response_map.rb  &amp;lt;--------- 92.5% coverage&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map.rb &amp;lt;------ 23.08% coverage&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
* response_map.rb &amp;lt;----------------- 74.47% coverage&lt;br /&gt;
&lt;br /&gt;
This project aims to get all the response maps to at least a 90% level of coverage for every Response Map file by writing unit tests for each uncovered method listed in the next section.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
* Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
* Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
* Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
* Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
== Test Files Involved ==&lt;br /&gt;
There are 4 test files involved in this project:&lt;br /&gt;
* review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* response_map_spec.rb&lt;br /&gt;
of these files, only review_response_map_spec.rb currently exists; the rest will be added.&lt;br /&gt;
&lt;br /&gt;
== Methods Tested Per File ==&lt;br /&gt;
&lt;br /&gt;
=== review_response_map_spec.rb ===&lt;br /&gt;
Currently this file is 92.5% covered and there are no plans to cover it further.&lt;br /&gt;
&lt;br /&gt;
=== metareview_response_map_spec.rb ===&lt;br /&gt;
The functions for metareview_response_map.rb that will be tested are:&lt;br /&gt;
====get_all_versions====&lt;br /&gt;
This returns a sorted array of all the different versions of what is being reviewed in this response map. This means for a test, we will need to create a reviewer, a reviewee, several types of reviews of different versions to be sorted correctly.&lt;br /&gt;
&lt;br /&gt;
====contributor====&lt;br /&gt;
Returns the team associated with the ReviewResponseMap that is to be metareviewed. We will need to create a ReviewResponseMap that has a team associated with it. Then we must create MetareviewResponseMap that points to a created ReviewResponseMap via the reviewed_object_id attribute. We will test if it indeed returns the team associated with ReviewResponseMap.&lt;br /&gt;
&lt;br /&gt;
====questionnaire====&lt;br /&gt;
Returns all questionnaires associated to the assignment of this MetareviewResponseMap that is of type 'MetareviewQuestionnaire'. We will need to create a valid MetareviewResponseMap including at least one MetareviewQuestionnaire that can be returned.&lt;br /&gt;
&lt;br /&gt;
====get_title====&lt;br /&gt;
Returns string &amp;quot;Metareview&amp;quot;. We will test if this string is the same as typed out.&lt;br /&gt;
====exports====&lt;br /&gt;
This function takes 3 parameters: csv (the csv file that will contain the exported metareview information), parent_id (the assignment ID containing the requested metareviews), and _options. The function sends all the information about the metareviews to a csv file. We will test that the information is properly exported to the csv file.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-export.jpg]]&lt;br /&gt;
&lt;br /&gt;
====export_fields====&lt;br /&gt;
Takes a parameter called &amp;quot;_options&amp;quot; that returns the three field columns associated with metareviews to be exported for use by other controllers. We will test to see that these three columns are properly returned.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-export_fields.jpg]]&lt;br /&gt;
&lt;br /&gt;
====import====&lt;br /&gt;
This function takes 3 parameters: row_hash (represents the hash of the metareview data we want to import), session, and id (representing the id of the assignment we want to import metareview data for). The function imports the data from the hash map, and if the information is input correctly, the data is extracted from the hash and creates a metareview for the requested assignment, otherwise it flashes an error saying the data was input incorrectly. We will test to make sure the imported data is properly converted into a metareview.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-import.jpg]]&lt;br /&gt;
&lt;br /&gt;
====email====&lt;br /&gt;
This function takes 3 parameters: defn, _participant (the user who will be receiving the email), and assignment (the assignment associated with the metareview). The function sends an email to the participant when they have a new metareview to complete. We will test to make sure the email is sent to the correct participant.&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:E2170-email.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== teammate_review_response_map_spec.rb ===&lt;br /&gt;
The functions for teammate_review_response_map.rb that will be tested are:&lt;br /&gt;
==== questionnaire ====&lt;br /&gt;
This function searches for a TeammateReviewQuestionnaire object and returns it.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate review response map-questionnaire.PNG]]&lt;br /&gt;
&lt;br /&gt;
==== get_title ====&lt;br /&gt;
This function returns the string &amp;quot;Teammate Review&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-get_title.png]]&lt;br /&gt;
&lt;br /&gt;
==== teammate_response_report ====&lt;br /&gt;
This function returns the teammate response report given the reviewer ID.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-teammate_response_report.PNG]]&lt;br /&gt;
&lt;br /&gt;
==== email ====&lt;br /&gt;
This function sends a notification email to a student who has been reviewed by their teammate.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-email.png]]&lt;br /&gt;
&lt;br /&gt;
=== response_map_spec.rb ===&lt;br /&gt;
The functions for response_map.rb that will be tested are:&lt;br /&gt;
* self.assessments_for(team)&lt;br /&gt;
* comparator&lt;br /&gt;
* self.reviewer_assessments_for(team, reviewer)&lt;br /&gt;
* metareviewed_by?&lt;br /&gt;
==== assign_metareviewer ====&lt;br /&gt;
This function is in charge of assigning a metareviewer to this review (i.e. a reviewer to review the review).&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-response_map-assign_metareviewer.png]]&lt;br /&gt;
&lt;br /&gt;
==== find_team_member ====&lt;br /&gt;
This function returns the team that the reviewer is part of.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-response_map-find_team_member.png]]&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141239</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141239"/>
		<updated>2021-11-08T19:13:48Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description of modifications/additions */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
* review_response_map.rb  &amp;lt;--------- 92.5% coverage&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map.rb &amp;lt;------ 23.08% coverage&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
* response_map.rb &amp;lt;----------------- 74.47% coverage&lt;br /&gt;
&lt;br /&gt;
This project aims to get all the response maps to at least a 90% level of coverage for every Response Map file by writing unit tests for each uncovered method listed in the next section.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
* Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
* Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
* Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
* Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
== Test Files Involved ==&lt;br /&gt;
There are 4 test files involved in this project:&lt;br /&gt;
* review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* response_map_spec.rb&lt;br /&gt;
of these files, only review_response_map_spec.rb currently exists; the rest will be added.&lt;br /&gt;
&lt;br /&gt;
== Methods Tested Per File ==&lt;br /&gt;
&lt;br /&gt;
=== review_response_map_spec.rb ===&lt;br /&gt;
Currently this file is 92.5% covered and there are no plans to cover it further.&lt;br /&gt;
&lt;br /&gt;
=== metareview_response_map_spec.rb ===&lt;br /&gt;
The functions for metareview_response_map.rb that will be tested are:&lt;br /&gt;
* get_all_versions&lt;br /&gt;
* contributor&lt;br /&gt;
* questionnaire&lt;br /&gt;
* get_title&lt;br /&gt;
* export&lt;br /&gt;
* export_fields&lt;br /&gt;
* import&lt;br /&gt;
* email&lt;br /&gt;
&lt;br /&gt;
=== teammate_review_response_map_spec.rb ===&lt;br /&gt;
The functions for teammate_review_response_map.rb that will be tested are:&lt;br /&gt;
==== questionnaire ====&lt;br /&gt;
This function searches for a TeammateReviewQuestionnaire object and returns it.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate review response map-questionnaire.PNG]]&lt;br /&gt;
&lt;br /&gt;
==== get_title ====&lt;br /&gt;
This function returns the string &amp;quot;Teammate Review&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-get_title.png]]&lt;br /&gt;
&lt;br /&gt;
==== teammate_response_report ====&lt;br /&gt;
This function returns the teammate response report given the reviewer ID.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-teammate_response_report.PNG]]&lt;br /&gt;
&lt;br /&gt;
==== email ====&lt;br /&gt;
This function sends a notification email to a student who has been reviewed by their teammate.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-email.png]]&lt;br /&gt;
&lt;br /&gt;
=== response_map_spec.rb ===&lt;br /&gt;
The functions for response_map.rb that will be tested are:&lt;br /&gt;
* self.assessments_for(team)&lt;br /&gt;
* comparator&lt;br /&gt;
* self.reviewer_assessments_for(team, reviewer)&lt;br /&gt;
* metareviewed_by?&lt;br /&gt;
==== assign_metareviewer ====&lt;br /&gt;
This function is in charge of assigning a metareviewer to this review (i.e. a reviewer to review the review).&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-response_map-assign_metareviewer.png]]&lt;br /&gt;
&lt;br /&gt;
==== find_team_member ====&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141236</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=141236"/>
		<updated>2021-11-08T19:10:53Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
* review_response_map.rb  &amp;lt;--------- 92.5% coverage&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map.rb &amp;lt;------ 23.08% coverage&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
* response_map.rb &amp;lt;----------------- 74.47% coverage&lt;br /&gt;
&lt;br /&gt;
This project aims to get all the response maps to at least a 90% level of coverage for every Response Map file by writing unit tests for each uncovered method listed in the next section.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
* Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
* Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
* Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
* Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
== Test Files Involved ==&lt;br /&gt;
There are 4 test files involved in this project:&lt;br /&gt;
* review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* response_map_spec.rb&lt;br /&gt;
of these files, only review_response_map_spec.rb currently exists; the rest will be added.&lt;br /&gt;
&lt;br /&gt;
== Description of modifications/additions ==&lt;br /&gt;
&lt;br /&gt;
=== review_response_map_spec.rb ===&lt;br /&gt;
Currently this file is 92.5% covered and there are no plans to cover it further.&lt;br /&gt;
&lt;br /&gt;
=== metareview_response_map_spec.rb ===&lt;br /&gt;
The functions for metareview_response_map.rb that will be tested are:&lt;br /&gt;
* get_all_versions&lt;br /&gt;
* contributor&lt;br /&gt;
* questionnaire&lt;br /&gt;
* get_title&lt;br /&gt;
* export&lt;br /&gt;
* export_fields&lt;br /&gt;
* import&lt;br /&gt;
* email&lt;br /&gt;
&lt;br /&gt;
=== teammate_review_response_map_spec.rb ===&lt;br /&gt;
The functions for teammate_review_response_map.rb that will be tested are:&lt;br /&gt;
==== questionnaire ====&lt;br /&gt;
This function searches for a TeammateReviewQuestionnaire object and returns it.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate review response map-questionnaire.PNG]]&lt;br /&gt;
&lt;br /&gt;
==== get_title ====&lt;br /&gt;
This function returns the string &amp;quot;Teammate Review&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-get_title.png]]&lt;br /&gt;
&lt;br /&gt;
==== teammate_response_report ====&lt;br /&gt;
This function returns the teammate response report given the reviewer ID.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-teammate_response_report.PNG]]&lt;br /&gt;
&lt;br /&gt;
==== email ====&lt;br /&gt;
This function sends a notification email to a student who has been reviewed by their teammate.&lt;br /&gt;
&lt;br /&gt;
[[File:E2170-teammate_review_response_map-email.png]]&lt;br /&gt;
&lt;br /&gt;
=== response_map_spec.rb ===&lt;br /&gt;
The functions for response_map.rb that will be tested are:&lt;br /&gt;
* self.assessments_for(team)&lt;br /&gt;
* comparator&lt;br /&gt;
* self.reviewer_assessments_for(team, reviewer)&lt;br /&gt;
* metareviewed_by?&lt;br /&gt;
==== assign_metareviewer ====&lt;br /&gt;
==== find_team_member ====&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140456</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140456"/>
		<updated>2021-11-02T21:07:11Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
review_response_map.rb  &amp;lt;--------- 92.5% coverage&lt;br /&gt;
&lt;br /&gt;
metareview_response_map.rb &amp;lt;------ 23.08% coverage&lt;br /&gt;
&lt;br /&gt;
teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
response_map.rb &amp;lt;----------------- 74.47% coverage&lt;br /&gt;
&lt;br /&gt;
This project aims to get all the response maps to at least a 90% level of coverage for every Response Map file.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
* Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
* Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
* Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
* Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
== Test Files Involved ==&lt;br /&gt;
There are 4 test files involved in this project:&lt;br /&gt;
* review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* response_map_spec.rb&lt;br /&gt;
of these files, only review_response_map_spec.rb currently exists in this project.&lt;br /&gt;
&lt;br /&gt;
== Description of modifications/additions ==&lt;br /&gt;
&lt;br /&gt;
=== review_response_map_spec.rb ===&lt;br /&gt;
Currently this file is 92.5% covered and there are no plans to cover it further.&lt;br /&gt;
&lt;br /&gt;
=== metareview_response_map_spec.rb ===&lt;br /&gt;
&lt;br /&gt;
=== teammate_review_response_map_spec.rb ===&lt;br /&gt;
&lt;br /&gt;
=== response_map_spec.rb ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140455</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140455"/>
		<updated>2021-11-02T21:06:59Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
review_response_map.rb  &amp;lt;--------- 92.5% coverage&lt;br /&gt;
&lt;br /&gt;
metareview_response_map.rb &amp;lt;------ 23.08% coverage&lt;br /&gt;
&lt;br /&gt;
teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
response_map.rb &amp;lt;----------------- 74.47%&lt;br /&gt;
&lt;br /&gt;
This project aims to get all the response maps to at least a 90% level of coverage for every Response Map file.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
&lt;br /&gt;
* Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
* Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
* Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
* Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
== Test Files Involved ==&lt;br /&gt;
There are 4 test files involved in this project:&lt;br /&gt;
* review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
* response_map_spec.rb&lt;br /&gt;
of these files, only review_response_map_spec.rb currently exists in this project.&lt;br /&gt;
&lt;br /&gt;
== Description of modifications/additions ==&lt;br /&gt;
&lt;br /&gt;
=== review_response_map_spec.rb ===&lt;br /&gt;
Currently this file is 92.5% covered and there are no plans to cover it further.&lt;br /&gt;
&lt;br /&gt;
=== metareview_response_map_spec.rb ===&lt;br /&gt;
&lt;br /&gt;
=== teammate_review_response_map_spec.rb ===&lt;br /&gt;
&lt;br /&gt;
=== response_map_spec.rb ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Running Tests ==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140431</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140431"/>
		<updated>2021-11-02T17:10:04Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
review_response_map.rb  &amp;lt;--------- %11.36 coverage&lt;br /&gt;
&lt;br /&gt;
metareview_response_map.rb &amp;lt;------ no coverage&lt;br /&gt;
&lt;br /&gt;
teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
response_map.rb &amp;lt;----------------- no coverage&lt;br /&gt;
&lt;br /&gt;
This project aims to get all the response maps to at least a 70% level of coverage for every Response Map file.&lt;br /&gt;
&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
=== Test Files Involved ===&lt;br /&gt;
&lt;br /&gt;
review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021&amp;diff=140335</id>
		<title>CSC/ECE 517 Fall 2021</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021&amp;diff=140335"/>
		<updated>2021-11-01T18:58:45Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Final Projects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== OSS Projects ==&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2117. Refactor questionaires_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2128. Refactor student_quizzes_controller.rb &amp;amp; late_policies_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2129. Refactor auth_controller.rb &amp;amp; password_retrieval_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2132. Add tests cases for review mapping helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2134. Write unit tests for admin_controller.rb and institution_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2138. Auto-generate submission directory names based on assignment]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2142. Improve e-mail notifications]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2133. Write tests for popup_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2120. Refactor reputation_web_service_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2139. Remove multiple topics at a time]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2131. Improve assessment360_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2121. Refactor suggestion_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2122. Refactor impersonate_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2123. Refactor sign_up_sheet_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2126. Refactor account_request_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2124. Refactor review_mapping_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2125. Refactor review_mapping_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2127. Refactor teams_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2130. Refactor submitted_content_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2140. Create new late policy successfully and fix Bank link]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2141. OSS project Finklestein: Instructors &amp;amp; Institutions]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2144. Refactor delayed mailer and scheduled task]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2147. Role-based reviewing]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2145. OSS Project Beige]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2146. Introduce a Student View for instructors]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - Refactor Evaluation of SQL Queries]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2135. Email notification to reviewers and instructors]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2168. Testing - Reputations]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2166. Testing - Scoring &amp;amp; Grades]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2149. Finish Github metrics integration - Reputations]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2161. Merge code for role-based reviewing with code for topic-specific rubrics]]&lt;br /&gt;
&lt;br /&gt;
== Final Projects ==&lt;br /&gt;
* [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps#Description_about_project CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps]&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021&amp;diff=140334</id>
		<title>CSC/ECE 517 Fall 2021</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021&amp;diff=140334"/>
		<updated>2021-11-01T18:58:03Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Final Projects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== OSS Projects ==&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2117. Refactor questionaires_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2128. Refactor student_quizzes_controller.rb &amp;amp; late_policies_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2129. Refactor auth_controller.rb &amp;amp; password_retrieval_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2132. Add tests cases for review mapping helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2134. Write unit tests for admin_controller.rb and institution_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2138. Auto-generate submission directory names based on assignment]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2142. Improve e-mail notifications]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2133. Write tests for popup_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2120. Refactor reputation_web_service_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2139. Remove multiple topics at a time]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2131. Improve assessment360_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2121. Refactor suggestion_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2122. Refactor impersonate_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2123. Refactor sign_up_sheet_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2126. Refactor account_request_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2124. Refactor review_mapping_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2125. Refactor review_mapping_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2127. Refactor teams_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2130. Refactor submitted_content_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2140. Create new late policy successfully and fix Bank link]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2141. OSS project Finklestein: Instructors &amp;amp; Institutions]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2144. Refactor delayed mailer and scheduled task]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2147. Role-based reviewing]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2145. OSS Project Beige]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2146. Introduce a Student View for instructors]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - Refactor Evaluation of SQL Queries]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2135. Email notification to reviewers and instructors]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2168. Testing - Reputations]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2166. Testing - Scoring &amp;amp; Grades]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2149. Finish Github metrics integration - Reputations]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2161. Merge code for role-based reviewing with code for topic-specific rubrics]]&lt;br /&gt;
&lt;br /&gt;
== Final Projects ==&lt;br /&gt;
* [https://expertiza.csc.ncsu.edu/index.php/CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps#Description_about_project ECE 517 Fall 2021 - E2170. Testing - Response Maps]&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140333</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140333"/>
		<updated>2021-11-01T18:57:11Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
review_response_map.rb  &amp;lt;--------- %11.36 coverage&lt;br /&gt;
&lt;br /&gt;
metareview_response_map.rb &amp;lt;------ no coverage&lt;br /&gt;
&lt;br /&gt;
teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
response_map.rb &amp;lt;----------------- no coverage&lt;br /&gt;
&lt;br /&gt;
This project aims to get all the response maps to at least a 70% level of coverage for every Response Map file.&lt;br /&gt;
&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
=== Test Files Involved ===&lt;br /&gt;
&lt;br /&gt;
review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140332</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140332"/>
		<updated>2021-11-01T18:55:52Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
review_response_map.rb  &amp;lt;--------- %11.36 coverage&lt;br /&gt;
&lt;br /&gt;
metareview_response_map.rb &amp;lt;------ no coverage&lt;br /&gt;
&lt;br /&gt;
teammate_review_response_map.rb &amp;lt;- no coverage&lt;br /&gt;
&lt;br /&gt;
response_map.rb &amp;lt;----------------- no coverage&lt;br /&gt;
&lt;br /&gt;
review_re&lt;br /&gt;
&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
=== Test Files Involved ===&lt;br /&gt;
&lt;br /&gt;
review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140331</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140331"/>
		<updated>2021-11-01T18:54:40Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
The breakdown of the ResponseMap model can be found [https://expertiza.csc.ncsu.edu/index.php/Response_maps here]. There are several types of ResponseMaps that extend functionality of the original ResponseMap. None of which including the superclass are adequately tested. These files include:&lt;br /&gt;
&lt;br /&gt;
review_response_map.rb&lt;br /&gt;
&lt;br /&gt;
metareview_response_map.rb&lt;br /&gt;
&lt;br /&gt;
teammate_review_response_map.rb&lt;br /&gt;
&lt;br /&gt;
response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
=== Test Files Involved ===&lt;br /&gt;
&lt;br /&gt;
review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140330</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140330"/>
		<updated>2021-11-01T18:47:35Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
=== Test Files Involved ===&lt;br /&gt;
&lt;br /&gt;
review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/&amp;lt;test file name&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140329</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140329"/>
		<updated>2021-11-01T18:47:04Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Test Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
=== Test Files Involved ===&lt;br /&gt;
&lt;br /&gt;
review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
metareview_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
teammate_review_response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Super Admin Login===&lt;br /&gt;
&lt;br /&gt;
*Despite the username, this user is not an instructor. The role was changed in the database to give instructor6 super admin privileges.&lt;br /&gt;
Username: instructor6&lt;br /&gt;
Password: password&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140328</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140328"/>
		<updated>2021-11-01T18:46:55Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Files Involved */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
=== Test Files Involved ===&lt;br /&gt;
&lt;br /&gt;
review_response_map_spec.rb&lt;br /&gt;
metareview_response_map_spec.rb&lt;br /&gt;
teammate_review_response_map_spec.rb&lt;br /&gt;
response_map_spec.rb&lt;br /&gt;
&lt;br /&gt;
=== Super Admin Login===&lt;br /&gt;
&lt;br /&gt;
*Despite the username, this user is not an instructor. The role was changed in the database to give instructor6 super admin privileges.&lt;br /&gt;
Username: instructor6&lt;br /&gt;
Password: password&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140327</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140327"/>
		<updated>2021-11-01T18:45:37Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2170 which aims to adequately test several files regarding the ResponseMap model. Here is a description of what response maps do:&lt;br /&gt;
*In Expertiza, response maps establish a relationship between a reviewer, a reviewee, and an object to be reviewed.  The reviewer is an assignment_participant, the reviewee is an assignment_team, and the reviewed object is either an assignment or another response_map. Each (reviewer, reviewee) pair will have a separate response map. Every time a new review is performed (e.g, every round), a new Response object is created whose map_id is that response map.&lt;br /&gt;
&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Quinn Dibble (qdibble)&lt;br /&gt;
&lt;br /&gt;
Alex Carruth (agcarrut)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Super Admin Login===&lt;br /&gt;
&lt;br /&gt;
*Despite the username, this user is not an instructor. The role was changed in the database to give instructor6 super admin privileges.&lt;br /&gt;
Username: instructor6&lt;br /&gt;
Password: password&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140326</id>
		<title>CSC/ECE 517 Fall 2021 - E2170. Testing - Response Maps</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2170._Testing_-_Response_Maps&amp;diff=140326"/>
		<updated>2021-11-01T18:41:06Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: Created page with &amp;quot;== About Expertiza==  [http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission acro...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha when requesting the page to make a new user. &lt;br /&gt;
&lt;br /&gt;
''DISCLAIMER: &lt;br /&gt;
*Some of the issues handed to us were already fixed when we looked at them from a previous project, so this page is only documenting the ones that we worked on. It can be assumed that the other undocumented issues are already done.&lt;br /&gt;
*'''THIS PROJECT IS NOT ABOUT MAKING A NEW USER.''' The purpose of the captcha is to verify if the user CAN BE REDIRECTED to the request new user page. The actual act of requesting a new user will error out due to some complications with the internal system's mailing system which is out of the scope of our assignments for this project. If you attempt to create a user, you are testing functionality that we were not assigned to fix.&lt;br /&gt;
''&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Super Admin Login===&lt;br /&gt;
&lt;br /&gt;
*Despite the username, this user is not an instructor. The role was changed in the database to give instructor6 super admin privileges.&lt;br /&gt;
Username: instructor6&lt;br /&gt;
Password: password&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation instructions of the gem and integrating the recaptcha API key can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
'''Front end change /app/views/_login.html.erb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;%= form_tag({:controller =&amp;gt; 'account_request', :role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :method =&amp;gt; &amp;quot;get&amp;quot;) do %&amp;gt;&lt;br /&gt;
        &amp;lt;div&amp;gt;&lt;br /&gt;
          &amp;lt;%= recaptcha_tags %&amp;gt;  &amp;lt;------ Displays reCaptcha widget&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
        &amp;lt;%= submit_tag &amp;quot;Request account&amp;quot;, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'width:100%; margin-left:auto; margin-right:auto;' %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''action_allowed? changes'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      verify_recaptcha &amp;lt;---- function provided by recaptcha gem; validates frontend recaptcha input&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Login info:====&lt;br /&gt;
Username: instructor6 Password: password&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There has been a database change where the role of instructor6 was bumped up to Super Admin.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file.&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;br /&gt;
&lt;br /&gt;
Our pull request to the beta branch can be found [https://github.com/expertiza/expertiza/pull/2117 here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021&amp;diff=140325</id>
		<title>CSC/ECE 517 Fall 2021</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021&amp;diff=140325"/>
		<updated>2021-11-01T17:59:05Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* OSS Projects */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== OSS Projects ==&lt;br /&gt;
&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2117. Refactor questionaires_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2128. Refactor student_quizzes_controller.rb &amp;amp; late_policies_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2129. Refactor auth_controller.rb &amp;amp; password_retrieval_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2132. Add tests cases for review mapping helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2134. Write unit tests for admin_controller.rb and institution_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2138. Auto-generate submission directory names based on assignment]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2142. Improve e-mail notifications]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2133. Write tests for popup_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2120. Refactor reputation_web_service_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2139. Remove multiple topics at a time]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2131. Improve assessment360_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2121. Refactor suggestion_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2122. Refactor impersonate_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2123. Refactor sign_up_sheet_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2126. Refactor account_request_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2124. Refactor review_mapping_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2125. Refactor review_mapping_helper.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2127. Refactor teams_controller]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2130. Refactor submitted_content_controller.rb]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2140. Create new late policy successfully and fix Bank link]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2141. OSS project Finklestein: Instructors &amp;amp; Institutions]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2144. Refactor delayed mailer and scheduled task]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2147. Role-based reviewing]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2145. OSS Project Beige]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2146. Introduce a Student View for instructors]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - Refactor Evaluation of SQL Queries]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2135. Email notification to reviewers and instructors]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2168. Testing - Reputations]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2166. Testing - Scoring &amp;amp; Grades]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2149. Finish Github metrics integration - Reputations]]&lt;br /&gt;
* [[CSC/ECE 517 Fall 2021 - E2161. Merge code for role-based reviewing with code for topic-specific rubrics]]&lt;br /&gt;
&lt;br /&gt;
== Final Projects ==&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140256</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140256"/>
		<updated>2021-10-30T19:48:43Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Relevant Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha when requesting the page to make a new user. &lt;br /&gt;
&lt;br /&gt;
''DISCLAIMER: &lt;br /&gt;
*Some of the issues handed to us were already fixed when we looked at them from a previous project, so this page is only documenting the ones that we worked on. It can be assumed that the other undocumented issues are already done.&lt;br /&gt;
*'''THIS PROJECT IS NOT ABOUT MAKING A NEW USER.''' The purpose of the captcha is to verify if the user CAN BE REDIRECTED to the request new user page. The actual act of requesting a new user will error out due to some complications with the internal system's mailing system which is out of the scope of our assignments for this project. If you attempt to create a user, you are testing functionality that we were not assigned to fix.&lt;br /&gt;
''&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Super Admin Login===&lt;br /&gt;
&lt;br /&gt;
*Despite the username, this user is not an instructor. The role was changed in the database to give instructor6 super admin privileges.&lt;br /&gt;
Username: instructor6&lt;br /&gt;
Password: password&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation instructions of the gem and integrating the recaptcha API key can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
'''Front end change /app/views/_login.html.erb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;%= form_tag({:controller =&amp;gt; 'account_request', :role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :method =&amp;gt; &amp;quot;get&amp;quot;) do %&amp;gt;&lt;br /&gt;
        &amp;lt;div&amp;gt;&lt;br /&gt;
          &amp;lt;%= recaptcha_tags %&amp;gt;  &amp;lt;------ Displays reCaptcha widget&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
        &amp;lt;%= submit_tag &amp;quot;Request account&amp;quot;, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'width:100%; margin-left:auto; margin-right:auto;' %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''action_allowed? changes'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      verify_recaptcha &amp;lt;---- function provided by recaptcha gem; validates frontend recaptcha input&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Login info:====&lt;br /&gt;
Username: instructor6 Password: password&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There has been a database change where the role of instructor6 was bumped up to Super Admin.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file.&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;br /&gt;
&lt;br /&gt;
Our pull request to the beta branch can be found [https://github.com/expertiza/expertiza/pull/2117 here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140243</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140243"/>
		<updated>2021-10-28T15:16:54Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha when requesting the page to make a new user. &lt;br /&gt;
&lt;br /&gt;
''DISCLAIMER: &lt;br /&gt;
*Some of the issues handed to us were already fixed when we looked at them from a previous project, so this page is only documenting the ones that we worked on. It can be assumed that the other undocumented issues are already done.&lt;br /&gt;
*'''THIS PROJECT IS NOT ABOUT MAKING A NEW USER.''' The purpose of the captcha is to verify if the user CAN BE REDIRECTED to the request new user page. The actual act of requesting a new user will error out due to some complications with the internal system's mailing system which is out of the scope of our assignments for this project. If you attempt to create a user, you are testing functionality that we were not assigned to fix.&lt;br /&gt;
''&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Super Admin Login===&lt;br /&gt;
&lt;br /&gt;
*Despite the username, this user is not an instructor. The role was changed in the database to give instructor6 super admin privileges.&lt;br /&gt;
Username: instructor6&lt;br /&gt;
Password: password&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation instructions of the gem and integrating the recaptcha API key can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
'''Front end change /app/views/_login.html.erb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;%= form_tag({:controller =&amp;gt; 'account_request', :role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :method =&amp;gt; &amp;quot;get&amp;quot;) do %&amp;gt;&lt;br /&gt;
        &amp;lt;div&amp;gt;&lt;br /&gt;
          &amp;lt;%= recaptcha_tags %&amp;gt;  &amp;lt;------ Displays reCaptcha widget&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
        &amp;lt;%= submit_tag &amp;quot;Request account&amp;quot;, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'width:100%; margin-left:auto; margin-right:auto;' %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''action_allowed? changes'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      verify_recaptcha &amp;lt;---- function provided by recaptcha gem; validates frontend recaptcha input&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Login info:====&lt;br /&gt;
Username: instructor6 Password: password&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There has been a database change where the role of instructor6 was bumped up to Super Admin.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file.&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140034</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140034"/>
		<updated>2021-10-25T20:59:07Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Login info: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha to the approval/rejection process. &lt;br /&gt;
&lt;br /&gt;
''DISCLAIMER: Some of the issues handed to us were already fixed when we looked at them from a previous project, so this page is only documenting the ones that we worked on. It can be assumed that the other undocumented issues are already done.&lt;br /&gt;
''&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Super Admin Login===&lt;br /&gt;
&lt;br /&gt;
*Despite the username, this user is not an instructor. The role was changed in the database to give instructor6 super admin privileges.&lt;br /&gt;
Username: instructor6&lt;br /&gt;
Password: password&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation instructions of the gem and integrating the recaptcha API key can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
'''Front end change /app/views/_login.html.erb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;%= form_tag({:controller =&amp;gt; 'account_request', :role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :method =&amp;gt; &amp;quot;get&amp;quot;) do %&amp;gt;&lt;br /&gt;
        &amp;lt;div&amp;gt;&lt;br /&gt;
          &amp;lt;%= recaptcha_tags %&amp;gt;  &amp;lt;------ Displays reCaptcha widget&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
        &amp;lt;%= submit_tag &amp;quot;Request account&amp;quot;, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'width:100%; margin-left:auto; margin-right:auto;' %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''action_allowed? changes'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      verify_recaptcha &amp;lt;---- function provided by recaptcha gem; validates frontend recaptcha input&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Login info:====&lt;br /&gt;
Username: instructor6 Password: password&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
There has been a database change where the role of instructor6 was bumped up to Super Admin.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file.&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140033</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140033"/>
		<updated>2021-10-25T20:58:48Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Login info: */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha to the approval/rejection process. &lt;br /&gt;
&lt;br /&gt;
''DISCLAIMER: Some of the issues handed to us were already fixed when we looked at them from a previous project, so this page is only documenting the ones that we worked on. It can be assumed that the other undocumented issues are already done.&lt;br /&gt;
''&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Super Admin Login===&lt;br /&gt;
&lt;br /&gt;
*Despite the username, this user is not an instructor. The role was changed in the database to give instructor6 super admin privileges.&lt;br /&gt;
Username: instructor6&lt;br /&gt;
Password: password&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation instructions of the gem and integrating the recaptcha API key can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
'''Front end change /app/views/_login.html.erb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;%= form_tag({:controller =&amp;gt; 'account_request', :role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :method =&amp;gt; &amp;quot;get&amp;quot;) do %&amp;gt;&lt;br /&gt;
        &amp;lt;div&amp;gt;&lt;br /&gt;
          &amp;lt;%= recaptcha_tags %&amp;gt;  &amp;lt;------ Displays reCaptcha widget&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
        &amp;lt;%= submit_tag &amp;quot;Request account&amp;quot;, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'width:100%; margin-left:auto; margin-right:auto;' %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''action_allowed? changes'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      verify_recaptcha &amp;lt;---- function provided by recaptcha gem; validates frontend recaptcha input&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
====Login info:====&lt;br /&gt;
Username: instructor6 Password: password&lt;br /&gt;
There has been a database change where the role of instructor6 was bumped up to Super Admin.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file.&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140032</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140032"/>
		<updated>2021-10-25T20:58:31Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* create_approved_user */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha to the approval/rejection process. &lt;br /&gt;
&lt;br /&gt;
''DISCLAIMER: Some of the issues handed to us were already fixed when we looked at them from a previous project, so this page is only documenting the ones that we worked on. It can be assumed that the other undocumented issues are already done.&lt;br /&gt;
''&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Super Admin Login===&lt;br /&gt;
&lt;br /&gt;
*Despite the username, this user is not an instructor. The role was changed in the database to give instructor6 super admin privileges.&lt;br /&gt;
Username: instructor6&lt;br /&gt;
Password: password&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation instructions of the gem and integrating the recaptcha API key can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
'''Front end change /app/views/_login.html.erb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;%= form_tag({:controller =&amp;gt; 'account_request', :role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :method =&amp;gt; &amp;quot;get&amp;quot;) do %&amp;gt;&lt;br /&gt;
        &amp;lt;div&amp;gt;&lt;br /&gt;
          &amp;lt;%= recaptcha_tags %&amp;gt;  &amp;lt;------ Displays reCaptcha widget&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
        &amp;lt;%= submit_tag &amp;quot;Request account&amp;quot;, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'width:100%; margin-left:auto; margin-right:auto;' %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''action_allowed? changes'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      verify_recaptcha &amp;lt;---- function provided by recaptcha gem; validates frontend recaptcha input&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==Login info:==&lt;br /&gt;
Username: instructor6 Password: password&lt;br /&gt;
There has been a database change where the role of instructor6 was bumped up to Super Admin.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file.&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140031</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140031"/>
		<updated>2021-10-25T20:58:01Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* create_approved_user */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha to the approval/rejection process. &lt;br /&gt;
&lt;br /&gt;
''DISCLAIMER: Some of the issues handed to us were already fixed when we looked at them from a previous project, so this page is only documenting the ones that we worked on. It can be assumed that the other undocumented issues are already done.&lt;br /&gt;
''&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Super Admin Login===&lt;br /&gt;
&lt;br /&gt;
*Despite the username, this user is not an instructor. The role was changed in the database to give instructor6 super admin privileges.&lt;br /&gt;
Username: instructor6&lt;br /&gt;
Password: password&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation instructions of the gem and integrating the recaptcha API key can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
'''Front end change /app/views/_login.html.erb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;%= form_tag({:controller =&amp;gt; 'account_request', :role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :method =&amp;gt; &amp;quot;get&amp;quot;) do %&amp;gt;&lt;br /&gt;
        &amp;lt;div&amp;gt;&lt;br /&gt;
          &amp;lt;%= recaptcha_tags %&amp;gt;  &amp;lt;------ Displays reCaptcha widget&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
        &amp;lt;%= submit_tag &amp;quot;Request account&amp;quot;, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'width:100%; margin-left:auto; margin-right:auto;' %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''action_allowed? changes'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      verify_recaptcha &amp;lt;---- function provided by recaptcha gem; validates frontend recaptcha input&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process.&lt;br /&gt;
Login info:&lt;br /&gt;
Username: instructor6 Password: password&lt;br /&gt;
There has been a database change where the role of instructor6 was bumped up to Super Admin.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file.&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140030</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140030"/>
		<updated>2021-10-25T20:56:26Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha to the approval/rejection process. &lt;br /&gt;
&lt;br /&gt;
''DISCLAIMER: Some of the issues handed to us were already fixed when we looked at them from a previous project, so this page is only documenting the ones that we worked on. It can be assumed that the other undocumented issues are already done.&lt;br /&gt;
''&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Super Admin Login===&lt;br /&gt;
&lt;br /&gt;
*Despite the username, this user is not an instructor. The role was changed in the database to give instructor6 super admin privileges.&lt;br /&gt;
Username: instructor6&lt;br /&gt;
Password: password&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation instructions of the gem and integrating the recaptcha API key can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
'''Front end change /app/views/_login.html.erb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;%= form_tag({:controller =&amp;gt; 'account_request', :role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :method =&amp;gt; &amp;quot;get&amp;quot;) do %&amp;gt;&lt;br /&gt;
        &amp;lt;div&amp;gt;&lt;br /&gt;
          &amp;lt;%= recaptcha_tags %&amp;gt;  &amp;lt;------ Displays reCaptcha widget&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
        &amp;lt;%= submit_tag &amp;quot;Request account&amp;quot;, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'width:100%; margin-left:auto; margin-right:auto;' %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''action_allowed? changes'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      verify_recaptcha &amp;lt;---- function provided by recaptcha gem; validates frontend recaptcha input&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file.&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140029</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=140029"/>
		<updated>2021-10-25T20:39:45Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha to the approval/rejection process. &lt;br /&gt;
&lt;br /&gt;
''DISCLAIMER: Some of the issues handed to us were already fixed when we looked at them from a previous project, so this page is only documenting the ones that we worked on. It can be assumed that the other undocumented issues are already done.&lt;br /&gt;
''&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation instructions of the gem and integrating the recaptcha API key can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
'''Front end change /app/views/_login.html.erb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
    &amp;lt;%= form_tag({:controller =&amp;gt; 'account_request', :role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :method =&amp;gt; &amp;quot;get&amp;quot;) do %&amp;gt;&lt;br /&gt;
        &amp;lt;div&amp;gt;&lt;br /&gt;
          &amp;lt;%= recaptcha_tags %&amp;gt;  &amp;lt;------ Displays reCaptcha widget&lt;br /&gt;
        &amp;lt;/div&amp;gt;&lt;br /&gt;
        &amp;lt;%= submit_tag &amp;quot;Request account&amp;quot;, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'width:100%; margin-left:auto; margin-right:auto;' %&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''action_allowed? changes'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      verify_recaptcha &amp;lt;---- function provided by recaptcha gem; validates frontend recaptcha input&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file.&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=139834</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=139834"/>
		<updated>2021-10-21T03:36:19Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha to the approval/rejection process. &lt;br /&gt;
&lt;br /&gt;
''DISCLAIMER: Some of the issues handed to us were already fixed when we looked at them from a previous project, so this page is only documenting the ones that we worked on. It can be assumed that the other undocumented issues are already done.&lt;br /&gt;
''&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation of the gem and getting the key instructions can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
'''Front end change /app/views/_login.html.erb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to &amp;quot;Request account&amp;quot;,{:controller =&amp;gt; 'account_request',:role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'color:white;width:100%;margin-left:auto;margin-right:auto;' %&amp;gt;&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;%= recaptcha_tags %&amp;gt;   &amp;lt;&amp;lt;--=-----displays recaptcha widget&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''action_allowed? changes'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def captcha_test&lt;br /&gt;
    valid = true&lt;br /&gt;
    @something&lt;br /&gt;
    if verify_recaptcha(model: @something) == true&lt;br /&gt;
      valid = true&lt;br /&gt;
    end&lt;br /&gt;
    return valid&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      captcha_test&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file.&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=139831</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=139831"/>
		<updated>2021-10-21T03:35:24Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha to the approval/rejection process. &lt;br /&gt;
&lt;br /&gt;
''DISCLAIMER: Some of the issues handed to us were already fixed when we looked at them, so this page is only documenting the ones that initially remained needing to be fixed.&lt;br /&gt;
''&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation of the gem and getting the key instructions can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
'''Front end change /app/views/_login.html.erb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to &amp;quot;Request account&amp;quot;,{:controller =&amp;gt; 'account_request',:role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'color:white;width:100%;margin-left:auto;margin-right:auto;' %&amp;gt;&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;%= recaptcha_tags %&amp;gt;   &amp;lt;&amp;lt;--=-----displays recaptcha widget&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''action_allowed? changes'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def captcha_test&lt;br /&gt;
    valid = true&lt;br /&gt;
    @something&lt;br /&gt;
    if verify_recaptcha(model: @something) == true&lt;br /&gt;
      valid = true&lt;br /&gt;
    end&lt;br /&gt;
    return valid&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      captcha_test&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file.&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=139830</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=139830"/>
		<updated>2021-10-21T03:35:07Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* Description about project */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha to the approval/rejection process. &lt;br /&gt;
&lt;br /&gt;
DISCLAIMER: Some of the issues handed to us were already fixed when we looked at them, so this page is only documenting the ones that initially remained needing to be fixed.&lt;br /&gt;
&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation of the gem and getting the key instructions can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
'''Front end change /app/views/_login.html.erb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to &amp;quot;Request account&amp;quot;,{:controller =&amp;gt; 'account_request',:role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'color:white;width:100%;margin-left:auto;margin-right:auto;' %&amp;gt;&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;%= recaptcha_tags %&amp;gt;   &amp;lt;&amp;lt;--=-----displays recaptcha widget&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''action_allowed? changes'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def captcha_test&lt;br /&gt;
    valid = true&lt;br /&gt;
    @something&lt;br /&gt;
    if verify_recaptcha(model: @something) == true&lt;br /&gt;
      valid = true&lt;br /&gt;
    end&lt;br /&gt;
    return valid&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      captcha_test&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file.&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=139816</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=139816"/>
		<updated>2021-10-21T03:24:42Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* action_allowed? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha to the approval/rejection process.&lt;br /&gt;
&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation of the gem and getting the key instructions can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
'''Front end change /app/views/_login.html.erb'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to &amp;quot;Request account&amp;quot;,{:controller =&amp;gt; 'account_request',:role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'color:white;width:100%;margin-left:auto;margin-right:auto;' %&amp;gt;&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;%= recaptcha_tags %&amp;gt;   &amp;lt;&amp;lt;--=-----displays recaptcha widget&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''action_allowed? changes'''&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def captcha_test&lt;br /&gt;
    valid = true&lt;br /&gt;
    @something&lt;br /&gt;
    if verify_recaptcha(model: @something) == true&lt;br /&gt;
      valid = true&lt;br /&gt;
    end&lt;br /&gt;
    return valid&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      captcha_test&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file. &lt;br /&gt;
&lt;br /&gt;
Our code changes can be viewed [https://github.com/expertiza/expertiza/pull/2094/files here].&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=139815</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=139815"/>
		<updated>2021-10-21T03:22:51Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* action_allowed? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha to the approval/rejection process.&lt;br /&gt;
&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation of the gem and getting the key instructions can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to &amp;quot;Request account&amp;quot;,{:controller =&amp;gt; 'account_request',:role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'color:white;width:100%;margin-left:auto;margin-right:auto;' %&amp;gt;&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;%= recaptcha_tags %&amp;gt;   &amp;lt;&amp;lt;--=-----displays recaptcha widget&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def captcha_test&lt;br /&gt;
    valid = true&lt;br /&gt;
    @something&lt;br /&gt;
    if verify_recaptcha(model: @something) == true&lt;br /&gt;
      valid = true&lt;br /&gt;
    end&lt;br /&gt;
    return valid&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      captcha_test&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file. &lt;br /&gt;
&lt;br /&gt;
Our code changes can be viewed [https://github.com/expertiza/expertiza/pull/2094/files here].&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=139812</id>
		<title>CSC/ECE 517 Fall 2021 - E2126. Refactor account request controller.rb</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2021_-_E2126._Refactor_account_request_controller.rb&amp;diff=139812"/>
		<updated>2021-10-21T03:21:52Z</updated>

		<summary type="html">&lt;p&gt;Aamajumd: /* action_allowed? */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== About Expertiza==&lt;br /&gt;
&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework that supports submission across different document types, including theURLs and wiki pages. It allows the instructor not only to create and customize new or existing assignments but also 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. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Description about project ==&lt;br /&gt;
This page is a description of Expertiza OSS project E2126 which refactoring the account_request_controller.rb file. This file allows Super Administrators to manage the approval process for new users. Our job was to refactor some of the longer methods in this file, make error messages more intuitive, and add a security captcha to the approval/rejection process.&lt;br /&gt;
&lt;br /&gt;
=== Team ===&lt;br /&gt;
&lt;br /&gt;
Connor Smith (cpsmith6)&lt;br /&gt;
&lt;br /&gt;
Abir Majumder (aamajumd)&lt;br /&gt;
&lt;br /&gt;
Joshua Myers (jamyers3)&lt;br /&gt;
&lt;br /&gt;
=== Files Involved ===&lt;br /&gt;
&lt;br /&gt;
account_request_controller.rb&lt;br /&gt;
&lt;br /&gt;
=== Running Tests ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  rspec ./spec/controllers/account_request_controller.rb&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Relevant Methods ==&lt;br /&gt;
&lt;br /&gt;
* action_allowed?&lt;br /&gt;
* create_approved_user&lt;br /&gt;
* create_requested_user_record&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? ===&lt;br /&gt;
&lt;br /&gt;
This method validates if the user is allowed to be redirected to the appropriate page. The task for this project is to add a captcha system before the user requests new. This happens when the user hits the &amp;quot;Request account&amp;quot; button on the login page. This project's repo already has the &amp;quot;recaptcha&amp;quot; gem installed. Future developers need to keep in mind that functionality of the captcha depends on the developer updating the site key and secret key of the Google ReCaptcha API. Installation of the gem and getting the key instructions can be found [https://github.com/ambethia/recaptcha here].&lt;br /&gt;
&lt;br /&gt;
There was one change to the frontend to display the captcha at _login.html.erb.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
...&lt;br /&gt;
  &amp;lt;% end %&amp;gt;&lt;br /&gt;
  &amp;lt;p&amp;gt;&lt;br /&gt;
  &amp;lt;%= link_to &amp;quot;Request account&amp;quot;,{:controller =&amp;gt; 'account_request',:role =&amp;gt; &amp;quot;Instructor&amp;quot;, :action =&amp;gt; 'new'}, :class =&amp;gt; 'btn btn-danger', :style =&amp;gt; 'color:white;width:100%;margin-left:auto;margin-right:auto;' %&amp;gt;&lt;br /&gt;
  &amp;lt;div&amp;gt;&lt;br /&gt;
    &amp;lt;%= recaptcha_tags %&amp;gt;   &amp;lt;&amp;lt;--=-----displays recaptcha widget&lt;br /&gt;
  &amp;lt;/div&amp;gt;&lt;br /&gt;
  &amp;lt;/p&amp;gt;&lt;br /&gt;
  &amp;lt;br/&amp;gt;&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;% end %&amp;gt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
    def captcha_test&lt;br /&gt;
    valid = true&lt;br /&gt;
    @something&lt;br /&gt;
    if verify_recaptcha(model: @something) == true&lt;br /&gt;
      valid = true&lt;br /&gt;
    end&lt;br /&gt;
    return valid&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'list_pending_requested'&lt;br /&gt;
      current_user_has_admin_privileges?&lt;br /&gt;
    when 'new'&lt;br /&gt;
      captcha_test&lt;br /&gt;
    when 'create_requested_user_record'&lt;br /&gt;
      true&lt;br /&gt;
    when 'keys'&lt;br /&gt;
      current_user_has_student_privileges?&lt;br /&gt;
    else&lt;br /&gt;
      current_user_has_ta_privileges?&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_approved_user ===&lt;br /&gt;
&lt;br /&gt;
This method allows a Super Admin to approve or reject new users, and gives them an error message if the incorrect steps are taken during that process&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        new_user = User.new&lt;br /&gt;
        new_user.name = requested_user.name&lt;br /&gt;
        new_user.role_id = requested_user.role_id&lt;br /&gt;
        new_user.institution_id = requested_user.institution_id&lt;br /&gt;
        new_user.fullname = requested_user.fullname&lt;br /&gt;
        new_user.email = requested_user.email&lt;br /&gt;
        new_user.parent_id = session[:user].id&lt;br /&gt;
        new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
        if new_user.save&lt;br /&gt;
          password = new_user.reset_password&lt;br /&gt;
          # Mail is sent to the user with a new password&lt;br /&gt;
          prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
          prepared_mail.deliver_now&lt;br /&gt;
          flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
          undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
        else&lt;br /&gt;
          foreign&lt;br /&gt;
        end&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
This method was refactored so the creation of the new user is handled in a separate method called '''&amp;quot;user_new&amp;quot;'''&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_approved_user&lt;br /&gt;
    if params[:selection] == nil&lt;br /&gt;
      flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      redirect_to action: 'list_pending_requested'&lt;br /&gt;
      return &lt;br /&gt;
    end&lt;br /&gt;
    is_approved = (params[:commit] == &amp;quot;Accept&amp;quot;? &amp;quot;Approved&amp;quot; : &amp;quot;Rejected&amp;quot;)&lt;br /&gt;
    users = params[:selection]&lt;br /&gt;
    users.each do |user|&lt;br /&gt;
      requested_user = AccountRequest.find_by(id: user.first)&lt;br /&gt;
      requested_user.status = is_approved&lt;br /&gt;
      puts &amp;quot;Here&amp;quot;&lt;br /&gt;
      if requested_user.status.nil?&lt;br /&gt;
        flash[:error] = &amp;quot;Please Approve or Reject before submitting&amp;quot;&lt;br /&gt;
      elsif requested_user.update_attributes(params[:user])&lt;br /&gt;
        flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully updated.&amp;quot;&lt;br /&gt;
      end&lt;br /&gt;
      if requested_user.status == &amp;quot;Approved&amp;quot;&lt;br /&gt;
        user_new(requested_user)&lt;br /&gt;
      elsif requested_user.status == &amp;quot;Rejected&amp;quot;&lt;br /&gt;
        # If the user request has been rejected, a flash message is shown and redirected to review page&lt;br /&gt;
        if requested_user.update_columns(status: is_approved)&lt;br /&gt;
          flash[:success] = &amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been Rejected.&amp;quot;&lt;br /&gt;
          # redirect_to action: 'list_pending_requested'&lt;br /&gt;
          # return&lt;br /&gt;
        else&lt;br /&gt;
          flash[:error] = &amp;quot;Error processing request.&amp;quot;&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
    redirect_to action: 'list_pending_requested'&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def user_new(requested_user)&lt;br /&gt;
    puts requested_user.inspect&lt;br /&gt;
    new_user = User.new&lt;br /&gt;
    new_user.name = requested_user.name&lt;br /&gt;
    new_user.role_id = requested_user.role_id&lt;br /&gt;
    new_user.institution_id = requested_user.institution_id&lt;br /&gt;
    new_user.fullname = requested_user.fullname&lt;br /&gt;
    new_user.email = requested_user.email&lt;br /&gt;
    new_user.parent_id = session[:user].id&lt;br /&gt;
    new_user.timezonepref = User.find_by(id: new_user.parent_id).timezonepref&lt;br /&gt;
    if new_user.save&lt;br /&gt;
      password = new_user.reset_password&lt;br /&gt;
      # Mail is sent to the user with a new password&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_user(new_user, &amp;quot;Your Expertiza account and password have been created.&amp;quot;, &amp;quot;user_welcome&amp;quot;, password)&lt;br /&gt;
      prepared_mail.deliver_now&lt;br /&gt;
      flash[:success] = &amp;quot;A new password has been sent to new user's e-mail address.&amp;quot;&lt;br /&gt;
      undo_link(&amp;quot;The user \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully created. &amp;quot;)&lt;br /&gt;
    else&lt;br /&gt;
      foreign&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== create_requested_user_record ===&lt;br /&gt;
&lt;br /&gt;
create_requested_user creates a new account request for a user (if they are not a duplicate user) so that it may be approved by a higher level user.&lt;br /&gt;
&lt;br /&gt;
==== Original Method ====&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  def create_requested_user_record&lt;br /&gt;
  &lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model. &lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
&lt;br /&gt;
    #&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
&lt;br /&gt;
    user_existed = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    requested_user_saved = requested_user.save&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
&lt;br /&gt;
    if !user_existed and requested_user_saved&lt;br /&gt;
      super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
      super_users.each do |super_user|&lt;br /&gt;
        prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
        prepared_mail.deliver&lt;br /&gt;
      end&lt;br /&gt;
      #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
      ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
      flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_existed&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting has already existed in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Refactored Method ====&lt;br /&gt;
&lt;br /&gt;
The new create_requested_user_record now only handles the different cases that can happen when a user requests an account (New user and request goes through, duplicate user and request doesn't go through, or some other error in the saving process. The new method save_requested_user creates the request object, validates it has all needed fields and tries to save it to the database. The new method notify_supers_new_request sends an email to the Super-Administrators that new user account request has been successfully created. Some variable names and error messages have been reworded to improve readability as well.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def create_requested_user_record&lt;br /&gt;
    requested_user = AccountRequest.new(requested_user_params)&lt;br /&gt;
    #An object is created with respect to AccountRequest model inorder to populate the users information when account is requested&lt;br /&gt;
    user_exists = User.find_by(name: requested_user.name) or User.find_by(name: requested_user.email)&lt;br /&gt;
    requested_user_saved = save_requested_user(requested_user, params)&lt;br /&gt;
    #Stores a boolean value with respect to whether the user data is saved or not&lt;br /&gt;
    if !user_exists and requested_user_saved&lt;br /&gt;
      notify_supers_new_request(requested_user)&lt;br /&gt;
      redirect_to '/instructions/home'&lt;br /&gt;
      return&lt;br /&gt;
    elsif user_exists&lt;br /&gt;
      flash[:error] = &amp;quot;The account you are requesting already exists in Expertiza.&amp;quot;&lt;br /&gt;
      #If the user account already exists, log error to the user&lt;br /&gt;
    else&lt;br /&gt;
      flash[:error] = requested_user.errors.full_messages.to_sentence&lt;br /&gt;
      #If saving in the AccountRequests model has failed&lt;br /&gt;
    end&lt;br /&gt;
    ExpertizaLogger.error LoggerMessage.new(controller_name, requested_user.name, flash[:error], request)&lt;br /&gt;
    redirect_to controller: 'account_request', action: 'new', role: 'Student'&lt;br /&gt;
    #if the first if clause fails, redirect back to the account requests page!&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def save_requested_user(requested_user, params)&lt;br /&gt;
    if params[:user][:institution_id].empty?&lt;br /&gt;
      institution = Institution.find_or_create_by(name: params[:institution][:name])&lt;br /&gt;
      requested_user.institution_id = institution.id&lt;br /&gt;
    end&lt;br /&gt;
    #If user enters others and adds a new institution, an institution id will be created with respect to the institution model.&lt;br /&gt;
    #This institution_attribute will be added to the AccountRequest model under institution_id attribute!&lt;br /&gt;
    requested_user.status = 'Under Review'&lt;br /&gt;
    #The status is by default 'Under Review' until the super admin approves or rejects&lt;br /&gt;
    # default to instructor role&lt;br /&gt;
    if requested_user.role_id == nil&lt;br /&gt;
      requested_user.role_id = Role.where(:name =&amp;gt; &amp;quot;Instructor&amp;quot;)[0].id&lt;br /&gt;
    end&lt;br /&gt;
    return requested_user.save&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  def  notify_supers_new_request(requested_user)&lt;br /&gt;
    super_users = User.joins(:role).where('roles.name = ?', 'Super-Administrator')&lt;br /&gt;
    super_users.each do |super_user|&lt;br /&gt;
      prepared_mail = MailerHelper.send_mail_to_all_super_users(super_user, requested_user, 'New account Request')&lt;br /&gt;
      prepared_mail.deliver&lt;br /&gt;
    end&lt;br /&gt;
    #Notifying an email to the administrator regarding the new user request!&lt;br /&gt;
    ExpertizaLogger.info LoggerMessage.new(controller_name, requested_user.name, 'The account you are requesting has been created successfully.', request)&lt;br /&gt;
    flash[:success] = &amp;quot;User signup for \&amp;quot;#{requested_user.name}\&amp;quot; has been successfully requested.&amp;quot;&lt;br /&gt;
    #Print out the acknowledgement message to the user and redirect to /instructors/home page when successful&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Results ==&lt;br /&gt;
&lt;br /&gt;
12 out of 12 tests in the account_request_controller_spec.rb test file. &lt;br /&gt;
&lt;br /&gt;
Our code changes can be viewed [https://github.com/expertiza/expertiza/pull/2094/files here].&lt;br /&gt;
&lt;br /&gt;
Here is a image of our tests passing:&amp;lt;br&amp;gt;&lt;br /&gt;
[[File:Passing Test.jpg]]&lt;br /&gt;
&lt;br /&gt;
=== Relevant Links ===&lt;br /&gt;
&lt;br /&gt;
Main Expertiza Repository can be found [https://github.com/expertiza/expertiza here].&lt;br /&gt;
&lt;br /&gt;
Our forked Repository can be found [https://github.com/majuabir/expertiza/tree/beta here].&lt;/div&gt;</summary>
		<author><name>Aamajumd</name></author>
	</entry>
</feed>