Commit 6163bab51cfd369e30c85d8c21ae7fd8bff1d561

Authored by David Silva
1 parent b899b03b
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

Alter mpog_software_plugin based on robocop.

Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
Showing 1 changed file with 103 additions and 99 deletions   Show diff stats
lib/mpog_software_plugin.rb
... ... @@ -11,18 +11,18 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
11 11 include Rails.application.routes.url_helpers
12 12  
13 13 def self.plugin_name
14   - "MpogSoftwarePlugin"
  14 + 'MpogSoftwarePlugin'
15 15 end
16 16  
17 17 def self.plugin_description
18   - _("Add Public Software and MPOG features.")
  18 + _('Add Public Software and MPOG features.')
19 19 end
20 20  
21 21 def profile_editor_extras
22 22 if context.profile.person?
23 23 expanded_template('person_editor_extras.html.erb')
24 24 elsif context.profile.respond_to?(:software_info) &&
25   - !context.profile.software_info.nil?
  25 + !context.profile.software_info.nil?
26 26  
27 27 if context.profile.software_info.first_edit?
28 28 context.profile.software_info.first_edit = false
... ... @@ -33,16 +33,17 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
33 33 end
34 34  
35 35 def profile_editor_transaction_extras
36   - single_hash_transactions = {:user => "user", :software_info => "software_info",
37   - :version => "license", :language => "language",
38   - :operating_system => "operating_system",
39   - :software_categories => "software_categories",
40   - :instituton => "instituton", :library => "libraries"}
41   -
42   - single_hash_transactions.each do |model,transaction|
43   - call_model_transaction(model,transaction)
44   - end
45   -
  36 + single_hash_transactions = { :user => 'user',
  37 + :software_info => 'software_info',
  38 + :version => 'license', :language => 'language',
  39 + :operating_system => 'operating_system',
  40 + :software_categories => 'software_categories',
  41 + :instituton => 'instituton',
  42 + :library => 'libraries' }
  43 +
  44 + single_hash_transactions.each do |model, transaction|
  45 + call_model_transaction(model, transaction)
  46 + end
46 47 end
47 48  
48 49 def profile_editor_controller_filters
... ... @@ -63,8 +64,8 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
63 64 end
64 65  
65 66 [{
66   - :type => "before_filter",
67   - :method_name => "validate_institution_sisp_field_access",
  67 + :type => 'before_filter',
  68 + :method_name => 'validate_institution_sisp_field_access',
68 69 :options => { :only => :edit },
69 70 :block => block
70 71 }]
... ... @@ -72,7 +73,7 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
72 73  
73 74 def profile_tabs
74 75 if context.profile.community?
75   - return profile_tabs_software if context.profile.software?
  76 + profile_tabs_software if context.profile.software?
76 77 profile_tabs_institution
77 78 end
78 79 end
... ... @@ -89,14 +90,14 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
89 90  
90 91 def self.extra_blocks
91 92 {
92   - SoftwaresBlock => {:type => [Environment, Person] },
93   - SoftwareInformationBlock => {:type => [Community] },
94   - InstitutionsBlock => {:type => [Environment, Person]},
95   - DownloadBlock => {:type => [Community]},
96   - RepositoryBlock => {:type => [Community]},
97   - CategoriesAndTagsBlock => {:type => [Community]},
98   - CategoriesSoftwareBlock => {:type => [Environment]},
99   - SearchCatalogBlock => {:type => [Environment]}
  93 + SoftwaresBlock => { :type => [Environment, Person] },
  94 + SoftwareInformationBlock => { :type => [Community] },
  95 + InstitutionsBlock => { :type => [Environment, Person] },
  96 + DownloadBlock => { :type => [Community] },
  97 + RepositoryBlock => { :type => [Community] },
  98 + CategoriesAndTagsBlock => { :type => [Community] },
  99 + CategoriesSoftwareBlock => { :type => [Environment] },
  100 + SearchCatalogBlock => { :type => [Environment] }
100 101 }
101 102 end
102 103  
... ... @@ -105,7 +106,7 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
105 106 end
106 107  
107 108 def js_files
108   - %w[
  109 + %w(
109 110 jquery.maskedinput.min.js
110 111 spb-utils.js
111 112 mpog-software.js
... ... @@ -116,11 +117,11 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
116 117 mpog-search.js
117 118 software-catalog.js
118 119 mpog-software-block.js
119   - ]
  120 + )
120 121 end
121 122  
122 123 def add_new_organization_buttons
123   - Proc::new do
  124 + proc do
