From 99d17c7988d86aabc3765e3a63b1f1720a9b816f Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Fri, 29 Apr 2011 14:06:08 +0200 Subject: [PATCH] SONAR-2382 Improve the web service 'reviews' - New class Api::Utils to define some shared methods (around ISO datetime, markdown, ...) - Move to_json and to_xml methods to RuleFailure and Review models - Delete the class MarkdownHelper. Method to convert to html is moved to Api::Utils --- .../app/controllers/api/events_controller.rb | 4 +- .../controllers/api/projects_controller.rb | 4 +- .../controllers/api/resources_controller.rb | 24 +++--- .../app/controllers/api/reviews_controller.rb | 9 +-- .../controllers/api/timemachine_controller.rb | 4 +- .../controllers/api/violations_controller.rb | 8 +- .../app/controllers/resource_controller.rb | 2 +- .../app/controllers/reviews_controller.rb | 2 +- .../WEB-INF/app/helpers/markdown_helper.rb | 26 ------- .../WEB-INF/app/helpers/reviews_helper.rb | 65 ---------------- .../webapp/WEB-INF/app/models/api/utils.rb | 44 +++++++++++ .../main/webapp/WEB-INF/app/models/review.rb | 75 +++++++++++++++++-- .../WEB-INF/app/models/review_comment.rb | 14 ++-- .../webapp/WEB-INF/app/models/rule_failure.rb | 30 ++------ .../app/views/resource/_violation.html.erb | 12 +-- .../app/views/reviews/_review.html.erb | 4 +- 16 files changed, 164 insertions(+), 163 deletions(-) delete mode 100644 sonar-server/src/main/webapp/WEB-INF/app/helpers/markdown_helper.rb create mode 100644 sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb index e22c280a179..afc773baa48 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/events_controller.rb @@ -206,7 +206,7 @@ class Api::EventsController < Api::ApiController hash[:rk]=event.resource.key if event.resource hash[:n]=event.name if event.name hash[:c]=event.category - hash[:dt]=format_datetime(event.event_date) if event.event_date + hash[:dt]=Api::Utils.format_datetime(event.event_date) if event.event_date hash[:ds]=event.description if event.description hash[:data]=event.data if event.data hash @@ -226,7 +226,7 @@ class Api::EventsController < Api::ApiController xml.name(event.name) if event.name xml.resourceKey(event.resource.key) if event.resource xml.category(event.category) - xml.date(format_datetime(event.event_date)) if event.event_date + xml.date(Api::Utils.format_datetime(event.event_date)) if event.event_date xml.description(event.description) if event.description xml.data(event.data) if event.data end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb index e0beb3c8233..ad53b529d7f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/projects_controller.rb @@ -134,7 +134,7 @@ class Api::ProjectsController < Api::ApiController versions={} @snapshots_by_pid[project.id].sort{|s1,s2| s2.version <=> s1.version}.each do |snapshot| version={:sid => snapshot.id.to_s} - version[:d]=format_datetime(snapshot.created_at) if snapshot.created_at + version[:d]=Api::Utils.format_datetime(snapshot.created_at) if snapshot.created_at if snapshot.last? hash[:lv]=snapshot.version end @@ -160,7 +160,7 @@ class Api::ProjectsController < Api::ApiController if @snapshots_by_pid && @snapshots_by_pid[project.id] @snapshots_by_pid[project.id].sort{|s1,s2| s2.version <=> s1.version}.each do |snapshot| attributes={:sid => snapshot.id.to_s, :last => snapshot.last?} - attributes[:date]=format_datetime(snapshot.created_at) if snapshot.created_at + attributes[:date]=Api::Utils.format_datetime(snapshot.created_at) if snapshot.created_at xml.version(snapshot.version, attributes) end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb index a7e01d541d0..dd852589a53 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/resources_controller.rb @@ -305,7 +305,7 @@ class Api::ResourcesController < Api::ApiController 'name' => resource.name, 'scope' => resource.scope, 'qualifier' => resource.qualifier, - 'date' => format_datetime(snapshot.created_at)} + 'date' => Api::Utils.format_datetime(snapshot.created_at)} json['lname']=resource.long_name if resource.long_name json['lang']=resource.language if resource.language json['version']=snapshot.version if snapshot.version @@ -315,23 +315,23 @@ class Api::ResourcesController < Api::ApiController if include_trends json[:p1]=snapshot.period1_mode if snapshot.period1_mode json[:p1p]=snapshot.period1_param if snapshot.period1_param - json[:p1d]=format_datetime(snapshot.period1_date) if snapshot.period1_date + json[:p1d]=Api::Utils.format_datetime(snapshot.period1_date) if snapshot.period1_date json[:p2]=snapshot.period2_mode if snapshot.period2_mode json[:p2p]=snapshot.period2_param if snapshot.period2_param - json[:p2d]=format_datetime(snapshot.period2_date) if snapshot.period2_date + json[:p2d]=Api::Utils.format_datetime(snapshot.period2_date) if snapshot.period2_date json[:p3]=snapshot.period3_mode if snapshot.period3_mode json[:p3p]=snapshot.period3_param if snapshot.period3_param - json[:p3d]=format_datetime(snapshot.period3_date) if snapshot.period3_date + json[:p3d]=Api::Utils.format_datetime(snapshot.period3_date) if snapshot.period3_date json[:p4]=snapshot.period4_mode if snapshot.period4_mode json[:p4p]=snapshot.period4_param if snapshot.period4_param - json[:p4d]=format_datetime(snapshot.period4_date) if snapshot.period4_date + json[:p4d]=Api::Utils.format_datetime(snapshot.period4_date) if snapshot.period4_date json[:p5]=snapshot.period5_mode if snapshot.period5_mode json[:p5p]=snapshot.period5_param if snapshot.period5_param - json[:p5d]=format_datetime(snapshot.period5_date) if snapshot.period5_date + json[:p5d]=Api::Utils.format_datetime(snapshot.period5_date) if snapshot.period5_date end if measures json_measures=[] @@ -395,30 +395,30 @@ class Api::ResourcesController < Api::ApiController xml.qualifier(resource.qualifier) xml.lang(resource.language) if resource.language xml.version(snapshot.version) if snapshot.version - xml.date(format_datetime(snapshot.created_at)) + xml.date(Api::Utils.format_datetime(snapshot.created_at)) xml.description(resource.description) if include_descriptions && resource.description xml.copy(resource.copy_resource_id) if resource.copy_resource_id if include_trends xml.period1(snapshot.period1_mode) if snapshot.period1_mode xml.period1_param(snapshot.period1_param) if snapshot.period1_param - xml.period1_date(format_datetime(snapshot.period1_date)) if snapshot.period1_date + xml.period1_date(Api::Utils.format_datetime(snapshot.period1_date)) if snapshot.period1_date xml.period2(snapshot.period2_mode) if snapshot.period2_mode xml.period2_param(snapshot.period2_param) if snapshot.period2_param - xml.period2_date(format_datetime(snapshot.period2_date)) if snapshot.period2_date + xml.period2_date(Api::Utils.format_datetime(snapshot.period2_date)) if snapshot.period2_date xml.period3(snapshot.period3_mode) if snapshot.period3_mode xml.period3_param(snapshot.period3_param) if snapshot.period3_param - xml.period3_date(format_datetime(snapshot.period3_date)) if snapshot.period3_date + xml.period3_date(Api::Utils.format_datetime(snapshot.period3_date)) if snapshot.period3_date xml.period4(snapshot.period4_mode) if snapshot.period4_mode xml.period4_param(snapshot.period4_param) if snapshot.period4_param - xml.period4_date(format_datetime(snapshot.period4_date)) if snapshot.period4_date + xml.period4_date(Api::Utils.format_datetime(snapshot.period4_date)) if snapshot.period4_date xml.period5(snapshot.period5_mode) if snapshot.period5_mode xml.period5_param(snapshot.period5_param) if snapshot.period5_param - xml.period5_date(format_datetime(snapshot.period5_date)) if snapshot.period5_date + xml.period5_date(Api::Utils.format_datetime(snapshot.period5_date)) if snapshot.period5_date end if measures diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb index 79b00afb83f..17923826915 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/reviews_controller.rb @@ -18,19 +18,16 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # -require "json" +require 'json' class Api::ReviewsController < Api::ApiController - include MarkdownHelper, ReviewsHelper - def index - convert_markdown=(params[:html]=='true') reviews=Review.search(params) respond_to do |format| - format.json { render :json => jsonp(to_json(reviews, convert_markdown)) } - format.xml {render :xml => to_xml(reviews, convert_markdown)} + format.json { render :json => jsonp(Review.reviews_to_json(reviews)) } + format.xml {render :xml => Review.reviews_to_xml(reviews)} format.text { render :text => text_not_supported } end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/timemachine_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/timemachine_controller.rb index e0e710a3b74..cc2443d4ecc 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/timemachine_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/timemachine_controller.rb @@ -191,7 +191,7 @@ class Api::TimemachineController < Api::ApiController end @sids.each do |snapshot_id| - cell={:d => format_datetime(@dates_by_sid[snapshot_id])} + cell={:d => Api::Utils.format_datetime(@dates_by_sid[snapshot_id])} cell_values=[] cell[:v]=cell_values @@ -216,7 +216,7 @@ class Api::TimemachineController < Api::ApiController end csv << header @sids.each do |snapshot_id| - row=[format_datetime(@dates_by_sid[snapshot_id])] + row=[Api::Utils.format_datetime(@dates_by_sid[snapshot_id])] @metadata.each do |metadata| measure=@measures_by_sid[snapshot_id][metadata.to_id] if measure diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb index f78bc3fefbc..55a8198579a 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/api/violations_controller.rb @@ -18,7 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 # -require "json" +require 'json' class Api::ViolationsController < Api::ResourceRestController @@ -92,15 +92,17 @@ class Api::ViolationsController < Api::ResourceRestController end def rest_to_json(rule_failures) - JSON(rule_failures.collect{|rule_failure| rule_failure.to_hash_json(params['include_review']=="true")}) + include_review=(params['include_review']=='true') + JSON(rule_failures.collect{|rule_failure| rule_failure.to_json(include_review)}) end def rest_to_xml(rule_failures) + include_review=(params['include_review']=='true') xml = Builder::XmlMarkup.new(:indent => 0) xml.instruct! xml.violations do rule_failures.each do |rule_failure| - rule_failure.to_xml(xml, params['include_review']=="true") + rule_failure.to_xml(xml, include_review) end end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb index 8c3def0db68..87384d9fdd5 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/resource_controller.rb @@ -20,7 +20,7 @@ class ResourceController < ApplicationController SECTION=Navigation::SECTION_RESOURCE - helper :dashboard, :markdown + helper :dashboard def index @resource = Project.by_key(params[:id]) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb index 105830de552..ac563f86f08 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/reviews_controller.rb @@ -26,7 +26,7 @@ class ReviewsController < ApplicationController :only => [:assign, :comment_form, :flag_as_false_positive, :violation_assign, :violation_flag_as_false_positive,:violation_save_comment, :violation_delete_comment], :redirect_to => {:action => :error_not_post} - helper ReviewsHelper, MarkdownHelper, SourceHelper + helper SourceHelper def index init_params() diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/markdown_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/markdown_helper.rb deleted file mode 100644 index 0c6aedf79bb..00000000000 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/markdown_helper.rb +++ /dev/null @@ -1,26 +0,0 @@ - # - # Sonar, entreprise quality control tool. - # Copyright (C) 2008-2011 SonarSource - # mailto:contact AT sonarsource DOT com - # - # Sonar is free software; you can redistribute it and/or - # modify it under the terms of the GNU Lesser General Public - # License as published by the Free Software Foundation; either - # version 3 of the License, or (at your option) any later version. - # - # Sonar is distributed in the hope that it will be useful, - # but WITHOUT ANY WARRANTY; without even the implied warranty of - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - # Lesser General Public License for more details. - # - # You should have received a copy of the GNU Lesser General Public - # License along with Sonar; if not, write to the Free Software - # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 - # -module MarkdownHelper - - def markdown_to_html(input) - input ? Java::OrgSonarServerUi::JRubyFacade.markdownToHtml(ERB::Util.html_escape(input)) : '' - end - -end \ No newline at end of file diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/reviews_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/reviews_helper.rb index 41da95a1847..2cf6e97b6ee 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/reviews_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/reviews_helper.rb @@ -23,69 +23,4 @@ module ReviewsHelper Project.find(:all, :select => 'id,name,long_name', :conditions => ['enabled=? AND scope=? AND qualifier IN (?)', true, 'PRJ', ['TRK', 'VW','SVW']], :order => 'name ASC') end - def to_xml(reviews, convert_markdown) - xml = Builder::XmlMarkup.new(:indent => 0) - xml.instruct! - - xml.reviews do - reviews.each do |review| - review_to_xml(xml, review, convert_markdown) - end - end - end - - def review_to_xml(xml, review, html=false) - xml.review do - xml.id(review.id.to_i) - xml.createdAt(format_datetime(review.created_at)) - xml.updatedAt(format_datetime(review.updated_at)) - xml.user(review.user.login) - xml.assignee(review.assignee.login) if review.assignee - xml.title(review.title) - xml.type(review.review_type) - xml.status(review.status) - xml.severity(review.severity) - xml.resource(review.resource.kee) if review.resource - xml.line(review.resource_line) if review.resource_line > 0 - xml.comments do - review.review_comments.each do |comment| - xml.comment do - xml.author(comment.user.login) - xml.updatedAt(format_datetime(comment.updated_at)) - xml.text(html ? markdown_to_html(comment.review_text): comment.review_text) - end - end - end - end - end - - def to_json(reviews, convert_markdown=false) - JSON(reviews.collect{|review| review_to_json(review, convert_markdown)}) - end - - def review_to_json(review, html=false) - json = {} - json['id'] = review.id.to_i - json['createdAt'] = format_datetime(review.created_at) - json['updatedAt'] = format_datetime(review.updated_at) - json['author'] = review.user.login - json['assignee'] = review.assignee.login if review.assignee - json['title'] = review.title if review.title - json['type'] = review.review_type - json['status'] = review.status - json['severity'] = review.severity - json['resource'] = review.resource.kee if review.resource - json['line'] = review.resource_line if review.resource_line > 0 - comments = [] - review.review_comments.each do |comment| - comments << { - 'author' => comment.user.login, - 'updatedAt' => format_datetime(comment.updated_at), - 'text' => (html ? markdown_to_html(comment.review_text): comment.review_text) - } - end - json['comments'] = comments - json - end - end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb new file mode 100644 index 00000000000..2d7ab0cfbfb --- /dev/null +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/api/utils.rb @@ -0,0 +1,44 @@ +# +# Sonar, entreprise quality control tool. +# Copyright (C) 2008-2011 SonarSource +# mailto:contact AT sonarsource DOT com +# +# Sonar is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 3 of the License, or (at your option) any later version. +# +# Sonar is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with Sonar; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02 +# +require 'time' + +class Api::Utils + + # Format dateTime to ISO format + def self.format_datetime(datetime) + datetime.strftime("%Y-%m-%dT%H:%M:%S%z") + end + + def self.parse_datetime(datetime_string, default_is_now=true) + if datetime_string.blank? + return (default_is_now ? Time.now : nil) + end + Time.parse(datetime_string) + end + + def self.is_number?(s) + true if Float(s) rescue false + end + + def self.markdown_to_html(markdown) + markdown ? Java::OrgSonarServerUi::JRubyFacade.markdownToHtml(ERB::Util.html_escape(markdown)) : '' + end + +end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb index 115f4b7b58f..8d0f0359049 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review.rb @@ -108,7 +108,7 @@ class Review < ActiveRecord::Base authors=options['authors'].split(',') if options['authors'] if authors && authors.size>0 && !authors[0].blank? conditions << 'user_id in (:authors)' - unless is_number?(authors[0]) + unless Api::Utils.is_number?(authors[0]) authors=User.logins_to_ids(authors) end values[:authors]=authors @@ -117,7 +117,7 @@ class Review < ActiveRecord::Base assignees=options['assignees'].split(',') if options['assignees'] if assignees && assignees.size>0 && !assignees[0].blank? conditions << 'assignee_id in (:assignees)' - unless is_number?(assignees[0]) + unless Api::Utils.is_number?(assignees[0]) assignees=User.logins_to_ids(assignees) end values[:assignees]=assignees @@ -125,12 +125,77 @@ class Review < ActiveRecord::Base Review.find(:all, :include => [ 'review_comments' ], :order => 'created_at DESC', :conditions => [conditions.join(' AND '), values], :limit => 200) end + + def self.reviews_to_xml(reviews) + xml = Builder::XmlMarkup.new(:indent => 0) + xml.instruct! + xml.reviews do + reviews.each do |review| + review.to_xml(xml) + end + end + end + + def to_xml(xml) + xml.review do + xml.id(id.to_i) + xml.createdAt(Api::Utils.format_datetime(created_at)) + xml.updatedAt(Api::Utils.format_datetime(updated_at)) + xml.user(user.login) + xml.assignee(assignee.login) if assignee + xml.title(title) + xml.type(review_type) + xml.status(status) + xml.severity(severity) + xml.resource(resource.kee) if resource + xml.line(resource_line) if resource_line && resource_line>0 + xml.comments do + review_comments.each do |comment| + xml.comment do + xml.author(comment.user.login) + xml.updatedAt(Api::Utils.format_datetime(comment.updated_at)) + xml.text(comment.html_text) + end + end + end + end + end + + def self.reviews_to_json(reviews) + JSON(reviews.collect{|review| review.to_json()}) + end + + def to_json + json = {} + json['id'] = id.to_i + json['createdAt'] = Api::Utils.format_datetime(created_at) + json['updatedAt'] = Api::Utils.format_datetime(updated_at) + json['author'] = user.login + json['assignee'] = assignee.login if assignee + json['title'] = title if title + json['type'] = review_type + json['status'] = status + json['severity'] = severity + json['resource'] = resource.kee if resource + json['line'] = resource_line if resource_line && resource_line>0 + comments = [] + review_comments.each do |comment| + comments << { + 'author' => comment.user.login, + 'updatedAt' => Api::Utils.format_datetime(comment.updated_at), + 'text' => comment.html_text + } + end + json['comments'] = comments + json + end + + + private - def self.is_number?(s) - true if Float(s) rescue false - end + def assign_project if self.project.nil? && self.resource diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb index fa427eb43a5..214f1afa4f9 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/review_comment.rb @@ -21,14 +21,18 @@ class ReviewComment < ActiveRecord::Base belongs_to :user belongs_to :review validates_presence_of :user => "can't be empty" - validate :comment_should_not_be_empty + validate :comment_should_not_be_blank alias_attribute :text, :review_text - + + def html_text + Api::Utils.markdown_to_html(review_text) + end + private - - def comment_should_not_be_empty - errors.add("Comment", " cannot be empty") if review_text.blank? + + def comment_should_not_be_blank + errors.add("Comment", " cannot be blank") if review_text.blank? end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb index f2685534f5d..9f529d73f80 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/models/rule_failure.rb @@ -20,16 +20,10 @@ class RuleFailure < ActiveRecord::Base - include MarkdownHelper, ReviewsHelper - belongs_to :rule belongs_to :snapshot has_one :review, :primary_key => "permanent_id", :foreign_key => "rule_failure_permanent_id", :order => "created_at" - def false_positive? - switched_off==true - end - # first line of message def title @title||= @@ -43,19 +37,14 @@ class RuleFailure < ActiveRecord::Base end end - # in case to_has_json was used somewhere else before the "include_review" param was introduced - def to_hash_json - to_hash_json(false) - end - - def to_hash_json(include_review=false) + def to_json(include_review=false) json = {} json['message'] = message json['line'] = line if line && line>=1 json['priority'] = Sonar::RulePriority.to_s(failure_level).upcase json['switchedOff']=true if switched_off? if created_at - json['createdAt'] = format_datetime(created_at) + json['createdAt'] = Api::Utils.format_datetime(created_at) end json['rule'] = { :key => rule.key, @@ -68,15 +57,10 @@ class RuleFailure < ActiveRecord::Base :qualifier => snapshot.project.qualifier, :language => snapshot.project.language } - json['review'] = review_to_json(review, true) if review && include_review + json['review'] = review.to_json if include_review && review json end - # in case to_xml was used somewhere else before the "include_review" param was introduced - def to_xml(xml) - to_xml(xml, false) - end - def to_xml(xml=Builder::XmlMarkup.new(:indent => 0), include_review=false) xml.violation do xml.message(message) @@ -84,7 +68,7 @@ class RuleFailure < ActiveRecord::Base xml.priority(Sonar::RulePriority.to_s(failure_level)) xml.switchedOff(true) if switched_off? if created_at - xml.createdAt(format_datetime(created_at)) + xml.createdAt(Api::Utils.format_datetime(created_at)) end xml.rule do xml.key(rule.key) @@ -97,14 +81,10 @@ class RuleFailure < ActiveRecord::Base xml.qualifier(snapshot.project.qualifier) xml.language(snapshot.project.language) end - review_to_xml(xml, review, true) if review && include_review + review.to_xml(xml) if include_review && review end end - def format_datetime(datetime) - datetime.strftime("%Y-%m-%dT%H:%M:%S%z") - end - def build_review(options={}) if review.nil? self.review=Review.new( diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb index bd4e5c8e920..71065ec421f 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/resource/_violation.html.erb @@ -19,7 +19,7 @@ <%= distance_of_time_in_words_to_now(violation.created_at) -%>   <% end %> - <% if violation.false_positive? %> + <% if violation.switched_off? %> <%= image_tag("sep12.png") -%>   False-Positive @@ -37,7 +37,7 @@ <%= image_tag("sep12.png") -%> <% if violation.review - unless violation.false_positive? + unless violation.switched_off? %>   <%= link_to_remote (violation.review && violation.review.assignee_id ? "Reassign" : "Assign"), @@ -56,8 +56,8 @@ <% end %>   - <%= link_to_remote (violation.false_positive? ? "Unflag as false-positive" : "Flag as false-positive"), - :url => { :controller => "reviews", :action => "violation_false_positive_form", :id => violation.id, :false_positive => !violation.false_positive? }, + <%= link_to_remote (violation.switched_off? ? "Unflag as false-positive" : "Flag as false-positive"), + :url => { :controller => "reviews", :action => "violation_false_positive_form", :id => violation.id, :false_positive => !violation.switched_off? }, :update => "reviewForm" + violation.id.to_s, :complete => "$('vActions" + violation.id.to_s + "').hide();$('reviewForm" + violation.id.to_s + "').show();$('commentText" + violation.id.to_s + "').focus();" -%> @@ -109,10 +109,10 @@ <% if is_last_comment %>
- <%= markdown_to_html(review_comment.text) -%> + <%= review_comment.html_text -%>
<% else %> - <%= markdown_to_html(review_comment.text) -%> + <%= review_comment.html_text -%> <% end %> <% diff --git a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb index ef40b132d6c..9b69baadc63 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb +++ b/sonar-server/src/main/webapp/WEB-INF/app/views/reviews/_review.html.erb @@ -127,10 +127,10 @@ <% if is_last_comment %>
- <%= markdown_to_html(comment.text) -%> + <%= comment.html_text -%>
<% else %> - <%= markdown_to_html(comment.text) -%> + <%= comment.html_text -%> <% end %> <% end %> -- 2.39.5