<?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=Pgomata</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=Pgomata"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Pgomata"/>
	<updated>2026-05-25T18:17:11Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1551_RGS&amp;diff=98054</id>
		<title>CSC/ECE 517 Fall 2015/oss E1551 RGS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1551_RGS&amp;diff=98054"/>
		<updated>2015-11-01T03:44:22Z</updated>

		<summary type="html">&lt;p&gt;Pgomata: /* Expertiza */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= E1551. Refactoring response_controller.rb =&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
&lt;br /&gt;
'''About Expertiza'''&lt;br /&gt;
Expertiza is an open source project accomplished by NCState students. It was developed in Ruby on Rails. It has general features like forming teams, registering for topics in a project, uploading the final deliveries. After completing the project there is an option for submitting reviews as well and updating the reviews. There is an option for submitting new quizzes as well.&lt;br /&gt;
&lt;br /&gt;
== ResponseController ==&lt;br /&gt;
'''What it does''':  response_controller.rb manages Responses.  A Response is what is generated any time a user fills out a rubric--any rubric.  This includes review rubrics, author-feedback rubrics, teammate-review rubrics, quizzes, and surveys.&lt;br /&gt;
Responses come in versions.  Any time an author revises work, and the reviewer comes back to review it, a new Response object is generated.  This Response object points to a particular ReponseMap, which tells who the reviewer is, which team is the reviewee, and what the reviewed entity is.&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
== Changes ==&lt;br /&gt;
=== Refactor latestResponseVersion method ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:&amp;lt;code&amp;gt;latestResponseVersion&amp;lt;/code&amp;gt; is misnamed.  It returns all versions of a response, and anyway, the method name should use underscores, not camelcase.&lt;br /&gt;
;Solution&lt;br /&gt;
:&lt;br /&gt;
&lt;br /&gt;
=== Rename get_scores ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:&amp;lt;code&amp;gt;get_scores&amp;lt;/code&amp;gt; has a Java-like name.  It should just be &amp;lt;code&amp;gt;scores&amp;lt;/code&amp;gt;.&lt;br /&gt;
'''Solution summary'''&lt;br /&gt;
: The method &amp;lt;code&amp;gt;get_scores&amp;lt;/code&amp;gt; was renamed to &amp;lt;code&amp;gt;scores&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Delete rereview method ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:The 100+-line method &amp;lt;code&amp;gt;rereview&amp;lt;/code&amp;gt; does not seem to be used anymore.  The second-round review can be invoked in the same way as the first-round review.  Remove it.&lt;br /&gt;
;Solution summary&lt;br /&gt;
: The method &amp;lt;code&amp;gt;rereview&amp;lt;/code&amp;gt; was deleted.&lt;br /&gt;
&lt;br /&gt;
=== DRY create and update ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:&amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;update&amp;lt;/code&amp;gt; use completely different code.  Factor the common parts out into a partial, thereby simplifying the methods.&lt;br /&gt;
;Solution summary&lt;br /&gt;
:There was not much actual overlap in these two methods. Minimal changes.&lt;br /&gt;
=== Consistent authorization ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:Authorization needs to be checked in the &amp;lt;code&amp;gt;action_allowed&amp;lt;/code&amp;gt; method instead of in &amp;lt;code&amp;gt;redirect_when_disallowed&amp;lt;/code&amp;gt; at the bottom of the file. &lt;br /&gt;
;Solution summary&lt;br /&gt;
:So the functionality is moved from &amp;lt;code&amp;gt;redirect_when_disallowed&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;action_allowed&amp;lt;/code&amp;gt;. And also it is made sure  that no one other than the author of a review (or another team member, in the case of author feedback) can edit it and then removed the &amp;lt;code&amp;gt;redirect_when_disallowed&amp;lt;/code&amp;gt; method.&lt;br /&gt;
:Code before changing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 def action_allowed?&lt;br /&gt;
    current_user&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 def redirect_when_disallowed(response)&lt;br /&gt;
    # For author feedback, participants need to be able to read feedback submitted by other teammates.&lt;br /&gt;
    # If response is anything but author feedback, only the person who wrote feedback should be able to see it.&lt;br /&gt;
    if response.map.read_attribute(:type) == 'FeedbackResponseMap' &amp;amp;&amp;amp; response.map.assignment.team_assignment?&lt;br /&gt;
      team = response.map.reviewer.team&lt;br /&gt;
      unless team.has_user session[:user]&lt;br /&gt;
        redirect_to '/denied?reason=You are not on the team that wrote this feedback'&lt;br /&gt;
      else&lt;br /&gt;
        return false&lt;br /&gt;
      end&lt;br /&gt;
      response.map.read_attribute(:type)&lt;br /&gt;
    end&lt;br /&gt;
    !current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
