<?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=Evilkom</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=Evilkom"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Evilkom"/>
	<updated>2026-06-28T05:47:57Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=165250</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=165250"/>
		<updated>2025-04-26T22:51:46Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Test Coverage Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Addressed Problems==&lt;br /&gt;
&lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
&amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
&amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=ruby line&amp;gt; def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=ruby line&amp;gt; def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
Business logic is placed in services to simplify future updates.  &lt;br /&gt;
Private methods are used to improve unit test isolation.  &lt;br /&gt;
Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;syntaxhighlight lang=ruby line&amp;gt; def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
RESTful routes and actions are followed.  &lt;br /&gt;
&amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
  &amp;lt;syntaxhighlight lang=ruby line&amp;gt; def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
Locale is determined from parameters or browser headers.  &lt;br /&gt;
Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
  &amp;lt;syntaxhighlight lang=ruby line&amp;gt;def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
&lt;br /&gt;
[[File:controllerdiagram.png]]&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` was deleted&lt;br /&gt;
* Related counters for metareview progress was removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=ruby line&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=ruby line&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=ruby line&amp;gt;def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Test Coverage Summary ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|none|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 84.62%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.00%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 84.48%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|none|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller (Original Expertiza Repo):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb&lt;br /&gt;
&lt;br /&gt;
* '''Views (one controller action view and three partials):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/tree/main/app/views/student_review&lt;br /&gt;
&lt;br /&gt;
* '''StudentReviewService Implementation Repo (Kii4ka):'''  &lt;br /&gt;
  https://github.com/Kii4ka/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
* '''Pull Request to Expertiza Reimplementation Repo (#197):'''  &lt;br /&gt;
  https://github.com/expertiza/reimplementation-back-end/pull/197&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=165243</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=165243"/>
		<updated>2025-04-25T02:17:19Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Addressed Problems==&lt;br /&gt;
&lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
&amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
&amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=ruby line&amp;gt; def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=ruby line&amp;gt; def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
Business logic is placed in services to simplify future updates.  &lt;br /&gt;
Private methods are used to improve unit test isolation.  &lt;br /&gt;
Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
 &amp;lt;syntaxhighlight lang=ruby line&amp;gt; def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
RESTful routes and actions are followed.  &lt;br /&gt;
&amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
  &amp;lt;syntaxhighlight lang=ruby line&amp;gt; def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
Locale is determined from parameters or browser headers.  &lt;br /&gt;
Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
  &amp;lt;syntaxhighlight lang=ruby line&amp;gt;def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
&lt;br /&gt;
[[File:controllerdiagram.png]]&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` was deleted&lt;br /&gt;
* Related counters for metareview progress was removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=ruby line&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;syntaxhighlight lang=ruby line&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end &amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=ruby line&amp;gt;def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Test Coverage Summary ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|none|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 93.75%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|none|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller (Original Expertiza Repo):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb&lt;br /&gt;
&lt;br /&gt;
* '''Views (one controller action view and three partials):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/tree/main/app/views/student_review&lt;br /&gt;
&lt;br /&gt;
* '''StudentReviewService Implementation Repo (Kii4ka):'''  &lt;br /&gt;
  https://github.com/Kii4ka/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
* '''Pull Request to Expertiza Reimplementation Repo (#197):'''  &lt;br /&gt;
  https://github.com/expertiza/reimplementation-back-end/pull/197&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=165242</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=165242"/>
		<updated>2025-04-25T02:12:05Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Single Responsibility Principle (SRP) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Addressed Problems==&lt;br /&gt;
&lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
&amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
&amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=ruby line&amp;gt; def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
Business logic is placed in services to simplify future updates.  &lt;br /&gt;
Private methods are used to improve unit test isolation.  &lt;br /&gt;
Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
RESTful routes and actions are followed.  &lt;br /&gt;
&amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
Locale is determined from parameters or browser headers.  &lt;br /&gt;
Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
&lt;br /&gt;
[[File:controllerdiagram.png]]&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` was deleted&lt;br /&gt;
* Related counters for metareview progress was removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Test Coverage Summary ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|none|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 93.75%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|none|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller (Original Expertiza Repo):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb&lt;br /&gt;
&lt;br /&gt;
* '''Views (one controller action view and three partials):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/tree/main/app/views/student_review&lt;br /&gt;
&lt;br /&gt;
* '''StudentReviewService Implementation Repo (Kii4ka):'''  &lt;br /&gt;
  https://github.com/Kii4ka/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
* '''Pull Request to Expertiza Reimplementation Repo (#197):'''  &lt;br /&gt;
  https://github.com/expertiza/reimplementation-back-end/pull/197&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=165000</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=165000"/>
		<updated>2025-04-23T02:13:23Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Addressed Problems==&lt;br /&gt;
&lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
&amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
&amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
Business logic is placed in services to simplify future updates.  &lt;br /&gt;
Private methods are used to improve unit test isolation.  &lt;br /&gt;
Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
RESTful routes and actions are followed.  &lt;br /&gt;
&amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
Locale is determined from parameters or browser headers.  &lt;br /&gt;
Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
&lt;br /&gt;
[[File:controllerdiagram.png]]&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` was deleted&lt;br /&gt;
* Related counters for metareview progress was removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Test Coverage Summary ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|none|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 93.75%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|none|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller (Original Expertiza Repo):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb&lt;br /&gt;
&lt;br /&gt;
* '''Views (one controller action view and three partials):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/tree/main/app/views/student_review&lt;br /&gt;
&lt;br /&gt;
* '''StudentReviewService Implementation Repo (Kii4ka):'''  &lt;br /&gt;
  https://github.com/Kii4ka/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
* '''Pull Request to Expertiza Reimplementation Repo (#197):'''  &lt;br /&gt;
  https://github.com/expertiza/reimplementation-back-end/pull/197&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164991</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164991"/>
		<updated>2025-04-23T02:05:11Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Response Handling */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Addressed Problems==&lt;br /&gt;
&lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
&lt;br /&gt;
[[File:controllerdiagram.png]]&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Test Coverage Summary ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|none|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 93.75%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|none|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller (Original Expertiza Repo):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb&lt;br /&gt;
&lt;br /&gt;
* '''Views (one controller action view and three partials):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/tree/main/app/views/student_review&lt;br /&gt;
&lt;br /&gt;
* '''StudentReviewService Implementation Repo (Kii4ka):'''  &lt;br /&gt;
  https://github.com/Kii4ka/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
* '''Pull Request to Expertiza Reimplementation Repo (#197):'''  &lt;br /&gt;
  https://github.com/expertiza/reimplementation-back-end/pull/197&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164988</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164988"/>
		<updated>2025-04-23T02:04:08Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Design Principles Analysis */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Addressed Problems==&lt;br /&gt;
&lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
&lt;br /&gt;
[[File:controllerdiagram.png]]&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Test Coverage Summary ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|none|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 93.75%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|none|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller (Original Expertiza Repo):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb&lt;br /&gt;
&lt;br /&gt;
* '''Views (one controller action view and three partials):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/tree/main/app/views/student_review&lt;br /&gt;
&lt;br /&gt;
* '''StudentReviewService Implementation Repo (Kii4ka):'''  &lt;br /&gt;
  https://github.com/Kii4ka/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
* '''Pull Request to Expertiza Reimplementation Repo (#197):'''  &lt;br /&gt;
  https://github.com/expertiza/reimplementation-back-end/pull/197&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164977</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164977"/>
		<updated>2025-04-23T01:58:07Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Existing Issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Addressed Problems==&lt;br /&gt;
&lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
&lt;br /&gt;
[[File:controllerdiagram.png]]&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Test Coverage Summary ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|none|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 93.75%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|none|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller (Original Expertiza Repo):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb&lt;br /&gt;
&lt;br /&gt;
* '''Views (one controller action view and three partials):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/tree/main/app/views/student_review&lt;br /&gt;
&lt;br /&gt;
* '''StudentReviewService Implementation Repo (Kii4ka):'''  &lt;br /&gt;
  https://github.com/Kii4ka/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
* '''Pull Request to Expertiza Reimplementation Repo (#197):'''  &lt;br /&gt;
  https://github.com/expertiza/reimplementation-back-end/pull/197&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164949</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164949"/>
		<updated>2025-04-23T01:23:51Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
&lt;br /&gt;
[[File:controllerdiagram.png]]&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Test Coverage Summary ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|none|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 93.75%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|none|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller (Original Expertiza Repo):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb&lt;br /&gt;
&lt;br /&gt;
* '''Views (one controller action view and three partials):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/tree/main/app/views/student_review&lt;br /&gt;
&lt;br /&gt;
* '''StudentReviewService Implementation Repo (Kii4ka):'''  &lt;br /&gt;
  https://github.com/Kii4ka/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
* '''Pull Request to Expertiza Reimplementation Repo (#197):'''  &lt;br /&gt;
  https://github.com/expertiza/reimplementation-back-end/pull/197&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164703</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164703"/>
		<updated>2025-04-22T18:25:39Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Test Coverage Summary ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|none|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|none|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller (Original Expertiza Repo):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb&lt;br /&gt;
&lt;br /&gt;
* '''Views (one controller action view and three partials):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/tree/main/app/views/student_review&lt;br /&gt;
&lt;br /&gt;
* '''StudentReviewService Implementation Repo (Kii4ka):'''  &lt;br /&gt;
  https://github.com/Kii4ka/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
* '''Pull Request to Expertiza Reimplementation Repo (#197):'''  &lt;br /&gt;
  https://github.com/expertiza/reimplementation-back-end/pull/197&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164679</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164679"/>
		<updated>2025-04-22T17:50:39Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Controller */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|none|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|none|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller (Original Expertiza Repo):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb&lt;br /&gt;
&lt;br /&gt;
* '''Views (one controller action view and three partials):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/tree/main/app/views/student_review&lt;br /&gt;
&lt;br /&gt;
* '''StudentReviewService Implementation Repo (Kii4ka):'''  &lt;br /&gt;
  https://github.com/Kii4ka/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
* '''Pull Request to Expertiza Reimplementation Repo (#197):'''  &lt;br /&gt;
  https://github.com/expertiza/reimplementation-back-end/pull/197&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164678</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164678"/>
		<updated>2025-04-22T17:49:22Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Relevant Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|none|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|none|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller (Original Expertiza Repo):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb&lt;br /&gt;
&lt;br /&gt;
* '''Views (one controller action view and three partials):'''  &lt;br /&gt;
  https://github.com/expertiza/expertiza/tree/main/app/views/student_review&lt;br /&gt;
&lt;br /&gt;
* '''StudentReviewService Implementation Repo (Kii4ka):'''  &lt;br /&gt;
  https://github.com/Kii4ka/reimplementation-back-end&lt;br /&gt;
&lt;br /&gt;
* '''Pull Request to Expertiza Reimplementation Repo (#197):'''  &lt;br /&gt;
  https://github.com/expertiza/reimplementation-back-end/pull/197&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164675</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164675"/>
		<updated>2025-04-22T17:41:48Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Test Coverage Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|none|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|none|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164674</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164674"/>
		<updated>2025-04-22T17:41:25Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|left|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|none|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164673</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164673"/>
		<updated>2025-04-22T17:39:43Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Test Coverage Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|left|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
[[File:Ckecks.png|thumb|left|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164672</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164672"/>
		<updated>2025-04-22T17:38:44Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Test Coverage Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|left|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Ckecks.png|thumb|center|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- This blank line creates the space --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164669</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164669"/>
		<updated>2025-04-22T17:37:21Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|left|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Ckecks.png|thumb|left|center|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164667</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164667"/>
		<updated>2025-04-22T17:36:51Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Test Coverage Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|center|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Ckecks.png|thumb|left|center|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164666</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164666"/>
		<updated>2025-04-22T17:35:55Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  LIST_ACTION     = 'list'.freeze&lt;br /&gt;
  SUBMITTER_ROLE  = 'submitter'.freeze&lt;br /&gt;
&lt;br /&gt;
  before_action :authorize_user, only: [LIST_ACTION.to_sym]&lt;br /&gt;
  before_action :load_service, only: [:list]&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  def authorize_user&lt;br /&gt;
    unless action_allowed?&lt;br /&gt;
      render json: { error: 'Unauthorized' }, status: :unauthorized&lt;br /&gt;
      return&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Quick-exit unless they're a student.&lt;br /&gt;
  # Then, only allow the LIST_ACTION for users who also have the SUBMITTER_ROLE on this resource.&lt;br /&gt;
  def action_allowed?&lt;br /&gt;
    # guard clause: must be a student at all&lt;br /&gt;
    return false unless current_user_has_student_privileges?  # early return&lt;br /&gt;
&lt;br /&gt;
    # only permit “list” for submitters&lt;br /&gt;
    action_name == LIST_ACTION &amp;amp;&amp;amp;&lt;br /&gt;
      are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE)&lt;br /&gt;
  end&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility. Adding the below code to ApplicationController Class.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  # 1) Set locale for every request&lt;br /&gt;
  before_action :set_locale&lt;br /&gt;
  # 2) Perform authorization&lt;br /&gt;
  before_action :authorize&lt;br /&gt;
&lt;br /&gt;
  private&lt;br /&gt;
&lt;br /&gt;
  # Sets I18n.locale based on params, Accept-Language header, or default&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
  # Returns a valid locale symbol or nil&lt;br /&gt;
  def extract_locale&lt;br /&gt;
    # 1) Param override&lt;br /&gt;
    if params[:locale].present?&lt;br /&gt;
      sym = params[:locale].to_sym&lt;br /&gt;
      return sym if I18n.available_locales.include?(sym)&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    # 2) Accept-Language header fallback&lt;br /&gt;
    header = request.env['HTTP_ACCEPT_LANGUAGE'].to_s&lt;br /&gt;
    header&lt;br /&gt;
      .split(',')&lt;br /&gt;
      .map { |l| l[0..1].downcase.to_sym }&lt;br /&gt;
      .find { |loc| I18n.available_locales.include?(loc) }&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|left|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Ckecks.png|thumb|left|600px|All checks have passed]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
______&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Ckecks.png&amp;diff=164663</id>
		<title>File:Ckecks.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Ckecks.png&amp;diff=164663"/>
		<updated>2025-04-22T17:32:37Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164630</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164630"/>
		<updated>2025-04-22T16:33:13Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Test Coverage Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|left|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
______&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164629</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164629"/>
		<updated>2025-04-22T16:33:01Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Test Coverage Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|left|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164627</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164627"/>
		<updated>2025-04-22T16:32:40Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Test Coverage Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|left|600px|RSpec Tests Report]]&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164626</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164626"/>
		<updated>2025-04-22T16:31:33Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Test Coverage Summary */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
[[File:Screenshot_2025-04-22_at_12.29.17_PM.png|thumb|center|600px|Screenshot of StudentReviewController test passes]]&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=File:Screenshot_2025-04-22_at_12.29.17_PM.png&amp;diff=164625</id>
		<title>File:Screenshot 2025-04-22 at 12.29.17 PM.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=File:Screenshot_2025-04-22_at_12.29.17_PM.png&amp;diff=164625"/>
		<updated>2025-04-22T16:30:18Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164619</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164619"/>
		<updated>2025-04-22T16:24:56Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Test Coverage Summary ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! File Name&lt;br /&gt;
! Test Coverage&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/api/v1/student_review_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 86.67%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/controllers/application_controller.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 100.0%&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;app/services/student_review_service.rb&amp;lt;/code&amp;gt;&lt;br /&gt;
| 85.71%&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewController Spec ==&lt;br /&gt;
&lt;br /&gt;
The test file provides comprehensive test coverage for the &amp;lt;code&amp;gt;Api::V1::StudentReviewController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Core Controller Functionality ===&lt;br /&gt;
* '''Controller Action Existence:'''  &lt;br /&gt;
  - Verifies that the &amp;lt;code&amp;gt;list&amp;lt;/code&amp;gt; action is defined.&lt;br /&gt;
* '''Response Structure:'''  &lt;br /&gt;
  - Confirms the controller returns the expected JSON structure with all required fields.&lt;br /&gt;
* '''Authorization Logic:'''  &lt;br /&gt;
  - Ensures that proper authorization checks are in place and function correctly.&lt;br /&gt;
&lt;br /&gt;
=== Authorization Tests ===&lt;br /&gt;
* '''Proper Authorization:'''  &lt;br /&gt;
  - Tests scenarios where a user is authorized to access resources.&lt;br /&gt;
* '''Unauthorized Access:'''  &lt;br /&gt;
  - Ensures unauthorized users receive a 401 response.&lt;br /&gt;
* '''Student Privileges:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;action_allowed?&amp;lt;/code&amp;gt; method with and without student privileges.&lt;br /&gt;
* '''Participant Authorization:'''  &lt;br /&gt;
  - Verifies the &amp;lt;code&amp;gt;authorized_participant?&amp;lt;/code&amp;gt; method behavior.&lt;br /&gt;
&lt;br /&gt;
=== Bidding Functionality ===&lt;br /&gt;
* '''Bidding Enabled:'''  &lt;br /&gt;
  - Verifies redirection occurs when bidding is enabled.&lt;br /&gt;
* '''Bidding Disabled:'''  &lt;br /&gt;
  - Ensures no redirection occurs when bidding is disabled.&lt;br /&gt;
* '''&amp;lt;code&amp;gt;check_bidding_redirect&amp;lt;/code&amp;gt; Method:'''  &lt;br /&gt;
  - Tests the method independently to verify redirection logic.&lt;br /&gt;
&lt;br /&gt;
=== Service Integration ===&lt;br /&gt;
* '''Service Loading:'''  &lt;br /&gt;
  - Tests for proper initialization of the &amp;lt;code&amp;gt;load_service&amp;lt;/code&amp;gt; method.&lt;br /&gt;
* '''Service Data Usage:'''  &lt;br /&gt;
  - Confirms service output is correctly used in controller responses.&lt;br /&gt;
&lt;br /&gt;
=== Reviewer-related Tests ===&lt;br /&gt;
* '''With Reviewer:'''  &lt;br /&gt;
  - Tests the flow when a participant has an associated reviewer.&lt;br /&gt;
* '''Without Reviewer:'''  &lt;br /&gt;
  - Tests behavior when no reviewer is present.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Types ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests functionality related to calibration logic.&lt;br /&gt;
* '''Topic ID Handling:'''  &lt;br /&gt;
  - Verifies accurate calculation of &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Internationalization ===&lt;br /&gt;
* '''Locale Setting:'''  &lt;br /&gt;
  - Tests &amp;lt;code&amp;gt;controller_locale&amp;lt;/code&amp;gt; method functionality.&lt;br /&gt;
* '''User Locale Preference:'''  &lt;br /&gt;
  - Tests locale assignment when user has preferences.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to default locale works properly.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Missing Reviewer:'''  &lt;br /&gt;
  - Verifies behavior when the reviewer does not exist.&lt;br /&gt;
* '''Review Mappings Sorting:'''  &lt;br /&gt;
  - Tests sorting logic for review mappings under various conditions.&lt;br /&gt;
&lt;br /&gt;
This comprehensive test suite ensures that all aspects of the &amp;lt;code&amp;gt;StudentReviewController&amp;lt;/code&amp;gt; are thoroughly tested—from basic functionality to edge cases and error handling—achieving a test coverage rate of '''86.67%'''.&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in ApplicationController Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;application_controller_spec.rb&amp;lt;/code&amp;gt; file provides thorough test coverage for the internationalization (i18n) functionality in the &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;. Here's a summary of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Locale Setting Logic ===&lt;br /&gt;
* '''Set Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;set_locale&amp;lt;/code&amp;gt; method that configures the application's current locale.&lt;br /&gt;
* '''Invalid Locale Handling:'''  &lt;br /&gt;
  - Verifies that invalid locales passed in parameters are properly ignored.&lt;br /&gt;
* '''Default Locale Fallback:'''  &lt;br /&gt;
  - Ensures fallback to the default locale when no valid locale is found.&lt;br /&gt;
&lt;br /&gt;
=== Locale Extraction ===&lt;br /&gt;
* '''Extract Locale Method:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;extract_locale&amp;lt;/code&amp;gt; method for determining the locale to use.&lt;br /&gt;
* '''Parameter-based Extraction:'''  &lt;br /&gt;
  - Verifies that the locale is correctly extracted from URL parameters.&lt;br /&gt;
* '''HTTP Header Extraction:'''  &lt;br /&gt;
  - Tests extraction of locale from the &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; HTTP header.&lt;br /&gt;
* '''Validation:'''  &lt;br /&gt;
  - Confirms extracted locales are checked against &amp;lt;code&amp;gt;I18n.available_locales&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== HTTP Accept-Language Header Parsing ===&lt;br /&gt;
* '''Country-Specific Codes:'''  &lt;br /&gt;
  - Tests proper handling of country-specific language codes such as &amp;lt;code&amp;gt;en-US&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Quality Factors:'''  &lt;br /&gt;
  - Tests parsing of language quality preferences (e.g., &amp;lt;code&amp;gt;fr;q=0.9&amp;lt;/code&amp;gt;).&lt;br /&gt;
* '''Multiple Languages:'''  &lt;br /&gt;
  - Verifies behavior when the header includes multiple language options.&lt;br /&gt;
* '''Invalid Languages:'''  &lt;br /&gt;
  - Ensures that unsupported languages are safely ignored.&lt;br /&gt;
* '''Empty/Nil Headers:'''  &lt;br /&gt;
  - Tests how the system behaves when the language header is empty or missing.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''Multi-part Headers:'''  &lt;br /&gt;
  - Tests parsing of complex &amp;lt;code&amp;gt;Accept-Language&amp;lt;/code&amp;gt; headers.&lt;br /&gt;
* '''Priority Handling:'''  &lt;br /&gt;
  - Ensures that language preferences are honored based on quality factors.&lt;br /&gt;
* '''Fallback Behavior:'''  &lt;br /&gt;
  - Verifies fallback logic when preferred languages are not available.&lt;br /&gt;
&lt;br /&gt;
These tests use RSpec’s controller testing features with an anonymous controller inheriting from &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; to isolate i18n behavior. Setup and teardown logic ensures that the original i18n configuration is restored after each test.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite ensures robust support for multilingual scenarios, helping maintain internationalization integrity throughout the application.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Summary of Tests in StudentReviewService Spec ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;code&amp;gt;student_review_service_spec.rb&amp;lt;/code&amp;gt; file provides comprehensive test coverage for the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class. Here's a breakdown of what was tested:&lt;br /&gt;
&lt;br /&gt;
=== Initialization and Setup ===&lt;br /&gt;
* '''Constructor Testing:'''  &lt;br /&gt;
  - Verifies proper initialization, including loading of the participant and assignment.&lt;br /&gt;
* '''Topic ID and Review Phase:'''  &lt;br /&gt;
  - Ensures that &amp;lt;code&amp;gt;topic_id&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;review_phase&amp;lt;/code&amp;gt; are set correctly.&lt;br /&gt;
* '''Error Handling:'''  &lt;br /&gt;
  - Tests that appropriate exceptions are raised when the participant does not exist.&lt;br /&gt;
&lt;br /&gt;
=== Core Functionality ===&lt;br /&gt;
* '''Bidding Enabled Check:'''  &lt;br /&gt;
  - Tests the &amp;lt;code&amp;gt;bidding_enabled?&amp;lt;/code&amp;gt; method under both enabled and disabled conditions.&lt;br /&gt;
* '''Review Mappings:'''  &lt;br /&gt;
  - Verifies correct loading and sorting of review mappings.&lt;br /&gt;
* '''Response IDs:'''  &lt;br /&gt;
  - Confirms that response IDs are correctly extracted from the database.&lt;br /&gt;
&lt;br /&gt;
=== Special Assignment Cases ===&lt;br /&gt;
* '''Calibrated Assignments:'''  &lt;br /&gt;
  - Tests sorting logic specific to calibrated assignments:&lt;br /&gt;
    - Uses &amp;lt;code&amp;gt;id % 5&amp;lt;/code&amp;gt; criteria.&lt;br /&gt;
    - Covers specific IDs (1, 2, 5, 6, 7) to ensure sorting correctness.&lt;br /&gt;
&lt;br /&gt;
=== Edge Cases ===&lt;br /&gt;
* '''No Reviewer:'''  &lt;br /&gt;
  - Ensures &amp;lt;code&amp;gt;review_mappings&amp;lt;/code&amp;gt; is set to an empty array.&lt;br /&gt;
  - Verifies that progress counters for reviews are zero.&lt;br /&gt;
&lt;br /&gt;
=== Response Handling ===&lt;br /&gt;
* '''Response ID Loading:'''  &lt;br /&gt;
  - Confirms response IDs are correctly retrieved from &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt;.&lt;br /&gt;
* '''Empty Response Lists:'''  &lt;br /&gt;
  - Tests proper handling when no responses are available.&lt;br /&gt;
&lt;br /&gt;
=== Testing Approach ===&lt;br /&gt;
This test suite uses RSpec's mocking and stubbing features to isolate logic from external dependencies:&lt;br /&gt;
* Uses doubles for models like &amp;lt;code&amp;gt;User&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;Assignment&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;Participant&amp;lt;/code&amp;gt;.&lt;br /&gt;
* Stubs private methods when needed to focus tests on expected behavior.&lt;br /&gt;
* Mocks &amp;lt;code&amp;gt;SampleReview&amp;lt;/code&amp;gt; for controlled data input.&lt;br /&gt;
* Uses RSpec's expectation syntax to assert correctness.&lt;br /&gt;
&lt;br /&gt;
Overall, this test suite thoroughly validates the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; class under both standard and edge-case scenarios, ensuring correct functionality for calibrated assignments, bidding, review progress, and reviewer absence.&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164560</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164560"/>
		<updated>2025-04-22T07:09:21Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting  (including calibrated assignments)&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
* `controller_locale` method:  &lt;br /&gt;
  * Verify that the locale is correctly set for student users.&lt;br /&gt;
  * Test fallback behavior if locale cannot be determined.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design Principles Analysis ==&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt;, and &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Single Responsibility Principle (SRP) ===&lt;br /&gt;
* '''Focused Responsibilities:'''  &lt;br /&gt;
  - &amp;lt;code&amp;gt;StudentReviewService&amp;lt;/code&amp;gt; handles only review-related operations.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;ApplicationController&amp;lt;/code&amp;gt; manages cross-cutting concerns such as authorization and locale setting.  &lt;br /&gt;
  - Each class and method has one clear and dedicated purpose.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def calculate_review_progress&lt;br /&gt;
    @num_reviews_total = @review_mappings.size&lt;br /&gt;
    @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
      !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
    end&lt;br /&gt;
    @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== DRY (Don’t Repeat Yourself) ===&lt;br /&gt;
* '''Centralized Logic:'''  &lt;br /&gt;
  - Shared methods like &amp;lt;code&amp;gt;load_participant_and_assignment&amp;lt;/code&amp;gt; promote reuse.  &lt;br /&gt;
  - Authorization and locale-setting logic are abstracted into concerns.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def load_participant_and_assignment(participant_id)&lt;br /&gt;
    @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
    @assignment = @participant.assignment&lt;br /&gt;
    @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
    @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Maintainability and Testability ===&lt;br /&gt;
* '''Modular Design:'''  &lt;br /&gt;
  - Business logic is placed in services to simplify future updates.  &lt;br /&gt;
  - Private methods are used to improve unit test isolation.  &lt;br /&gt;
  - Clear method names improve code readability.  &lt;br /&gt;
&lt;br /&gt;
  def load_review_mappings&lt;br /&gt;
    reviewer = @participant.get_reviewer&lt;br /&gt;
    @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
    @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== RESTful Best Practices ===&lt;br /&gt;
* '''Rails-Conventional Controllers:'''  &lt;br /&gt;
  - RESTful routes and actions are followed.  &lt;br /&gt;
  - &amp;lt;code&amp;gt;AuthenticationController&amp;lt;/code&amp;gt; includes a clear and secure login endpoint.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def login&lt;br /&gt;
    user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
    if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
      token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
      render json: { token: }, status: :ok&lt;br /&gt;
    else&lt;br /&gt;
      render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Localization and Internationalization ===&lt;br /&gt;
* '''Locale Handling:'''  &lt;br /&gt;
  - Locale is determined from parameters or browser headers.  &lt;br /&gt;
  - Rails i18n support is properly configured and applied.  &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  def set_locale&lt;br /&gt;
    I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary Table ===&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Additional Strengths ===  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164559</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164559"/>
		<updated>2025-04-22T06:55:00Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Additional Strengths */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting  (including calibrated assignments)&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
* `controller_locale` method:  &lt;br /&gt;
  * Verify that the locale is correctly set for student users.&lt;br /&gt;
  * Test fallback behavior if locale cannot be determined.&lt;br /&gt;
&lt;br /&gt;
== Summary Table ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Additional Strengths ==  &lt;br /&gt;
&lt;br /&gt;
* '''Service Object Pattern:'''  &lt;br /&gt;
  - Business logic is encapsulated in dedicated service classes, improving modularity and reuse.  &lt;br /&gt;
&lt;br /&gt;
* '''JWT Authentication:'''  &lt;br /&gt;
  - Secure authentication is implemented using JSON Web Tokens with proper token generation and expiration handling.  &lt;br /&gt;
&lt;br /&gt;
* '''Readable Method Naming:'''  &lt;br /&gt;
  - Method names clearly reflect their responsibilities, enhancing code readability and maintainability.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164558</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164558"/>
		<updated>2025-04-22T06:53:51Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Summary Table */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting  (including calibrated assignments)&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
* `controller_locale` method:  &lt;br /&gt;
  * Verify that the locale is correctly set for student users.&lt;br /&gt;
  * Test fallback behavior if locale cannot be determined.&lt;br /&gt;
&lt;br /&gt;
== Summary Table ==&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Principle&lt;br /&gt;
! Status&lt;br /&gt;
! Notes&lt;br /&gt;
|-&lt;br /&gt;
| '''Single Responsibility'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Each class has one focused responsibility&lt;br /&gt;
|-&lt;br /&gt;
| '''DRY'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Shared logic centralized in service methods&lt;br /&gt;
|-&lt;br /&gt;
| '''Maintainability &amp;amp; Testability'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Modular code with helper methods and clear naming&lt;br /&gt;
|-&lt;br /&gt;
| '''RESTful Practices'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Follows Rails conventions&lt;br /&gt;
|-&lt;br /&gt;
| '''Localization/i18n'''&lt;br /&gt;
| Implemented&lt;br /&gt;
| Locale handled through params and headers&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==   Additional Strengths == &lt;br /&gt;
&lt;br /&gt;
- **Service Object Pattern** used for organizing business logic.&lt;br /&gt;
- **JWT Authentication** for secure login flow.&lt;br /&gt;
- **Readable Method Naming** improves developer experience.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164557</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164557"/>
		<updated>2025-04-22T06:52:27Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* View Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting  (including calibrated assignments)&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
* `controller_locale` method:  &lt;br /&gt;
  * Verify that the locale is correctly set for student users.&lt;br /&gt;
  * Test fallback behavior if locale cannot be determined.&lt;br /&gt;
&lt;br /&gt;
==  Summary Table == &lt;br /&gt;
&lt;br /&gt;
| Principle                        | Status       | Notes                                                    |&lt;br /&gt;
|----------------------------------|--------------|----------------------------------------------------------|&lt;br /&gt;
| **Single Responsibility**        |  Implemented | Each class has one focused responsibility                |&lt;br /&gt;
| **DRY**                          |  Implemented | Shared logic centralized in service methods              |&lt;br /&gt;
| **Maintainability &amp;amp; Testability**|  Implemented | Modular code with helper methods and clear naming        |&lt;br /&gt;
| **RESTful Practices**            |  Implemented | Follows Rails conventions                                |&lt;br /&gt;
| **Localization/i18n**            |  Implemented | Locale handled through params and headers                |&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
==   Additional Strengths == &lt;br /&gt;
&lt;br /&gt;
- **Service Object Pattern** used for organizing business logic.&lt;br /&gt;
- **JWT Authentication** for secure login flow.&lt;br /&gt;
- **Readable Method Naming** improves developer experience.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164556</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164556"/>
		<updated>2025-04-22T06:47:44Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Design Principles Applied (Planned) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting  (including calibrated assignments)&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
* `controller_locale` method:  &lt;br /&gt;
  * Verify that the locale is correctly set for student users.&lt;br /&gt;
  * Test fallback behavior if locale cannot be determined.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
## Design Principles Analysis&lt;br /&gt;
&lt;br /&gt;
This section outlines how our application aligns with core software design principles, based on a detailed analysis of the `StudentReviewService`, `ApplicationController`, and `AuthenticationController`.&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### Single Responsibility Principle (SRP)&lt;br /&gt;
&lt;br /&gt;
Each component is focused on a distinct task.&lt;br /&gt;
&lt;br /&gt;
- `StudentReviewService`: Handles only review-related operations.&lt;br /&gt;
- `ApplicationController`: Manages authorization, locale, and other cross-cutting concerns.&lt;br /&gt;
- Modular design ensures that each class or method has one clear purpose.&lt;br /&gt;
&lt;br /&gt;
**Example:**&lt;br /&gt;
```ruby&lt;br /&gt;
def calculate_review_progress&lt;br /&gt;
  @num_reviews_total = @review_mappings.size&lt;br /&gt;
  @num_reviews_completed = @review_mappings.count do |map|&lt;br /&gt;
    !map.response.empty? &amp;amp;&amp;amp; map.response.last.is_submitted&lt;br /&gt;
  end&lt;br /&gt;
  @num_reviews_in_progress = @num_reviews_total - @num_reviews_completed&lt;br /&gt;
end&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### DRY (Don’t Repeat Yourself)&lt;br /&gt;
&lt;br /&gt;
Shared logic is centralized and reused effectively.&lt;br /&gt;
&lt;br /&gt;
- `load_participant_and_assignment` encapsulates reused logic.&lt;br /&gt;
- Authorization and locale-setting logic is factored into concerns.&lt;br /&gt;
&lt;br /&gt;
**Example:**&lt;br /&gt;
```ruby&lt;br /&gt;
def load_participant_and_assignment(participant_id)&lt;br /&gt;
  @participant = AssignmentParticipant.find(participant_id)&lt;br /&gt;
  @assignment = @participant.assignment&lt;br /&gt;
  @topic_id = SignedUpTeam.topic_id(@assignment.id, @participant.user_id)&lt;br /&gt;
  @review_phase = @assignment.current_stage(@topic_id)&lt;br /&gt;
end&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### Maintainability and Testability&lt;br /&gt;
&lt;br /&gt;
- Separation of responsibilities into service objects simplifies testing.&lt;br /&gt;
- Private helper methods clarify logic.&lt;br /&gt;
- Clear method naming aids readability and future maintenance.&lt;br /&gt;
&lt;br /&gt;
**Example:**&lt;br /&gt;
```ruby&lt;br /&gt;
def load_review_mappings&lt;br /&gt;
  reviewer = @participant.get_reviewer&lt;br /&gt;
  @review_mappings = reviewer ? ReviewResponseMap.where(...) : []&lt;br /&gt;
  @review_mappings = @review_mappings.sort_by { |m| m.id % 5 } if @assignment.is_calibrated&lt;br /&gt;
end&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### RESTful Best Practices&lt;br /&gt;
&lt;br /&gt;
- Controller actions follow REST conventions.&lt;br /&gt;
- `AuthenticationController` uses standard patterns for login/authentication.&lt;br /&gt;
&lt;br /&gt;
**Example:**&lt;br /&gt;
```ruby&lt;br /&gt;
def login&lt;br /&gt;
  user = User.find_by(name: params[:user_name]) || User.find_by(email: params[:user_name])&lt;br /&gt;
  if user&amp;amp;.authenticate(params[:password])&lt;br /&gt;
    token = JsonWebToken.encode({ id: user.id, ... }, 24.hours.from_now)&lt;br /&gt;
    render json: { token: }, status: :ok&lt;br /&gt;
  else&lt;br /&gt;
    render json: { error: 'Invalid username / password' }, status: :unauthorized&lt;br /&gt;
  end&lt;br /&gt;
end&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### Localization and Internationalization&lt;br /&gt;
&lt;br /&gt;
- Locale is extracted from URL params or browser headers.&lt;br /&gt;
- Rails i18n framework is used appropriately.&lt;br /&gt;
&lt;br /&gt;
**Example:**&lt;br /&gt;
```ruby&lt;br /&gt;
def set_locale&lt;br /&gt;
  I18n.locale = extract_locale || I18n.default_locale&lt;br /&gt;
end&lt;br /&gt;
```&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
### 📌 Summary Table&lt;br /&gt;
&lt;br /&gt;
| Principle                        | Status       | Notes                                                    |&lt;br /&gt;
|----------------------------------|--------------|----------------------------------------------------------|&lt;br /&gt;
| **Single Responsibility**        |  Implemented | Each class has one focused responsibility                |&lt;br /&gt;
| **DRY**                          |  Implemented | Shared logic centralized in service methods              |&lt;br /&gt;
| **Maintainability &amp;amp; Testability**|  Implemented | Modular code with helper methods and clear naming        |&lt;br /&gt;
| **RESTful Practices**            |  Implemented | Follows Rails conventions                                |&lt;br /&gt;
| **Localization/i18n**            |  Implemented | Locale handled through params and headers                |&lt;br /&gt;
&lt;br /&gt;
---&lt;br /&gt;
&lt;br /&gt;
###  Additional Strengths&lt;br /&gt;
&lt;br /&gt;
- **Service Object Pattern** used for organizing business logic.&lt;br /&gt;
- **JWT Authentication** for secure login flow.&lt;br /&gt;
- **Readable Method Naming** improves developer experience.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164018</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=164018"/>
		<updated>2025-04-18T20:13:11Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting  (including calibrated assignments)&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
* `controller_locale` method:  &lt;br /&gt;
  * Verify that the locale is correctly set for student users.&lt;br /&gt;
  * Test fallback behavior if locale cannot be determined.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Design Principles Applied (Planned)===  &lt;br /&gt;
* '''Single Responsibility Principle (SRP):'''  &lt;br /&gt;
  Each component is focused on a distinct task.  &lt;br /&gt;
* '''DRY (Don't Repeat Yourself):'''  &lt;br /&gt;
  Shared logic is extracted into reusable service methods.  &lt;br /&gt;
* '''Maintainability and Testability:'''  &lt;br /&gt;
  A modular design makes future updates and testing easier.  &lt;br /&gt;
* '''Use of Constants:'''  &lt;br /&gt;
  Magic strings are replaced with named constants for clarity.&lt;br /&gt;
* '''RESTful Best Practices:'''&lt;br /&gt;
  Routes and controller actions follow Rails conventions&lt;br /&gt;
* '''Localization and Internationalization:'''  &lt;br /&gt;
  Support for multiple languages via proper use of the `controller_locale` method and Rails i18n framework.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163401</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163401"/>
		<updated>2025-04-07T16:28:18Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting  (including calibrated assignments)&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
* `controller_locale` method:  &lt;br /&gt;
  * Verify that the locale is correctly set for student users.&lt;br /&gt;
  * Test fallback behavior if locale cannot be determined.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Design Principles Applied (Planned)===  &lt;br /&gt;
* '''Single Responsibility Principle (SRP):'''  &lt;br /&gt;
  Each component is focused on a distinct task.  &lt;br /&gt;
* '''DRY (Don't Repeat Yourself):'''  &lt;br /&gt;
  Shared logic is extracted into reusable service methods.  &lt;br /&gt;
* '''Maintainability and Testability:'''  &lt;br /&gt;
  A modular design makes future updates and testing easier.  &lt;br /&gt;
* '''Use of Constants:'''  &lt;br /&gt;
  Magic strings are replaced with named constants for clarity.&lt;br /&gt;
* '''RESTful Best Practices:'''&lt;br /&gt;
  Routes and controller actions follow Rails conventions&lt;br /&gt;
* '''Localization and Internationalization:'''  &lt;br /&gt;
  Support for multiple languages via proper use of the `controller_locale` method and Rails i18n framework.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163400</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163400"/>
		<updated>2025-04-07T16:27:02Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Design Principles Applied (Planned) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting  (including calibrated assignments)&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
* `controller_locale` method:  &lt;br /&gt;
  * Verify that the locale is correctly set for student users.&lt;br /&gt;
  * Test fallback behavior if locale cannot be determined.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Design Principles Applied (Planned)===  &lt;br /&gt;
* '''Single Responsibility Principle (SRP):'''  &lt;br /&gt;
  Each component is focused on a distinct task.  &lt;br /&gt;
* '''DRY (Don't Repeat Yourself):'''  &lt;br /&gt;
  Shared logic is extracted into reusable service methods.  &lt;br /&gt;
* '''Maintainability and Testability:'''  &lt;br /&gt;
  A modular design makes future updates and testing easier.  &lt;br /&gt;
* '''Use of Constants:'''  &lt;br /&gt;
  Magic strings are replaced with named constants for clarity.&lt;br /&gt;
* '''RESTful Best Practices:'''&lt;br /&gt;
  Routes and controller actions follow Rails conventions&lt;br /&gt;
* '''Localization and Internationalization:'''  &lt;br /&gt;
  Support for multiple languages via proper use of the `controller_locale` method and Rails i18n framework.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163397</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163397"/>
		<updated>2025-04-07T14:45:49Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Design Principles Applied (Planned) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting  (including calibrated assignments)&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
* `controller_locale` method:  &lt;br /&gt;
  * Verify that the locale is correctly set for student users.&lt;br /&gt;
  * Test fallback behavior if locale cannot be determined.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Design Principles Applied (Planned)===  &lt;br /&gt;
* '''Single Responsibility Principle (SRP):'''  &lt;br /&gt;
  Each component is focused on a distinct task.  &lt;br /&gt;
* '''DRY (Don't Repeat Yourself):'''  &lt;br /&gt;
  Shared logic is extracted into reusable service methods.  &lt;br /&gt;
* '''Maintainability and Testability:'''  &lt;br /&gt;
  A modular design makes future updates and testing easier.  &lt;br /&gt;
* '''Use of Constants:'''  &lt;br /&gt;
  Magic strings are replaced with named constants for clarity.&lt;br /&gt;
* '''RESTful Best Practices:'''&lt;br /&gt;
Routes and controller actions follow Rails conventions&lt;br /&gt;
* '''Localization and Internationalization:'''  &lt;br /&gt;
  Support for multiple languages via proper use of the `controller_locale` method and Rails i18n framework.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163396</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163396"/>
		<updated>2025-04-07T14:44:53Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Controller Testing */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting  (including calibrated assignments)&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
* `controller_locale` method:  &lt;br /&gt;
  * Verify that the locale is correctly set for student users.&lt;br /&gt;
  * Test fallback behavior if locale cannot be determined.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Design Principles Applied (Planned)===  &lt;br /&gt;
* '''Single Responsibility Principle (SRP):'''  &lt;br /&gt;
  Each component is focused on a distinct task.  &lt;br /&gt;
* '''DRY (Don't Repeat Yourself):'''  &lt;br /&gt;
  Shared logic is extracted into reusable service methods.  &lt;br /&gt;
* '''Maintainability and Testability:'''  &lt;br /&gt;
  A modular design makes future updates and testing easier.  &lt;br /&gt;
* '''Use of Constants:'''  &lt;br /&gt;
  Magic strings are replaced with named constants for clarity.&lt;br /&gt;
* '''RESTful Best Practices:'''&lt;br /&gt;
Routes and controller actions follow Rails conventions&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163395</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163395"/>
		<updated>2025-04-07T14:44:24Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* View Refactoring Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
* Ensure views follow Rails i18n localization conventions by replacing any hardcoded strings with translation keys where appropriate.&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting  (including calibrated assignments)&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Design Principles Applied (Planned)===  &lt;br /&gt;
* '''Single Responsibility Principle (SRP):'''  &lt;br /&gt;
  Each component is focused on a distinct task.  &lt;br /&gt;
* '''DRY (Don't Repeat Yourself):'''  &lt;br /&gt;
  Shared logic is extracted into reusable service methods.  &lt;br /&gt;
* '''Maintainability and Testability:'''  &lt;br /&gt;
  A modular design makes future updates and testing easier.  &lt;br /&gt;
* '''Use of Constants:'''  &lt;br /&gt;
  Magic strings are replaced with named constants for clarity.&lt;br /&gt;
* '''RESTful Best Practices:'''&lt;br /&gt;
Routes and controller actions follow Rails conventions&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163394</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163394"/>
		<updated>2025-04-07T14:43:42Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* controller_locale Method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
* Ensure the `controller_locale` method sets the locale appropriately for student users, supporting internationalization and accessibility.&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting  (including calibrated assignments)&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Design Principles Applied (Planned)===  &lt;br /&gt;
* '''Single Responsibility Principle (SRP):'''  &lt;br /&gt;
  Each component is focused on a distinct task.  &lt;br /&gt;
* '''DRY (Don't Repeat Yourself):'''  &lt;br /&gt;
  Shared logic is extracted into reusable service methods.  &lt;br /&gt;
* '''Maintainability and Testability:'''  &lt;br /&gt;
  A modular design makes future updates and testing easier.  &lt;br /&gt;
* '''Use of Constants:'''  &lt;br /&gt;
  Magic strings are replaced with named constants for clarity.&lt;br /&gt;
* '''RESTful Best Practices:'''&lt;br /&gt;
Routes and controller actions follow Rails conventions&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163393</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163393"/>
		<updated>2025-04-07T14:43:09Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability, following Rails best practices and RESTful conventions.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
* Adhere to Rails RESTful conventions and best practices.&lt;br /&gt;
* Improve maintainability, localization support, and scalability.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form  (to be removed)&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Set locale using controller_locale&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
=== controller_locale Method ===&lt;br /&gt;
&lt;br /&gt;
Ensure the locale is properly set for student interactions&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting  (including calibrated assignments)&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Design Principles Applied (Planned)===  &lt;br /&gt;
* '''Single Responsibility Principle (SRP):'''  &lt;br /&gt;
  Each component is focused on a distinct task.  &lt;br /&gt;
* '''DRY (Don't Repeat Yourself):'''  &lt;br /&gt;
  Shared logic is extracted into reusable service methods.  &lt;br /&gt;
* '''Maintainability and Testability:'''  &lt;br /&gt;
  A modular design makes future updates and testing easier.  &lt;br /&gt;
* '''Use of Constants:'''  &lt;br /&gt;
  Magic strings are replaced with named constants for clarity.&lt;br /&gt;
* '''RESTful Best Practices:'''&lt;br /&gt;
Routes and controller actions follow Rails conventions&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163147</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163147"/>
		<updated>2025-04-04T00:18:43Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Design / Proposed Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Separation of Concerns ===&lt;br /&gt;
This reimplementation is based on a clear separation of responsibilities:&lt;br /&gt;
* The controller handles only routing, access validation, and view setup.&lt;br /&gt;
* The service object encapsulates all business logic and data handling.&lt;br /&gt;
* Obsolete functionality such as `MetareviewResponseMap` is eliminated to simplify the design.&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Design Principles Applied (Planned)===  &lt;br /&gt;
* '''Single Responsibility Principle (SRP):'''  &lt;br /&gt;
  Each component is focused on a distinct task.  &lt;br /&gt;
* '''DRY (Don't Repeat Yourself):'''  &lt;br /&gt;
  Shared logic is extracted into reusable service methods.  &lt;br /&gt;
* '''Maintainability and Testability:'''  &lt;br /&gt;
  A modular design makes future updates and testing easier.  &lt;br /&gt;
* '''Use of Constants:'''  &lt;br /&gt;
  Magic strings are replaced with named constants for clarity.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163146</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163146"/>
		<updated>2025-04-04T00:16:32Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Controller Diagram */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Design Principles Applied (Planned)===  &lt;br /&gt;
* '''Single Responsibility Principle (SRP):'''  &lt;br /&gt;
  Each component is focused on a distinct task.  &lt;br /&gt;
* '''DRY (Don't Repeat Yourself):'''  &lt;br /&gt;
  Shared logic is extracted into reusable service methods.  &lt;br /&gt;
* '''Maintainability and Testability:'''  &lt;br /&gt;
  A modular design makes future updates and testing easier.  &lt;br /&gt;
* '''Use of Constants:'''  &lt;br /&gt;
  Magic strings are replaced with named constants for clarity.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163145</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163145"/>
		<updated>2025-04-04T00:15:39Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Architectural Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A `StudentReviewController` that handles only HTTP responsibilities.&lt;br /&gt;
* A new `StudentReviewService` that encapsulates all business logic.&lt;br /&gt;
* Continued use of models like `AssignmentParticipant`, `Assignment`, and `ReviewResponseMap` (excluding `MetareviewResponseMap`).&lt;br /&gt;
* Views adjusted to work with service-driven data.&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163144</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163144"/>
		<updated>2025-04-04T00:11:42Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Implementation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A '''lean controller''' focused on HTTP handling (params, redirects, view data)&lt;br /&gt;
* A new `StudentReviewService` class that performs all data retrieval and computation&lt;br /&gt;
* Simplified views that rely on pre-prepared instance variables&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
==Implementation ==&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163143</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163143"/>
		<updated>2025-04-04T00:11:18Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Controller Diagram */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A '''lean controller''' focused on HTTP handling (params, redirects, view data)&lt;br /&gt;
* A new `StudentReviewService` class that performs all data retrieval and computation&lt;br /&gt;
* Simplified views that rely on pre-prepared instance variables&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
===Implementation===&lt;br /&gt;
To be added after reimplementation and testing are complete.&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163142</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163142"/>
		<updated>2025-04-04T00:10:44Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Testing Plan */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A '''lean controller''' focused on HTTP handling (params, redirects, view data)&lt;br /&gt;
* A new `StudentReviewService` class that performs all data retrieval and computation&lt;br /&gt;
* Simplified views that rely on pre-prepared instance variables&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
To ensure the integrity of the reimplementation, both the service objects and controller actions should have dedicated tests. It is recommended to generate test skeletons as soon as the methods are in place.&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
* Validate that the service object correctly handles all business logic and returns expected outcomes.  &lt;br /&gt;
* Retrieve the participant using the provided ID.  &lt;br /&gt;
* Load the associated assignment.  &lt;br /&gt;
* Calculate topic ID using the participant’s parent ID and user ID.  &lt;br /&gt;
* Determine the current assignment phase based on the topic ID.  &lt;br /&gt;
* Check for existence of a reviewer.  &lt;br /&gt;
* Load correct review mappings based on reviewer existence.  &lt;br /&gt;
* Sort review mappings correctly for calibrated assignments.  &lt;br /&gt;
* Count total number of review mappings.  &lt;br /&gt;
* Count completed reviews by checking submitted responses.  &lt;br /&gt;
* Calculate number of in-progress reviews.  &lt;br /&gt;
* Load sample reviews for the assignment.  &lt;br /&gt;
* Extract and collect response IDs from sample reviews.  &lt;br /&gt;
* Identify whether bidding is enabled for the assignment.&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing === &lt;br /&gt;
* Verify that the `StudentReviewController` interacts properly with the service object and handles HTTP responses appropriately.&lt;br /&gt;
&lt;br /&gt;
'''Key Test Areas:'''  &lt;br /&gt;
* `action_allowed?` method:&lt;br /&gt;
  * Test both cases: when the user has student privileges and when they do not.&lt;br /&gt;
  * Confirm that `false` is returned when privileges are absent, and that the extra check is done for the `list` action when privileges are present.&lt;br /&gt;
&lt;br /&gt;
* `list` action:&lt;br /&gt;
  * Ensure controller delegates business logic to the service object.&lt;br /&gt;
  * Validate correct setting of instance variables based on service output.&lt;br /&gt;
  * Test redirection to bidding page when bidding is enabled.&lt;br /&gt;
  * Confirm correct behavior when the current user is unauthorized.&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163141</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163141"/>
		<updated>2025-04-04T00:04:48Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Relevant Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A '''lean controller''' focused on HTTP handling (params, redirects, view data)&lt;br /&gt;
* A new `StudentReviewService` class that performs all data retrieval and computation&lt;br /&gt;
* Simplified views that rely on pre-prepared instance variables&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing ===&lt;br /&gt;
* `action_allowed?` with and without student permissions&lt;br /&gt;
* `list` behavior:&lt;br /&gt;
  - Valid participant: sets instance variables from service&lt;br /&gt;
  - Unauthorized user: halts&lt;br /&gt;
  - Bidding enabled: redirects&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb/Original Controller Code]&lt;br /&gt;
* [https://github.com/expertiza/expertiza/tree/main/app/views/student_review/Student Review Views]&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163140</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163140"/>
		<updated>2025-04-04T00:03:27Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Existing Issues */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
==Existing Issues==  &lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method is too long and handles multiple responsibilities: data loading, logic, rendering setup, and redirects.  &lt;br /&gt;
  - Business logic is intertwined with HTTP concerns (e.g., redirection, instance variables).  &lt;br /&gt;
&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Literal strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` are used instead of constants.&lt;br /&gt;
&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - The `MetareviewResponseMap` model is no longer relevant but still referenced.&lt;br /&gt;
&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A '''lean controller''' focused on HTTP handling (params, redirects, view data)&lt;br /&gt;
* A new `StudentReviewService` class that performs all data retrieval and computation&lt;br /&gt;
* Simplified views that rely on pre-prepared instance variables&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing ===&lt;br /&gt;
* `action_allowed?` with and without student permissions&lt;br /&gt;
* `list` behavior:&lt;br /&gt;
  - Valid participant: sets instance variables from service&lt;br /&gt;
  - Unauthorized user: halts&lt;br /&gt;
  - Bidding enabled: redirects&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [Original Controller Code](https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb)&lt;br /&gt;
* [Student Review Views](https://github.com/expertiza/expertiza/tree/main/app/views/student_review)&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163139</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163139"/>
		<updated>2025-04-04T00:00:07Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
== Existing Issues ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method handles data loading, logic, rendering setup, and redirects.&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` should be constants.&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - Logic for `MetareviewResponseMap` remains but is no longer used.&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A '''lean controller''' focused on HTTP handling (params, redirects, view data)&lt;br /&gt;
* A new `StudentReviewService` class that performs all data retrieval and computation&lt;br /&gt;
* Simplified views that rely on pre-prepared instance variables&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing ===&lt;br /&gt;
* `action_allowed?` with and without student permissions&lt;br /&gt;
* `list` behavior:&lt;br /&gt;
  - Valid participant: sets instance variables from service&lt;br /&gt;
  - Unauthorized user: halts&lt;br /&gt;
  - Bidding enabled: redirects&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [Original Controller Code](https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb)&lt;br /&gt;
* [Student Review Views](https://github.com/expertiza/expertiza/tree/main/app/views/student_review)&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163138</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163138"/>
		<updated>2025-04-03T23:59:56Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Requirements */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
Reimplement the `StudentReviewController` and ensure all associated components function correctly. The components involved include:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
== Existing Issues ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method handles data loading, logic, rendering setup, and redirects.&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` should be constants.&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - Logic for `MetareviewResponseMap` remains but is no longer used.&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A '''lean controller''' focused on HTTP handling (params, redirects, view data)&lt;br /&gt;
* A new `StudentReviewService` class that performs all data retrieval and computation&lt;br /&gt;
* Simplified views that rely on pre-prepared instance variables&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing ===&lt;br /&gt;
* `action_allowed?` with and without student permissions&lt;br /&gt;
* `list` behavior:&lt;br /&gt;
  - Valid participant: sets instance variables from service&lt;br /&gt;
  - Unauthorized user: halts&lt;br /&gt;
  - Bidding enabled: redirects&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [Original Controller Code](https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb)&lt;br /&gt;
* [Student Review Views](https://github.com/expertiza/expertiza/tree/main/app/views/student_review)&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163137</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163137"/>
		<updated>2025-04-03T23:58:24Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
== Existing Issues ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method handles data loading, logic, rendering setup, and redirects.&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` should be constants.&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - Logic for `MetareviewResponseMap` remains but is no longer used.&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A '''lean controller''' focused on HTTP handling (params, redirects, view data)&lt;br /&gt;
* A new `StudentReviewService` class that performs all data retrieval and computation&lt;br /&gt;
* Simplified views that rely on pre-prepared instance variables&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing ===&lt;br /&gt;
* `action_allowed?` with and without student permissions&lt;br /&gt;
* `list` behavior:&lt;br /&gt;
  - Valid participant: sets instance variables from service&lt;br /&gt;
  - Unauthorized user: halts&lt;br /&gt;
  - Bidding enabled: redirects&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [Original Controller Code](https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb)&lt;br /&gt;
* [Student Review Views](https://github.com/expertiza/expertiza/tree/main/app/views/student_review)&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163136</id>
		<title>CSC/ECE 517 Spring 2025 - E2524 Reimplement student review controller</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Spring_2025_-_E2524_Reimplement_student_review_controller&amp;diff=163136"/>
		<updated>2025-04-03T23:56:34Z</updated>

		<summary type="html">&lt;p&gt;Evilkom: /* About Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==About Expertiza==&lt;br /&gt;
[http://expertiza.ncsu.edu/ Expertiza] is an open source project based on [http://rubyonrails.org/ Ruby on Rails] framework. Expertiza allows the instructor to create new assignments and customize new or existing assignments. It also allows the instructor to create a list of topics the students can sign up for. Students can form teams in Expertiza to work on various projects and assignments. Students can also peer review other students' submissions. Expertiza supports submission across various document types, including the URLs and wiki pages.&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
The goal of this project is to fully reimplement the `StudentReviewController` and its associated views. The reimplementation will introduce a new service layer, streamline logic, and remove obsolete code (e.g., references to metareviews). The new design prioritizes clarity, modularity, and maintainability.&lt;br /&gt;
&lt;br /&gt;
=== Purpose and Scope ===&lt;br /&gt;
This reimplementation addresses longstanding design issues in the original controller, including overly complex methods, redundant logic, and tight coupling between controller and view layers.&lt;br /&gt;
&lt;br /&gt;
=== Objectives ===&lt;br /&gt;
* Redesign the controller to delegate all business logic to a new service class&lt;br /&gt;
* Eliminate obsolete functionality (e.g., metareviews)&lt;br /&gt;
* Improve testability by enabling unit tests on the service layer&lt;br /&gt;
* Simplify the view templates by preparing data in the controller beforehand&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
=== Controller ===&lt;br /&gt;
[https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb student_review_controller.rb]&lt;br /&gt;
&lt;br /&gt;
=== Views ===&lt;br /&gt;
Located at [https://github.com/expertiza/expertiza/tree/main/app/views/student_review app/views/student_review]:&lt;br /&gt;
* `list.html.erb` – main controller view&lt;br /&gt;
* `_responses.html.erb` – renders each review&lt;br /&gt;
* `_set_dynamic_review.html.erb` – dynamic review form&lt;br /&gt;
* `_set_dynamic_metareview.html.erb` – dynamic metareview form&lt;br /&gt;
&lt;br /&gt;
=== Models Used ===&lt;br /&gt;
* `AssignmentParticipant`&lt;br /&gt;
* `Assignment`&lt;br /&gt;
* `SignedUpTeam`&lt;br /&gt;
* `ReviewResponseMap`&lt;br /&gt;
* `SampleReview`&lt;br /&gt;
* `MetareviewResponseMap` (obsolete – all references to be removed)&lt;br /&gt;
&lt;br /&gt;
== Existing Issues ==&lt;br /&gt;
&lt;br /&gt;
* '''Controller Complexity:'''  &lt;br /&gt;
  - The `list` method handles data loading, logic, rendering setup, and redirects.&lt;br /&gt;
* '''Redundant Logic:'''  &lt;br /&gt;
  - The `action_allowed?` method checks for student privileges multiple times.&lt;br /&gt;
* '''Hard-Coded Values:'''  &lt;br /&gt;
  - Strings like `&amp;quot;list&amp;quot;` and `&amp;quot;submitter&amp;quot;` should be constants.&lt;br /&gt;
* '''Obsolete Code:'''  &lt;br /&gt;
  - Logic for `MetareviewResponseMap` remains but is no longer used.&lt;br /&gt;
* '''Lack of Separation of Concerns:'''  &lt;br /&gt;
  - Controller handles business logic that should reside in service/model layers.&lt;br /&gt;
&lt;br /&gt;
== Design / Proposed Solution ==&lt;br /&gt;
&lt;br /&gt;
=== Architectural Overview ===&lt;br /&gt;
The new design will be based on the following structure:&lt;br /&gt;
* A '''lean controller''' focused on HTTP handling (params, redirects, view data)&lt;br /&gt;
* A new `StudentReviewService` class that performs all data retrieval and computation&lt;br /&gt;
* Simplified views that rely on pre-prepared instance variables&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Controller Responsibilities ===&lt;br /&gt;
* Validate access using a simplified `action_allowed?` method&lt;br /&gt;
* Call `StudentReviewService.new(id, current_user).perform` to gather data&lt;br /&gt;
* Assign service output to instance variables for the view&lt;br /&gt;
* Redirect if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Breakdown of Service Object Responsibilities ===&lt;br /&gt;
* Retrieve `AssignmentParticipant` and associated `Assignment`&lt;br /&gt;
* Calculate `topic_id` using `SignedUpTeam.topic_id`&lt;br /&gt;
* Determine review phase using `assignment.current_stage`&lt;br /&gt;
* Get reviewer via `participant.get_reviewer`&lt;br /&gt;
* Load and (if applicable) sort review mappings (`ReviewResponseMap`)&lt;br /&gt;
* Count completed and in-progress reviews&lt;br /&gt;
* Load sample reviews (`SampleReview`) and extract `response_ids`&lt;br /&gt;
* Check if bidding is enabled&lt;br /&gt;
&lt;br /&gt;
=== Removal of Obsolete Code ===&lt;br /&gt;
* All logic involving `MetareviewResponseMap` will be deleted&lt;br /&gt;
* Related counters for metareview progress will be removed from both controller and views&lt;br /&gt;
&lt;br /&gt;
=== action_allowed? Method ===&lt;br /&gt;
* Eliminate redundant privilege check: `|| current_user_has_student_privileges?`&lt;br /&gt;
* Use constants instead of literal strings (`LIST_ACTION = 'list'`)&lt;br /&gt;
* Restructure logic as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
return false unless current_user_has_student_privileges?&lt;br /&gt;
return are_needed_authorizations_present?(params[:id], SUBMITTER_ROLE) if action_name == LIST_ACTION&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== list Method ===&lt;br /&gt;
The `list` method will be removed and replaced with a simplified call to the service:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def list&lt;br /&gt;
  return unless valid_participant?&lt;br /&gt;
  @data = StudentReviewService.new(params[:id], current_user.id).perform&lt;br /&gt;
  redirect_to bidding_path if @data[:bidding_enabled]&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== View Refactoring Plan ==&lt;br /&gt;
&lt;br /&gt;
* `list.html.erb`: Simplify to only display data passed in from `@data`&lt;br /&gt;
* `_responses.html.erb`: Remove inline logic (e.g., topic ID lookups) and rely on passed-in values&lt;br /&gt;
* `_set_dynamic_*`: May be removed if dynamic review logic is relocated or rewritten&lt;br /&gt;
* View logic for metareviews will be removed&lt;br /&gt;
&lt;br /&gt;
== Testing Plan ==&lt;br /&gt;
&lt;br /&gt;
=== Service Object Testing ===&lt;br /&gt;
Thorough unit tests will be added to validate each responsibility of `StudentReviewService`:&lt;br /&gt;
&lt;br /&gt;
* Participant and assignment lookup&lt;br /&gt;
* Topic ID calculation&lt;br /&gt;
* Reviewer existence&lt;br /&gt;
* Review mapping fetching and sorting&lt;br /&gt;
* Completed/in-progress review counts&lt;br /&gt;
* Sample review loading and ID extraction&lt;br /&gt;
* Bidding check&lt;br /&gt;
&lt;br /&gt;
=== Controller Testing ===&lt;br /&gt;
* `action_allowed?` with and without student permissions&lt;br /&gt;
* `list` behavior:&lt;br /&gt;
  - Valid participant: sets instance variables from service&lt;br /&gt;
  - Unauthorized user: halts&lt;br /&gt;
  - Bidding enabled: redirects&lt;br /&gt;
&lt;br /&gt;
=== View Testing ===&lt;br /&gt;
* Test rendering of `list.html.erb` with full and empty review sets&lt;br /&gt;
* Validate rendering with various review statuses&lt;br /&gt;
* Confirm removal of metareview-related UI elements&lt;br /&gt;
&lt;br /&gt;
== Controller Diagram ==&lt;br /&gt;
To be added once the service class and interface are finalized.&lt;br /&gt;
&lt;br /&gt;
== Team ==&lt;br /&gt;
'''Mentor'''&lt;br /&gt;
* Janice Uwujaren&lt;br /&gt;
&lt;br /&gt;
'''Students'''&lt;br /&gt;
* Kenil Patel (kpatel47)&lt;br /&gt;
* Smit Patel (spatel68)&lt;br /&gt;
* Katerina Vilkomir (evilkom)&lt;br /&gt;
&lt;br /&gt;
== Relevant Links ==&lt;br /&gt;
* [Original Controller Code](https://github.com/expertiza/expertiza/blob/main/app/controllers/student_review_controller.rb)&lt;br /&gt;
* [Student Review Views](https://github.com/expertiza/expertiza/tree/main/app/views/student_review)&lt;br /&gt;
* GitHub Pull Request: (to be added)&lt;/div&gt;</summary>
		<author><name>Evilkom</name></author>
	</entry>
</feed>