Commit 00e189ae667b1842f3fdbccddf8a9ee2f12d3da8
Committed by
Luciano Prestes
1 parent
57138027
Exists in
master
and in
5 other branches
Temporary
Showing
3 changed files
with
99 additions
and
2 deletions
Show diff stats
controllers/mpog_software_plugin_myprofile_controller.rb
| @@ -54,7 +54,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController | @@ -54,7 +54,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController | ||
| 54 | valid_license = (request.post? && @license_info.valid?) | 54 | valid_license = (request.post? && @license_info.valid?) |
| 55 | if valid_software_info && valid_license && valid_community | 55 | if valid_software_info && valid_license && valid_community |
| 56 | @community = Community.create_after_moderation(user, {:environment => environment}.merge(params[:community]), @software_info, @license_info ) | 56 | @community = Community.create_after_moderation(user, {:environment => environment}.merge(params[:community]), @software_info, @license_info ) |
| 57 | - | 57 | + @software_info = SoftwareInfo.create_after_moderation(user,params[:software_info].merge({:environment => environment,:name => params[:community][:name]})) |
| 58 | unless params[:q].nil? | 58 | unless params[:q].nil? |
| 59 | admins = params[:q].split(/,/).map{|n| environment.people.find n.to_i} | 59 | admins = params[:q].split(/,/).map{|n| environment.people.find n.to_i} |
| 60 | 60 |
| @@ -0,0 +1,85 @@ | @@ -0,0 +1,85 @@ | ||
| 1 | +class CreateSoftware < Task | ||
| 2 | + | ||
| 3 | + validates_presence_of :requestor_id, :target_id | ||
| 4 | + validates_presence_of :name | ||
| 5 | + | ||
| 6 | + attr_accessible :name, :finality, :repository_link, :requestor, :environment | ||
| 7 | + | ||
| 8 | + alias :environment :target | ||
| 9 | + alias :environment= :target= | ||
| 10 | + | ||
| 11 | + DATA_FIELDS = ['name', 'finality', 'license_infos_id', 'repository_link'] | ||
| 12 | + DATA_FIELDS.each do |field| | ||
| 13 | + settings_items field.to_sym | ||
| 14 | + end | ||
| 15 | + | ||
| 16 | + def perform | ||
| 17 | + community = Community.create!(:name => self.name) | ||
| 18 | + | ||
| 19 | + community.environment = self.environment | ||
| 20 | + community.add_admin(self.requestor) | ||
| 21 | + | ||
| 22 | + software = SoftwareInfo.create!(:name => self.name, :finality => self.finality, | ||
| 23 | + :repository_link => self.repository_link, :community => community, | ||
| 24 | + :license_info_id => self.license_info_id) | ||
| 25 | + end | ||
| 26 | + | ||
| 27 | + def title | ||
| 28 | + _("New software") | ||
| 29 | + end | ||
| 30 | + | ||
| 31 | + # def icon | ||
| 32 | + # src = image ? image.public_filename(:minor) : '/images/icons-app/community-minor.png' | ||
| 33 | + # {:type => :defined_image, :src => src, :name => name} | ||
| 34 | + # end | ||
| 35 | + | ||
| 36 | + def subject | ||
| 37 | + name | ||
| 38 | + end | ||
| 39 | + | ||
| 40 | + def information | ||
| 41 | + if finality.blank? | ||
| 42 | + { :message => _('%{requestor} wants to create software %{subject} with no finality.') } | ||
| 43 | + else | ||
| 44 | + { :message => _('%{requestor} wants to create software %{subject} with this finality:<p><em>%{finality}</em></p>'), | ||
| 45 | + :variables => {:finality => finality} } | ||
| 46 | + end | ||
| 47 | + end | ||
| 48 | + | ||
| 49 | + def reject_details | ||
| 50 | + true | ||
| 51 | + end | ||
| 52 | + | ||
| 53 | + # tells if this request was rejected | ||
| 54 | + def rejected? | ||
| 55 | + self.status == Task::Status::CANCELLED | ||
| 56 | + end | ||
| 57 | + | ||
| 58 | + # tells if this request was appoved | ||
| 59 | + def approved? | ||
| 60 | + self.status == Task::Status::FINISHED | ||
| 61 | + end | ||
| 62 | + | ||
| 63 | + def target_notification_description | ||
| 64 | + _('%{requestor} wants to create software %{subject}') % {:requestor => requestor.name, :subject => subject} | ||
| 65 | + end | ||
| 66 | + | ||
| 67 | + def target_notification_message | ||
| 68 | + _("User \"%{user}\" just requested to create software %{software}. You have to approve or reject it through the \"Pending Validations\" section in your control panel.\n") % { :user => self.requestor.name, :software => self.name } | ||
| 69 | + end | ||
| 70 | + | ||
| 71 | + def task_created_message | ||
| 72 | + _("Your request for registering software %{software} at %{environment} was just sent. Environment administrator will receive it and will approve or reject your request according to his methods and creteria. | ||
| 73 | + | ||
| 74 | + You will be notified as soon as environment administrator has a position about your request.") % { :software => self.name, :environment => self.target } | ||
| 75 | + end | ||
| 76 | + | ||
| 77 | + def task_cancelled_message | ||
| 78 | + _("Your request for registering software %{software} at %{environment} was not approved by the environment administrator. The following explanation was given: \n\n%{explanation}") % { :software => self.name, :environment => self.environment, :explanation => self.reject_explanation } | ||
| 79 | + end | ||
| 80 | + | ||
| 81 | + def task_finished_message | ||
| 82 | + _('Your request for registering the software "%{software}" was approved. You can access %{environment} now and start using your new software.') % { :software => self.name, :environment => self.environment } | ||
| 83 | + end | ||
| 84 | + | ||
| 85 | +end |
lib/software_info.rb
| 1 | class SoftwareInfo < ActiveRecord::Base | 1 | class SoftwareInfo < ActiveRecord::Base |
| 2 | - attr_accessible :e_mag, :icp_brasil, :intern, :e_ping, :e_arq, :operating_platform, :demonstration_url, :acronym, :objectives, :features, :license_infos_id, :community_id, :finality, :repository_link, :public_software, :first_edit | 2 | + attr_accessible :e_mag, :icp_brasil, :intern, :e_ping, :e_arq, :operating_platform |
| 3 | + attr_accessible :demonstration_url, :acronym, :objectives, :features, :license_infos_id | ||
| 4 | + attr_accessible :community_id, :finality, :repository_link, :public_software, :first_edit | ||
| 3 | 5 | ||
| 4 | has_many :libraries, :dependent => :destroy | 6 | has_many :libraries, :dependent => :destroy |
| 5 | has_many :software_databases | 7 | has_many :software_databases |
| @@ -54,6 +56,16 @@ class SoftwareInfo < ActiveRecord::Base | @@ -54,6 +56,16 @@ class SoftwareInfo < ActiveRecord::Base | ||
| 54 | true | 56 | true |
| 55 | end | 57 | end |
| 56 | 58 | ||
| 59 | + # if create_after_moderation receive a model object, would be possible to reuse core method | ||
| 60 | + def self.create_after_moderation(requestor, attributes = {}) | ||
| 61 | + environment = attributes.delete(:environment) | ||
| 62 | + name = attributes.delete(:name) | ||
| 63 | + software = SoftwareInfo.new(attributes) | ||
| 64 | + CreateSoftware.create!(attributes.merge(:requestor => requestor, :environment => environment, :name => name)) | ||
| 65 | + end | ||
| 66 | + | ||
| 67 | + | ||
| 68 | + | ||
| 57 | def validate_acronym | 69 | def validate_acronym |
| 58 | self.acronym = "" if self.acronym.nil? | 70 | self.acronym = "" if self.acronym.nil? |
| 59 | if self.acronym.length > 10 && self.errors.messages[:acronym].nil? | 71 | if self.acronym.length > 10 && self.errors.messages[:acronym].nil? |