124 125 button(
125 126 :add,
126 127 _('Create a new software'),
... ... @@ -137,34 +138,18 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
137 138  
138 139 def profile_blocks_extra_content
139 140 return if context.session[:user].nil? ||
140   - !context.session[:hide_incomplete_percentage].blank?
141   -
142   - person = Person.where(:user_id=>context.session[:user]).first
143   -
144   - if context.profile && context.profile.person? && !person.nil?
145   - @person = person
146   - @percentege = calc_percentage_registration(person)
  141 + !context.session[:hide_incomplete_percentage].blank?
147 142  
148   - if @percentege >= 0 && @percentege <= 100
149   - expanded_template('incomplete_registration.html.erb')
150   - end
151   - end
  143 + person = Person.where(:user_id => context.session[:user]).first
  144 + puts "="*80,person,"="*80
  145 + call_percentage_profile_template(person)
152 146 end
153 147  
154   - def custom_user_registration_attributes user
155   - unless context.params[:user][:institution_ids].nil?
156   - context.params[:user][:institution_ids].delete("")
  148 + def custom_user_registration_attributes(user)
  149 + return if context.params[:user][:institution_ids].nil?
  150 + context.params[:user][:institution_ids].delete('')
157 151  
158   - context.params[:user][:institution_ids].each do |institution_id|
159   - institution = Institution.find institution_id
160   - user.institutions << institution
161   -
162   - if institution.community.admins.blank?
163   - institution.community.add_admin(user.person)
164   - end
165   - end
166   - end
167   - user.save unless user.institution_ids.empty?
  152 + update_user_institutions(user)
168 153  
169 154 user.institutions.each do |institution|
170 155 community = institution.community
... ... @@ -172,12 +157,12 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
172 157 end
173 158 end
174 159  
175   - def calc_percentage_registration person
  160 + def calc_percentage_registration(person)
176 161 required_list = profile_required_list
177 162 empty_fields = profile_required_empty_list person
178 163 count = required_list[:person_fields].count +
179 164 required_list[:user_fields].count
180   - percentege = 100 - ((empty_fields.count*100)/count)
  165 + percentege = 100 - ((empty_fields.count * 100) / count)
181 166 person.percentage_incomplete = percentege
182 167 person.save(validate: false)
183 168 percentege
... ... @@ -205,36 +190,31 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
205 190 end
206 191  
207 192 def profile_required_list
208   - fields = Hash.new
209   - fields[:person_fields] = [
210   - "cell_phone",
211   - "contact_phone",
212   - "comercial_phone",
213   - "country",
214   - "city",
215   - "state",
216   - "organization_website",
217   - "image",
218   - "identifier",
219   - "name"
220   - ]
221   - fields[:user_fields] = ["secondary_email", "email"]
  193 + fields = {}
  194 + fields[:person_fields] = %w('cell_phone',
  195 + 'contact_phone',
  196 + 'comercial_phone',
  197 + 'country',
  198 + 'city',
  199 + 'state',
  200 + 'organization_website',
  201 + 'image',
  202 + 'identifier',
  203 + 'name')
  204 +
  205 + fields[:user_fields] = %w('secondary_email', 'email')
222 206 fields
223 207 end
224 208  
225   - def profile_required_empty_list person
  209 + def profile_required_empty_list(person)
226 210 empty_fields = []
227 211 required_list = profile_required_list
228 212  
229 213 required_list[:person_fields].each do |field|
230   - if person.send(field).blank?
231   - empty_fields << field.sub("_"," ")
232   - end
  214 + empty_fields << field.sub('_',' ') if person.send(field).blank?
233 215 end
234 216 required_list[:user_fields].each do |field|
235   - if person.user.send(field).blank?
236   - empty_fields << field.sub("_"," ")
237   - end
  217 + empty_fields << field.sub('_',' ') if person.user.send(field).blank?
238 218 end
239 219 empty_fields
240 220 end
... ... @@ -271,7 +251,8 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
271 251 def institution_transaction
272 252 institution.date_modification = DateTime.now
273 253 institution.save
274   - institution_models = %w(governmental_power governmental_sphere juridical_nature)
  254 + institution_models = %w(governmental_power governmental_sphere
  255 + juridical_nature)
275 256  
276 257 institution_models.each do |model|
277 258 call_institution_transaction(model)
... ... @@ -361,10 +342,10 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
361 342  
362 343 def software_categories_transaction
363 344 ControlledVocabulary.transaction do
364   - context.profile.
365   - software_info.
366   - software_categories.
367   - update_attributes!(context.params[:software_categories])
  345 + context.profile
  346 + .software_info
  347 + .software_categories
  348 + .update_attributes!(context.params[:software_categories])
368 349 end
369 350 end
370 351  
... ... @@ -381,7 +362,7 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
381 362  
382 363 new_communities = []
383 364 unless context.params[:user][:institution_ids].nil?
384   - context.params[:user][:institution_ids].delete("")
  365 + context.params[:user][:institution_ids].delete('')
385 366  
386 367 context.params[:user][:institution_ids].each do |id|
387 368 new_communities << Institution.find(id).community
... ... @@ -397,49 +378,49 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
397 378 end
398 379  
399 380 def call_model_transaction(model,name)
400   - send(name + '_transaction') if context.params.has_key?(model.to_sym)
  381 + send(name + '_transaction') if context.params.key?(model.to_sym)
401 382 end
402 383  
403 384 def call_institution_transaction(model)
404   - context.profile.institution.send(model + '_id = ', context.params[model.to_sym])
  385 + context.profile.institution.send(model + '_id = ',
  386 + context.params[model.to_sym])
405 387 context.profile.institution.save!
406 388 end
407 389  
408   -
409 390 def software_info_button
410 391 {
411   - :title => _("Software Info"),
412   - :icon => "edit-profile-group control-panel-software-link",
  392 + :title => _('Software Info'),
  393 + :icon => 'edit-profile-group control-panel-software-link',
413 394 :url => {
414   - :controller => "mpog_software_plugin_myprofile",
415   - :action => "edit_software"
  395 + :controller => 'mpog_software_plugin_myprofile',
  396 + :action => 'edit_software'
416 397 }
417 398 }
418 399 end
419 400  
420 401 def create_new_software_button
421 402 {
422   - :title => _("Create a new software"),
423   - :icon => "design-editor",
  403 + :title => _('Create a new software'),
  404 + :icon => 'design-editor',
424 405 :url => {
425   - :controller => "mpog_software_plugin_myprofile",
426   - :action => "new_software"
  406 + :controller => 'mpog_software_plugin_myprofile',
  407 + :action => 'new_software'
427 408 }
428 409 }
429 410 end
430 411  
431 412 def institution_info_button
432 413 {
433   - :title => _("Institution Info"),
434   - :icon => "edit-profile-group control-panel-instituton-link",
  414 + :title => _('Institution Info'),
  415 + :icon => 'edit-profile-group control-panel-instituton-link',
435 416 :url => {
436   - :controller => "mpog_software_plugin_myprofile",
437   - :action => "edit_institution"
  417 + :controller => 'mpog_software_plugin_myprofile',
  418 + :action => 'edit_institution'
438 419 }
439 420 }
440 421 end
441 422  
442   - def manage_user_institutions(leave_communities,enter_communities)
  423 + def manage_user_institutions(leave_communities, enter_communities)
443 424 leave_communities = (old_communities - new_communities)
444 425 enter_communities = (new_communities - old_communities)
445 426  
... ... @@ -455,17 +436,40 @@ class MpogSoftwarePlugin &lt; Noosfero::Plugin
455 436 end
456 437  
457 438 def profile_tabs_software
458   - { :title => _("Software"),
  439 + { :title => _('Software'),
459 440 :id => 'mpog-fields',
460   - :content => Proc::new do render :partial => 'software_tab' end,
  441 + :content => proc do render :partial => 'software_tab' end,
461 442 :start => true }
462 443 end
463 444  
464 445 def profile_tabs_institution
465   - { :title => _("Institution"),
  446 + { :title => _('Institution'),
466 447 :id => 'mpog-fields',
467 448 :content => Proc::new do render :partial => 'institution_tab' end,
468 449 :start => true
469 450 }
470 451 end
  452 +
  453 + def call_percentage_profile_template(person)
  454 + if context.profile && context.profile.person? && !person.nil?
  455 + @person = person
  456 + @percentege = calc_percentage_registration(person)
  457 +
  458 + if @percentege >= 0 && @percentege <= 100
  459 + expanded_template('incomplete_registration.html.erb')
  460 + end
  461 + end
  462 + end
  463 +
  464 + def update_user_institutions(user)
  465 + context.params[:user][:institution_ids].each do |institution_id|
  466 + institution = Institution.find institution_id
  467 + user.institutions << institution
  468 +
  469 + if institution.community.admins.blank?
  470 + institution.community.add_admin(user.person)
  471 + end
  472 + end
  473 + user.save unless user.institution_ids.empty?
  474 + end
471 475 end
... ...