Commit b899b03b8b05fee8fb32688263b60e604dac3d5c
1 parent
e999d703
Exists in
master
and in
79 other branches
Decrease mpog_software_plugin block complexity.
Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com> Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
1 changed file
with
34 additions
and
23 deletions
Show diff stats
lib/mpog_software_plugin.rb
@@ -71,17 +71,9 @@ class MpogSoftwarePlugin < Noosfero::Plugin | @@ -71,17 +71,9 @@ class MpogSoftwarePlugin < Noosfero::Plugin | ||
71 | end | 71 | end |
72 | 72 | ||
73 | def profile_tabs | 73 | def profile_tabs |
74 | - if context.profile.community? && context.profile.software? | ||
75 | - { :title => _("Software"), | ||
76 | - :id => 'mpog-fields', | ||
77 | - :content => Proc::new do render :partial => 'software_tab' end, | ||
78 | - :start => true } | ||
79 | - elsif context.profile.community? && context.profile.institution? | ||
80 | - { :title => _("Institution"), | ||
81 | - :id => 'mpog-fields', | ||
82 | - :content => Proc::new do render :partial => 'institution_tab' end, | ||
83 | - :start => true | ||
84 | - } | 74 | + if context.profile.community? |
75 | + return profile_tabs_software if context.profile.software? | ||
76 | + profile_tabs_institution | ||
85 | end | 77 | end |
86 | end | 78 | end |
87 | 79 | ||
@@ -396,18 +388,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin | @@ -396,18 +388,7 @@ class MpogSoftwarePlugin < Noosfero::Plugin | ||
396 | end | 388 | end |
397 | end | 389 | end |
398 | 390 | ||
399 | - leave_communities = (old_communities - new_communities) | ||
400 | - enter_communities = (new_communities - old_communities) | ||
401 | - | ||
402 | - leave_communities.each do |community| | ||
403 | - community.remove_member(user.person) | ||
404 | - user.institutions.delete(community.institution) | ||
405 | - end | ||
406 | - | ||
407 | - enter_communities.each do |community| | ||
408 | - community.add_member(user.person) | ||
409 | - user.institutions << community.institution | ||
410 | - end | 391 | + manage_user_institutions(user, leave_communities, enter_communities) |
411 | end | 392 | end |
412 | 393 | ||
413 | def show_sisp_field | 394 | def show_sisp_field |
@@ -457,4 +438,34 @@ class MpogSoftwarePlugin < Noosfero::Plugin | @@ -457,4 +438,34 @@ class MpogSoftwarePlugin < Noosfero::Plugin | ||
457 | } | 438 | } |
458 | } | 439 | } |
459 | end | 440 | end |
441 | + | ||
442 | + def manage_user_institutions(leave_communities,enter_communities) | ||
443 | + leave_communities = (old_communities - new_communities) | ||
444 | + enter_communities = (new_communities - old_communities) | ||
445 | + | ||
446 | + leave_communities.each do |community| | ||
447 | + community.remove_member(user.person) | ||
448 | + user.institutions.delete(community.institution) | ||
449 | + end | ||
450 | + | ||
451 | + enter_communities.each do |community| | ||
452 | + community.add_member(user.person) | ||
453 | + user.institutions << community.institution | ||
454 | + end | ||
455 | + end | ||
456 | + | ||
457 | + def profile_tabs_software | ||
458 | + { :title => _("Software"), | ||
459 | + :id => 'mpog-fields', | ||
460 | + :content => Proc::new do render :partial => 'software_tab' end, | ||
461 | + :start => true } | ||
462 | + end | ||
463 | + | ||
464 | + def profile_tabs_institution | ||
465 | + { :title => _("Institution"), | ||
466 | + :id => 'mpog-fields', | ||
467 | + :content => Proc::new do render :partial => 'institution_tab' end, | ||
468 | + :start => true | ||
469 | + } | ||
470 | + end | ||
460 | end | 471 | end |