: Code after changing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'view','edit','delete','update'&lt;br /&gt;
      response = Response.find(params[:id])&lt;br /&gt;
       if response.map.read_attribute(:type) == 'FeedbackResponseMap' &amp;amp;&amp;amp; response.map.assignment.team_assignment?&lt;br /&gt;
        team = response.map.reviewer.team&lt;br /&gt;
        unless team.has_user session[:user]&lt;br /&gt;
          redirect_to '/denied?reason=You are not on the team that wrote this feedback'&lt;br /&gt;
        else&lt;br /&gt;
          return false&lt;br /&gt;
        end&lt;br /&gt;
        response.map.read_attribute(:type)&lt;br /&gt;
      end&lt;br /&gt;
      current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
    else&lt;br /&gt;
      current_user&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactor get_content ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:&amp;lt;code&amp;gt;get_content&amp;lt;/code&amp;gt; is a complex method. It should be renamed to &amp;lt;code&amp;gt;content&amp;lt;/code&amp;gt; and simplified.  Comments should be added explaining what it does.&lt;br /&gt;
;Solution summary&lt;br /&gt;
:The &amp;lt;code&amp;gt;get_content&amp;lt;/code&amp;gt; method was renamed &amp;lt;code&amp;gt;set_content&amp;lt;/code&amp;gt;, simplified, and documented with comments.&lt;br /&gt;
=== Remove SQL queries ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:This class contains SQL queries.  Please change them to Active Record commands.&lt;br /&gt;
;Solution summary&lt;br /&gt;
:No SQL queries were identified. No changes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Comparison of Original and Refactored Code==&lt;br /&gt;
&lt;br /&gt;
Major refactoring revolved around changing method names according to rails convention, using helper methods for avoiding duplication of code in controller methods.&lt;br /&gt;
&lt;br /&gt;
:Duplications in Code &lt;br /&gt;
::Original duplications : 172&lt;br /&gt;
::Post Refactoring : 21&lt;br /&gt;
&lt;br /&gt;
Code Complexity (Compared on Code Climate) &lt;br /&gt;
&lt;br /&gt;
'''Original ResponseController'''&amp;lt;ref name=&amp;quot;originalresponsecontroller&amp;gt;''Original responseController'' https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Code_climate_response.png]]&lt;br /&gt;
&lt;br /&gt;
'''Refactored Responsecontroller''' &amp;lt;ref name=&amp;quot;Refactoredresponsecontroller&amp;gt;''Refactored responseController'' https://github.com/viswaraavi/expertiza&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Code_climate_expertiza.png]]&lt;br /&gt;
&lt;br /&gt;
== Tests ==&lt;br /&gt;
Some functional tests are written for this class using Rspec and Factorygirls.&lt;br /&gt;
;To check these tests.&lt;br /&gt;
*clone the github repository link provided above &lt;br /&gt;
*run the command rspec spec/controllers/response_controller_spec.rb&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pgomata</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1551_RGS&amp;diff=98010</id>
		<title>CSC/ECE 517 Fall 2015/oss E1551 RGS</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2015/oss_E1551_RGS&amp;diff=98010"/>
		<updated>2015-11-01T02:29:57Z</updated>

		<summary type="html">&lt;p&gt;Pgomata: /* Refactor latestResponseVersion method */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= E1551. Refactoring response_controller.rb =&lt;br /&gt;
