Commit e4fe298324a5d14a60e2f976a06d9cfea0ce6f5c

Authored by Luciano Prestes
1 parent d759c4ec

Add task for moderate rating comment

Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Signed-off-by: Tallys Martins <tallysmartins@gmail.com>
Signed-off-by: Simião Carvalho <simiaosimis@gmail.com>
plugins/communities_ratings/controllers/communities_ratings_plugin_profile_controller.rb
... ... @@ -47,12 +47,15 @@ class CommunitiesRatingsPluginProfileController &lt; ProfileController
47 47 community_rating.value = params[:community_rating_value] if params[:community_rating_value]
48 48  
49 49 if params[:comments] and (not params[:comments][:body].empty?)
50   - comment = Comment.new(params[:comments])
51   - comment.author = community_rating.person
52   - comment.community = community_rating.community
53   - comment.save
54 50  
55   - community_rating.comment = comment
  51 + create_comment = CreateCommunityRatingComment.create!(
  52 + params[:comments].merge(
  53 + :requestor => community_rating.person,
  54 + :source => community_rating.community,
  55 + :community_rating => community_rating,
  56 + :environment => environment
  57 + )
  58 + )
56 59 end
57 60  
58 61 if community_rating.save
... ...
plugins/communities_ratings/db/migrate/20150806192933_create_community_rating_comment_task.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +class CreateCommunityRatingCommentTask < ActiveRecord::Migration
  2 + def up
  3 + change_table :tasks do |t|
  4 + t.belongs_to :community_rating
  5 + t.belongs_to :source, :foreign_key => :source_id
  6 + end
  7 + end
  8 +
  9 + def down
  10 + remove_column :tasks, :community_ratings_id
  11 + remove_column :tasks, :source_id
  12 + end
  13 +end
... ...
plugins/communities_ratings/lib/create_community_rating_comment.rb 0 → 100644
... ... @@ -0,0 +1,97 @@
  1 +class CreateCommunityRatingComment < Task
  2 + include Rails.application.routes.url_helpers
  3 +
  4 + validates_presence_of :requestor_id, :community_rating, :target_id
  5 +
  6 + attr_accessible :community_rating, :source, :body, :requestor, :reject_explanation, :environment
  7 + belongs_to :source, :class_name => 'Community', :foreign_key => :source_id
  8 + belongs_to :community_rating
  9 +
  10 + alias :environment :target
  11 + alias :environment= :target=
  12 +
  13 + DATA_FIELDS = ['body']
  14 + DATA_FIELDS.each do |field|
  15 + settings_items field.to_sym
  16 + end
  17 +
  18 +
  19 + def perform
  20 + comment = Comment.create!(:source => self.source, :body => self.body, :author => self.requestor)
  21 +
  22 + self.community_rating.comment = comment
  23 + self.community_rating.save!
  24 + end
  25 +
  26 + def title
  27 + _("New Comment")
  28 + end
  29 +
  30 + def information
  31 + message = _("%{requestor} wants to create a comment in the \"%{source}\" community. \n\n\n Comment: \n\n \"%{body}\"") %
  32 + {:requestor => self.requestor.name, :source => self.source.name, :body => self.body }
  33 +
  34 + {:message => message}
  35 + end
  36 +
  37 + def reject_details
  38 + true
  39 + end
  40 +
  41 + # tells if this request was rejected
  42 + def rejected?
  43 + self.status == Task::Status::CANCELLED
  44 + end
  45 +
  46 + # tells if this request was appoved
  47 + def approved?
  48 + self.status == Task::Status::FINISHED
  49 + end
  50 +
  51 + def target_notification_description
  52 + _('%{requestor} wants to create a comment in the \"%{source}\" community') %
  53 + {:requestor => self.requestor.name, :source => self.source.name }
  54 + end
  55 +
  56 + def target_notification_message
  57 + _("User \"%{user}\" just requested to create a comment in the \"%{source}\" community.
  58 + You have to approve or reject it through the \"Pending Validations\"
  59 + section in your control panel.\n") %
  60 + { :user => self.requestor.name, :source => self.source.name }
  61 + end
  62 +
  63 + def task_created_message
  64 +
  65 + _("Your request for commenting at %{source} was
  66 + just sent. Environment administrator will receive it and will approve or
  67 + reject your request according to his methods and criteria.
  68 +
  69 + You will be notified as soon as environment administrator has a position
  70 + about your request.") %
  71 + { :source => self.source.name }
  72 + end
  73 +
  74 + def task_cancelled_message
  75 + _("Your request for commenting at %{source} was
  76 + not approved by the environment administrator. The following explanation
  77 + was given: \n\n%{explanation}") %
  78 + { :source => self.source.name,
  79 + :explanation => self.reject_explanation }
  80 + end
  81 +
  82 + def task_finished_message
  83 + _('Your request for commenting was approved.
  84 + You can access %{url} to see your comment.') %
  85 + { :url => mount_url }
  86 + end
  87 +
  88 + private
  89 +
  90 + def mount_url
  91 + identifier = self.source.identifier
  92 + # The use of url_for doesn't allow the /social within the Public Software
  93 + # portal. That's why the url is mounted so 'hard coded'
  94 + url = "#{environment.top_url}/profile/#{identifier}"
  95 + end
  96 +
  97 +end
... ...