reviews.status.CLOSED=Closed
reviews.resolution.FALSE-POSITIVE=False-positive
reviews.resolution.FIXED=Fixed
-reviews.link_to_action_plan=Action plan
+reviews.link_to_action_plan=Plan
reviews.action_plan_label=Action plan
-reviews.action_plan_submit=Link to action plan
+reviews.action_plan_submit=Plan
+reviews.unlink_action_plan_submit=Unlink
reviews.no_action_plan=None
reviews.planned_for_x=Planned for {0}
reviews.planned_for_label=Planned for
+reviews.an_action_plan_must_be_created_first=An action plan should be first created to plan the remediation effort of this violation.
#------------------------------------------------------------------------------
action_plans.confirm_delete=Delete this action plan? Associated reviews will not be deleted.
action_plans.confirm_close=Close this action plan? There are still open reviews linked to it.
action_plans.create_new_action_plan=Create a new action plan
+action_plans.create_action_plan=Create action plan
+action_plans.edit_action_plan=Edit action plan
+action_plans.same_name_in_same_project=An action plan with this name already exists in this project.
action_plans.date_format_help=The date should be entered using the following pattern: 'day/month/year'. For instance, '31/12/2011'.
action_plans.date_not_valid=Date not valid
action_plans.date_cant_be_in_past=The dead-line can't be in the past
verify :method => :post, :only => [:save, :delete, :change_status], :redirect_to => {:action => :index}
def index
- @action_plans = ActionPlan.find(:all, :conditions => ['project_id=?', @resource.id], :include => 'reviews', :order => 'dead_line ASC')
+ load_action_plans()
end
- def new
- if params[:name] || params[:description] || params[:dead_line]
- @action_plan = ActionPlan.new
- elsif params[:plan_id]
- @action_plan = ActionPlan.find params[:plan_id]
- end
+ def edit
+ @action_plan = ActionPlan.find params[:plan_id]
+ load_action_plans()
+ render 'index'
end
def save
@action_plan.description = params[:description]
unless params[:dead_line].blank?
begin
- dead_line = Date.strptime(params[:dead_line], '%d/%m/%Y')
+ dead_line = DateTime.strptime(params[:dead_line], '%d/%m/%Y')
if dead_line.past?
date_not_valid = message('action_plans.date_cant_be_in_past')
else
end
if date_not_valid || !@action_plan.valid?
- @action_plan.errors.add :dead_line, date_not_valid if date_not_valid
- render :action => :new, :id => @resource.id
+ @action_plan.errors.add :base, date_not_valid if date_not_valid
+ flash[:error] = @action_plan.errors.full_messages.join('<br/>')
+ load_action_plans()
+ render 'index'
else
@action_plan.save
redirect_to :action => 'index', :id => @resource.id
return redirect_to home_path unless @resource
access_denied unless has_role?(:admin, @resource)
end
+
+ def load_action_plans
+ @action_plans = ActionPlan.find(:all, :conditions => ['project_id=?', @resource.id], :include => 'reviews', :order => 'dead_line ASC')
+ end
end
@global_violations=[]
@expandable=(@lines!=nil)
@filtered=!@expanded
+ @action_plans_size=ActionPlan.open_by_project_id(@snapshot.root_project_id).size
conditions='snapshot_id=?'
values=[@snapshot.id]
verify :method => :post,
:only => [:assign, :flag_as_false_positive, :save_comment, :delete_comment, :change_status,
- :link_to_action_plan,
+ :link_to_action_plan, :unlink_from_action_plan,
:violation_assign, :violation_flag_as_false_positive, :violation_change_severity,
:violation_save_comment, :violation_delete_comment, :violation_change_status,
- :violation_link_to_action_plan],
+ :violation_link_to_action_plan, :violation_unlink_from_action_plan],
:redirect_to => {:action => :error_not_post}
helper SourceHelper, UsersHelper
render :partial => "reviews/review"
end
+
+ # POST
+ def unlink_from_action_plan
+ @review = Review.find(params[:id])
+ unless has_rights_to_modify?(@review.project)
+ render :text => "<b>Cannot link to action plan</b> : access denied."
+ return
+ end
+
+ @review.link_to_action_plan(nil, current_user, params)
+
+ render :partial => "reviews/review"
+ end
#
render :partial => "resource/violation", :locals => {:violation => violation}
end
+
+ # POST
+ def violation_unlink_from_action_plan
+ violation = RuleFailure.find(params[:id], :include => 'snapshot')
+ unless has_rights_to_modify?(violation.snapshot)
+ render :text => "<b>Cannot link to action plan</b> : access denied."
+ return
+ end
+ violation.review.link_to_action_plan(nil, current_user, params)
+
+ render :partial => "resource/violation", :locals => {:violation => violation}
+ end
#
belongs_to :project
has_and_belongs_to_many :reviews
- validates_uniqueness_of :name
validates_length_of :name, :within => 1..200
validates_length_of :description, :maximum => 1000, :allow_blank => true, :allow_nil => true
validates_presence_of :user_login, :message => "can't be empty"
validates_presence_of :status, :message => "can't be empty"
validates_presence_of :project, :message => "can't be empty"
+ validate :unique_name_on_same_project
STATUS_OPEN = 'OPEN'
STATUS_CLOSED = 'CLOSED'
def over_due?
dead_line ? status==STATUS_OPEN && dead_line.past? : false
end
+
+ private
+
+ def unique_name_on_same_project
+ action_plan = ActionPlan.find(:first, :conditions => ['project_id=? AND name=?', project_id, name])
+ if action_plan && ( (id && action_plan.id!=id) || !id)
+ errors.add(:base, Api::Utils.message('action_plans.same_name_in_same_project'))
+ end
+ end
end
--- /dev/null
+<table class="admintable" width="100%">
+ <form action="<%= url_for :action => 'save' -%>" method="POST" id="create-action-plan-form">
+ <input type="hidden" name="id" value="<%= @resource.id -%>"/>
+ <input type="hidden" name="plan_id" value="<%= @action_plan.id if @action_plan -%>"/>
+ <tbody>
+ <tr>
+ <td colspan="2"><h1 class="marginbottom10"><%= @action_plan ? message('action_plans.edit_action_plan') : message('action_plans.create_new_action_plan') -%></h1></h1></td>
+ </tr>
+ <tr>
+ <td class="left" valign="top">
+ <%= message('action_plans.col.name') -%>:
+ <br/>
+ <input type="text" name="name" id="name" value="<%= @action_plan ? @action_plan.name : params[:name] -%>"/>
+ </td>
+ </tr>
+ <tr>
+ <td class="left" valign="top">
+ <%= message('action_plans.col.due_for') -%>:
+ <br/>
+ <input type="text" name="dead_line" id="dead_line" value="<%= @action_plan && @action_plan.dead_line ? @action_plan.dead_line.strftime('%d/%m/%Y') : params[:dead_line] -%>"/>
+ <br/>
+ <span class="note"><%= message('action_plans.date_format_help') -%></span>
+ </td>
+ </tr>
+ <tr>
+ <td class="left" valign="top">
+ <%= message('action_plans.col.description') -%>:
+ <br/>
+ <textarea rows="5" cols="80" name="description" id="description" class="width100"><%= @action_plan ? @action_plan.description : params['description'] -%></textarea>
+ </td>
+ </tr>
+ <tr>
+ <td class="left" valign="top">
+ <input type="submit" value="<%= @action_plan ? message('action_plans.edit_action_plan') : message('action_plans.create_action_plan') -%>"/>
+ </td>
+ </tr>
+ </tbody>
+ </form>
+</table>
\ No newline at end of file
unless action_plan.progress[:total]==0
options = {:controller => 'project_reviews', :action => 'index', :action_plan_id => action_plan.id, :projects => action_plan.project_id}
- resolved_reviews_link = link_to action_plan.progress[:resolved].to_s, options.merge({:statuses => "#{Review::STATUS_RESOLVED},#{Review::STATUS_CLOSED}"})
+ resolved_reviews_link = action_plan.progress[:resolved].to_s
+ resolved_reviews_link = link_to action_plan.progress[:resolved].to_s, options.merge({:statuses => "#{Review::STATUS_RESOLVED},#{Review::STATUS_CLOSED}"}) unless action_plan.progress[:resolved]==0
total_reviews_link = link_to action_plan.progress[:total].to_s, options
- resolved_reviews_url = url_for options.merge({:statuses => "#{Review::STATUS_RESOLVED},#{Review::STATUS_CLOSED}"})
- open_reviews_url = url_for options.merge({:statuses => "#{Review::STATUS_OPEN},#{Review::STATUS_REOPENED}"})
+ if action_plan.progress[:resolved] > 0
+ resolved_reviews_url = url_for options.merge({:statuses => "#{Review::STATUS_RESOLVED},#{Review::STATUS_CLOSED}"})
+ percent_resolved = (action_plan.progress[:resolved]*100/action_plan.progress[:total]).to_i
+ tooltip_resolved = message('action_plans.resolved_reviews_x_percent', :params => [percent_resolved.to_s, action_plan.progress[:resolved].to_s])
+ end
- percent_resolved = (action_plan.progress[:resolved]*100/action_plan.progress[:total]).to_i
- percent_open = (action_plan.progress[:open]*100/action_plan.progress[:total]).to_i
-
- tooltip_resolved = message('action_plans.resolved_reviews_x_percent', :params => [percent_resolved.to_s, action_plan.progress[:resolved].to_s])
- tooltip_open = message('action_plans.open_reviews_x_percent', :params => [percent_open.to_s, action_plan.progress[:open].to_s])
+ if action_plan.progress[:open] > 0
+ open_reviews_url = url_for options.merge({:statuses => "#{Review::STATUS_OPEN},#{Review::STATUS_REOPENED}"})
+ percent_open = (action_plan.progress[:open]*100/action_plan.progress[:total]).to_i
+ tooltip_open = message('action_plans.open_reviews_x_percent', :params => [percent_open.to_s, action_plan.progress[:open].to_s])
+ end
%>
<div class="progress">
<table>
<tbody>
<tr>
+ <% if action_plan.progress[:resolved] > 0 %>
<td class="resolved" style="width:<%= percent_resolved -%>%;">
<a href="<%= resolved_reviews_url -%>" title="<%= tooltip_resolved -%>" alt="<%= tooltip_resolved -%>"></a>
</td>
+ <% end %>
+ <% if action_plan.progress[:open] > 0 %>
<td class="open" style="width:<%= percent_open -%>%;">
<a href="<%= open_reviews_url -%>" title="<%= tooltip_open -%>" alt="<%= tooltip_open -%>"></a>
</td>
+ <% end %>
</tr>
</tbody>
</table>
-<div class="line-block marginbottom10">
- <ul class="operations">
- <li class="last">
- <%= image_tag 'add.png' -%>
- <%= link_to message('action_plans.add_action_plan'), {:action => 'new', :id => @resource.id}, {:id => 'addActionPlan'} -%>
- </li>
- </ul>
- <h1><%= message('action_plans.page_title') -%></h1>
-</div>
-
-<table class="width100 data sortable actionPlans" id="actionPlans">
- <thead>
+<table width="100%">
<tr>
- <th class="thin nowrap"><%= message('action_plans.col.status') -%></th>
- <th class="thin nowrap"><%= message('action_plans.col.name') -%></th>
- <th class="thin nowrap righticon" style="text-align: right"><%= message('action_plans.col.due_for') -%></th>
- <th class="nowrap nosort center"><%= message('action_plans.col.progress') -%></th>
- <th class="nowrap"><%= message('action_plans.col.description') -%></th>
- <th class="nowrap"><%= message('action_plans.col.author') -%></th>
- <th class="thin nowrap nosort"><%= message('action_plans.col.operations') -%></th>
- </tr>
- </thead>
- <tbody>
- <% if @action_plans.empty? %>
- <td colspan="7" class="even"><%= message('action_plans.no_action_plan') -%></td>
- <% end %>
- <%
- @action_plans.each do |plan|
- %>
- <tr>
- <td class="thin nowrap center"><img src="<%= ApplicationController.root_context -%>/images/status/<%= plan.status -%>.png" title="<%= message(plan.status.downcase).capitalize -%>"/></td>
- <td class="thin nowrap"><%= h(plan.name) -%></td>
- <td class="thin nowrap <%= 'over-due' if plan.over_due? -%>" align="right" x="<%= plan.dead_line ? plan.dead_line.tv_sec : '' -%>"><%= plan.dead_line ? plan.dead_line.strftime("%d %b %Y") : ' ' -%></td>
- <% if plan.progress[:total]==0 %>
- <td class="noprogress thin nowrap">
- <%= message('action_plans.no_reviews_linked_to_action_plan') -%>
- </td>
- <% else %>
- <td class="progress thin">
- <%= render :partial => 'progress', :locals => {:action_plan => plan} -%>
- </td>
- <% end %>
- <td id="desc"><%= h(plan.description) -%></td>
- <td id="desc"><%= h(plan.user.name) -%></td>
- <td class="thin nowrap">
- <% if plan.open? %>
- <%= link_to message('edit'), {:action => 'new', :id => @resource.id, :plan_id => plan.id}, {:class => 'action'} -%>
+ <td valign="top">
+
+ <h1><%= message('action_plans.page_title') -%></h1>
+
+ <table class="width100 data sortable actionPlans" id="actionPlans">
+ <thead>
+ <tr>
+ <th class="thin nowrap"><%= message('action_plans.col.status') -%></th>
+ <th class="thin nowrap"><%= message('action_plans.col.name') -%></th>
+ <th class="thin nowrap righticon" style="text-align: right"><%= message('action_plans.col.due_for') -%></th>
+ <th class="nowrap nosort center"><%= message('action_plans.col.progress') -%></th>
+ <th class="nowrap"><%= message('action_plans.col.description') -%></th>
+ <th class="nowrap"><%= message('action_plans.col.author') -%></th>
+ <th class="thin nowrap nosort"><%= message('action_plans.col.operations') -%></th>
+ </tr>
+ </thead>
+ <tbody>
+ <% if @action_plans.empty? %>
+ <td colspan="7" class="even"><%= message('action_plans.no_action_plan') -%></td>
<% end %>
- <%
- close_confirmation_message = {}
- if plan.open? && plan.has_open_reviews?
- close_confirmation_message = {:confirm => message('action_plans.confirm_close')}
- end
+ <%
+ @action_plans.each do |plan|
%>
- <%= link_to plan.open? ? message('action_plans.close') : message('action_plans.reopen'),
- {:action => 'change_status', :id => @resource.id, :plan_id => plan.id}, {:method => 'POST', :class => 'action'}.merge(close_confirmation_message) -%>
- <%= link_to message('delete'), {:action => 'delete', :id => @resource.id, :plan_id => plan.id}, {:method => 'POST', :confirm => message('action_plans.confirm_delete'), :class => 'action'} -%>
- </td>
- </tr>
- <% end %>
- </tbody>
+ <tr>
+ <td class="thin nowrap center"><img src="<%= ApplicationController.root_context -%>/images/status/<%= plan.status -%>.png" title="<%= message(plan.status.downcase).capitalize -%>"/></td>
+ <td class="thin nowrap"><%= h(plan.name) -%></td>
+ <td class="thin nowrap <%= 'over-due' if plan.over_due? -%>" align="right" x="<%= plan.dead_line ? plan.dead_line.tv_sec : '' -%>"><%= plan.dead_line ? plan.dead_line.strftime("%d %b %Y") : ' ' -%></td>
+ <% if plan.progress[:total]==0 %>
+ <td class="noprogress thin nowrap">
+ <%= message('action_plans.no_reviews_linked_to_action_plan') -%>
+ </td>
+ <% else %>
+ <td class="progress thin">
+ <%= render :partial => 'progress', :locals => {:action_plan => plan} -%>
+ </td>
+ <% end %>
+ <td id="desc"><%= h(plan.description) -%></td>
+ <td id="desc"><%= h(plan.user.name) -%></td>
+ <td class="thin nowrap right">
+ <% if plan.open? %>
+ <%= link_to message('edit'), :action => 'edit', :id => @resource.id, :plan_id => plan.id, :class => 'action' -%>
+ <% end %>
+ <%
+ close_confirmation_message = {}
+ if plan.open? && plan.has_open_reviews?
+ close_confirmation_message = {:confirm => message('action_plans.confirm_close')}
+ end
+ %>
+ <%= link_to plan.open? ? message('action_plans.close') : message('action_plans.reopen'),
+ {:action => 'change_status', :id => @resource.id, :plan_id => plan.id}, {:method => 'POST', :class => 'action'}.merge(close_confirmation_message) -%>
+ <%= link_to message('delete'), {:action => 'delete', :id => @resource.id, :plan_id => plan.id}, {:method => 'POST', :confirm => message('action_plans.confirm_delete'), :class => 'action'} -%>
+ </td>
+ </tr>
+ <% end %>
+ </tbody>
+ </table>
+ <script>TableKit.Sortable.init('actionPlans');</script>
+
+ </td>
+ <td class="sep"></td>
+ <td width="210" valign="top" align="right">
+ <div id="admin_form">
+ <%= render :partial => 'new' %>
+ </div>
+ </td>
+ </tr>
</table>
-<script>TableKit.Sortable.init('actionPlans');</script>
+++ /dev/null
-<h1 class="marginbottom10"><%= message('action_plans.create_new_action_plan') -%></h1>
-
-<% if @action_plan && @action_plan.errors.on_base
- @action_plan.errors.on_base.each do |error| %>
- <div class="error"><%= error -%></div>
-<% end
- end
-%>
-
-<form action="<%= url_for :action => 'save' -%>" method="POST" id="createForm">
- <input type="hidden" name="id" value="<%= @resource.id -%>"/>
- <input type="hidden" name="plan_id" value="<%= @action_plan.id if @action_plan -%>"/>
- <table class="width100 form">
- <tbody>
- <tr>
- <td class="keyCell">
- <%= message('action_plans.col.name') -%>:
- </td>
- <td>
- <input type="text" name="name" id="name" value="<%= @action_plan ? @action_plan.name : '' -%>"/>
- <% if @action_plan && @action_plan.errors.on('name')
- @action_plan.errors.on('name').each do |error| %>
- <span class="error"><%= error -%></span>
- <% end
- end %>
- </td>
- </tr>
- <tr>
- <td class="keyCell">
- <%= message('action_plans.col.due_for') -%>:
- </td>
- <td>
- <input type="text" name="dead_line" id="dead_line" value="<%= @action_plan && @action_plan.dead_line ? @action_plan.dead_line.strftime('%d/%m/%Y') : params[:dead_line] -%>"/>
- <span class="note"><%= message('action_plans.date_format_help') -%></span>
- <% if @action_plan && @action_plan.errors.on('dead_line')
- @action_plan.errors.on('dead_line').each do |error| %>
- <span class="error"><%= error -%></span>
- <% end
- end %>
- </td>
- </tr>
- <tr>
- <td class="keyCell">
- <%= message('action_plans.col.description') -%>:
- </td>
- <td>
- <textarea rows="5" cols="80" name="description" id="description" class="width100"><%= @action_plan ? @action_plan.description : '' -%></textarea>
- <% if @action_plan && @action_plan.errors.on('description')
- @action_plan.errors.on('description').each do |error| %>
- <span class="error"><%= error -%></span>
- <% end
- end %>
- </td>
- </tr>
- <tr>
- <td class="keyCell">
- </td>
- <td>
- <input type="submit" value="<%= message('save') -%>"/>
- <%= link_to message('cancel'), :action => 'index', :id => @resource.id -%>
- </td>
- </tr>
- </tbody>
- </table>
-</form>
\ No newline at end of file
+<div style="font-size: 85%; margin-bottom: 10px">
+ยป <a href="#" onclick="history.back()"><%= message('back') -%></a>
+</div>
+
<div id="reviews-search">
<h1><%= message('reviews') -%></h1>
<% unless violation.review && violation.review.resolved? %>
<%= button_to_function message('reviews.change_severity'), "sCSF(#{violation.id})", :name => 'bChangeSeverity' -%>
- <%= button_to_function message('reviews.link_to_action_plan'), "sAPF(#{violation.id})", :name => 'bLinkActionPlan' -%>
+ <%
+ @action_plans_size = ActionPlan.open_by_project_id(violation.review.project_id).size unless @action_plans_size
+ if @action_plans_size > 0
+ %>
+ <%= button_to_function message('reviews.link_to_action_plan'), "sAPF(#{violation.id})", :name => 'bLinkActionPlan' -%>
+ <% else %>
+ <input type="button" value="<%= message('reviews.link_to_action_plan') -%>" onclick="alert('<%= message('reviews.an_action_plan_must_be_created_first') -%>');" name="bLinkActionPlan">
+ <% end %>
<% end %>
</div>
<% end %>
<%= message('reviews.action_plan_label') -%>:
<select name="action_plan_id" id="selectActionPlan">
- <option value="-1" <%= 'selected' if !@review.planned? -%>><%= message('reviews.no_action_plan') -%></option>
<% @action_plans.each do |plan| %>
<option value="<%= plan.id -%>" <%= 'selected' if @review.linked_to?(plan) -%>><%= h(plan.name) -%></option>
<% end %>
<textarea id="actionText" rows="4" name="text" style="width: 100%"></textarea>
<%= submit_to_remote "submit_btn", message('reviews.action_plan_submit'), :url => {:action => 'link_to_action_plan'}, :html => {:id => "submit_btn"}, :update => 'review' -%>
+
+ <% if @review.planned? %>
+
+ <%= submit_to_remote "submit_btn", message('reviews.unlink_action_plan_submit'), :url => {:action => 'unlink_from_action_plan'}, :html => {:id => "submit_btn"}, :update => 'review' -%>
+ <% end %>
+
<%= link_to_remote message('cancel'), :url => {:action => 'show', :id => params[:id]}, :update => 'review' -%>
</form>
:update => "actionForm",
:complete => "$('actionButtons').remove();$('actionForm').show();$('selectSeverity').focus();" -%>
- <%= button_to_remote message('reviews.link_to_action_plan'),
+ <% if ActionPlan.open_by_project_id(@review.project_id).size>0 %>
+ <%= button_to_remote message('reviews.link_to_action_plan'),
:url => {:controller => "reviews", :action => "action_plan_form", :id => review.id},
:update => "actionForm",
:complete => "$('actionButtons').remove();$('actionForm').show();$('selectSeverity').focus();" -%>
+ <% else %>
+ <input type="button" value="<%= message('reviews.link_to_action_plan') -%>" onclick="alert('<%= message('reviews.an_action_plan_must_be_created_first') -%>');">
+ <% end %>
<% end %>
</div>
<% end %>
<%= message('reviews.action_plan_label') -%>:
<select name="action_plan_id" id="selectActionPlan<%= params[:id] -%>">
- <option value="-1" <%= 'selected' if !@violation.review || (@violation.review && !@violation.review.planned?) -%>><%= message('reviews.no_action_plan') -%></option>
<% @action_plans.each do |plan| %>
<option value="<%= plan.id -%>" <%= 'selected' if @violation.review && @violation.review.linked_to?(plan) -%>><%= h(plan.name) -%></option>
<% end %>
</table>
<%= submit_to_remote "submit_btn"+params[:id], message('reviews.action_plan_submit'), :url => {:action => 'violation_link_to_action_plan'}, :html => {:id => "submit_btn"+params[:id]}, :update => 'vId'+params[:id] -%>
+
+ <% if @violation.review && @violation.review.planned? %>
+
+ <%= submit_to_remote "submit_btn"+params[:id], message('reviews.unlink_action_plan_submit'), :url => {:action => 'violation_unlink_from_action_plan'}, :html => {:id => "submit_btn"+params[:id]}, :update => 'vId'+params[:id] -%>
+ <% end %>
+
<%= link_to_function message('cancel'), "cancelViolationAction(#{params[:id]})" -%>
</form>