== Expertiza ==&lt;br /&gt;
&lt;br /&gt;
'''About Expertiza'''&lt;br /&gt;
&lt;br /&gt;
== ResponseController ==&lt;br /&gt;
'''What it does''':  response_controller.rb manages Responses.  A Response is what is generated any time a user fills out a rubric--any rubric.  This includes review rubrics, author-feedback rubrics, teammate-review rubrics, quizzes, and surveys.&lt;br /&gt;
Responses come in versions.  Any time an author revises work, and the reviewer comes back to review it, a new Response object is generated.  This Response object points to a particular ReponseMap, which tells who the reviewer is, which team is the reviewee, and what the reviewed entity is.&lt;br /&gt;
&lt;br /&gt;
== Project Description ==&lt;br /&gt;
'''What needs to be done:'''&lt;br /&gt;
&lt;br /&gt;
== Changes ==&lt;br /&gt;
=== Refactor latestResponseVersion method ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:&amp;lt;code&amp;gt;latestResponseVersion&amp;lt;/code&amp;gt; is misnamed.  It returns all versions of a response, and anyway, the method name should use underscores, not camelcase.&lt;br /&gt;
;Solution&lt;br /&gt;
:&lt;br /&gt;
&lt;br /&gt;
=== Rename get_scores ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:&amp;lt;code&amp;gt;get_scores&amp;lt;/code&amp;gt; has a Java-like name.  It should just be &amp;lt;code&amp;gt;scores&amp;lt;/code&amp;gt;.&lt;br /&gt;
'''Solution summary'''&lt;br /&gt;
: The method &amp;lt;code&amp;gt;get_scores&amp;lt;/code&amp;gt; was renamed to &amp;lt;code&amp;gt;scores&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Delete rereview method ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:The 100+-line method &amp;lt;code&amp;gt;rereview&amp;lt;/code&amp;gt; does not seem to be used anymore.  The second-round review can be invoked in the same way as the first-round review.  Remove it.&lt;br /&gt;
;Solution summary&lt;br /&gt;
: The method &amp;lt;code&amp;gt;rereview&amp;lt;/code&amp;gt; was deleted.&lt;br /&gt;
&lt;br /&gt;
=== DRY create and update ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:&amp;lt;code&amp;gt;create&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;update&amp;lt;/code&amp;gt; use completely different code.  Factor the common parts out into a partial, thereby simplifying the methods.&lt;br /&gt;
;Solution summary&lt;br /&gt;
:There was not much actual overlap in these two methods. Minimal changes.&lt;br /&gt;
=== Consistent authorization ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:Authorization needs to be checked in the &amp;lt;code&amp;gt;action_allowed&amp;lt;/code&amp;gt; method instead of in &amp;lt;code&amp;gt;redirect_when_disallowed&amp;lt;/code&amp;gt; at the bottom of the file. &lt;br /&gt;
;Solution summary&lt;br /&gt;
:So the functionality is moved from &amp;lt;code&amp;gt;redirect_when_disallowed&amp;lt;/code&amp;gt; to &amp;lt;code&amp;gt;action_allowed&amp;lt;/code&amp;gt;. And also it is made sure  that no one other than the author of a review (or another team member, in the case of author feedback) can edit it and then removed the &amp;lt;code&amp;gt;redirect_when_disallowed&amp;lt;/code&amp;gt; method.&lt;br /&gt;
:Code before changing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 def action_allowed?&lt;br /&gt;
    current_user&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
 def redirect_when_disallowed(response)&lt;br /&gt;
    # For author feedback, participants need to be able to read feedback submitted by other teammates.&lt;br /&gt;
    # If response is anything but author feedback, only the person who wrote feedback should be able to see it.&lt;br /&gt;
    if response.map.read_attribute(:type) == 'FeedbackResponseMap' &amp;amp;&amp;amp; response.map.assignment.team_assignment?&lt;br /&gt;
      team = response.map.reviewer.team&lt;br /&gt;
      unless team.has_user session[:user]&lt;br /&gt;
        redirect_to '/denied?reason=You are not on the team that wrote this feedback'&lt;br /&gt;
      else&lt;br /&gt;
        return false&lt;br /&gt;
      end&lt;br /&gt;
      response.map.read_attribute(:type)&lt;br /&gt;
    end&lt;br /&gt;
    !current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
  end&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
: Code after changing&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;&lt;br /&gt;
 def action_allowed?&lt;br /&gt;
    case params[:action]&lt;br /&gt;
    when 'view','edit','delete','update'&lt;br /&gt;
      response = Response.find(params[:id])&lt;br /&gt;
       if response.map.read_attribute(:type) == 'FeedbackResponseMap' &amp;amp;&amp;amp; response.map.assignment.team_assignment?&lt;br /&gt;
        team = response.map.reviewer.team&lt;br /&gt;
        unless team.has_user session[:user]&lt;br /&gt;
          redirect_to '/denied?reason=You are not on the team that wrote this feedback'&lt;br /&gt;
        else&lt;br /&gt;
          return false&lt;br /&gt;
        end&lt;br /&gt;
        response.map.read_attribute(:type)&lt;br /&gt;
      end&lt;br /&gt;
      current_user_id?(response.map.reviewer.user_id)&lt;br /&gt;
    else&lt;br /&gt;
      current_user&lt;br /&gt;
    end&lt;br /&gt;
  end&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Refactor get_content ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:&amp;lt;code&amp;gt;get_content&amp;lt;/code&amp;gt; is a complex method. It should be renamed to &amp;lt;code&amp;gt;content&amp;lt;/code&amp;gt; and simplified.  Comments should be added explaining what it does.&lt;br /&gt;
;Solution summary&lt;br /&gt;
:The &amp;lt;code&amp;gt;get_content&amp;lt;/code&amp;gt; method was renamed &amp;lt;code&amp;gt;set_content&amp;lt;/code&amp;gt;, simplified, and documented with comments.&lt;br /&gt;
=== Remove SQL queries ===&lt;br /&gt;
;Problem definition&lt;br /&gt;
:This class contains SQL queries.  Please change them to Active Record commands.&lt;br /&gt;
;Solution summary&lt;br /&gt;
:No SQL queries were identified. No changes.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Comparison of Original and Refactored Code==&lt;br /&gt;
&lt;br /&gt;
Major refactoring revolved around changing method names according to rails convention, using helper methods for avoiding duplication of code in controller methods.&lt;br /&gt;
&lt;br /&gt;
:Duplications in Code &lt;br /&gt;
::Original duplications : 172&lt;br /&gt;
::Post Refactoring : 21&lt;br /&gt;
&lt;br /&gt;
Code Complexity (Compared on Code Climate) &lt;br /&gt;
&lt;br /&gt;
'''Original ResponseController'''&amp;lt;ref name=&amp;quot;originalresponsecontroller&amp;gt;''Original responseController'' https://github.com/expertiza/expertiza&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Code_climate_response.png]]&lt;br /&gt;
&lt;br /&gt;
'''Refactored Responsecontroller''' &amp;lt;ref name=&amp;quot;Refactoredresponsecontroller&amp;gt;''Refactored responseController'' https://github.com/viswaraavi/expertiza&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;br/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[File:Code_climate_expertiza.png]]&lt;br /&gt;
&lt;br /&gt;
== Tests ==&lt;br /&gt;
Some functional tests are written for this class.&lt;br /&gt;
==References==&lt;br /&gt;
&amp;lt;references&amp;gt;&lt;/div&gt;</summary>
		<author><name>Pgomata</name></author>
	</entry>
</feed>