Commit f8614ab710d6b425337e4e6bdca33c35f357aeaf
1 parent
f6978895
Exists in
master
and in
79 other branches
Creates constroy_software method in mpog_software_plugin_myprofile_controller.
- Create private methods to use it in mpog_software_plugin_myprofile_controller actions. Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
Showing
1 changed file
with
86 additions
and
87 deletions
Show diff stats
controllers/mpog_software_plugin_myprofile_controller.rb
... | ... | @@ -6,18 +6,14 @@ class MpogSoftwarePluginMyprofileController < MyProfileController |
6 | 6 | |
7 | 7 | def edit_institution |
8 | 8 | @show_sisp_field = environment.admins.include?(current_user.person) |
9 | - @estate_list = NationalRegion.find(:all, :conditions => | |
10 | - { :national_region_type_id => 2 }, | |
11 | - :order=>'name') | |
12 | - | |
9 | + @state_list = NationalRegion.find(:all, :conditions => { :national_region_type_id => 2 }, :order => 'name') | |
13 | 10 | @institution = @profile.institution |
14 | 11 | update_institution if request.post? |
15 | 12 | end |
16 | 13 | |
17 | 14 | def new_software |
18 | - | |
19 | - software_template = Community["software"] | |
20 | - if (!software_template.blank? && software_template.is_template) | |
15 | + software_template = Community['software'] | |
16 | + if !software_template.blank? && software_template.is_template | |
21 | 17 | params["community"]["template_id"] = software_template.id unless params["community"].blank? |
22 | 18 | end |
23 | 19 | |
... | ... | @@ -25,7 +21,7 @@ class MpogSoftwarePluginMyprofileController < MyProfileController |
25 | 21 | @community.environment = environment |
26 | 22 | @software_info = SoftwareInfo.new(params[:software_info]) |
27 | 23 | @license_info = if params[:license_info].nil? |
28 | - LicenseInfo::new | |
24 | + LicenseInfo.new | |
29 | 25 | else |
30 | 26 | LicenseInfo.find(:first, :conditions =>["version = ?","#{params[:license_info][:version]}"]) |
31 | 27 | end |
... | ... | @@ -33,27 +29,9 @@ class MpogSoftwarePluginMyprofileController < MyProfileController |
33 | 29 | valid_models = request.post? && (@community.valid? && @software_info.valid? && @license_info.valid?) |
34 | 30 | |
35 | 31 | if valid_models |
36 | - @software_info = SoftwareInfo.create_after_moderation(user,params[:software_info].merge({:environment => environment,:name => params[:community][:name], :license_info => @license_info})) | |
37 | - unless params[:q].nil? | |
38 | - admins = params[:q].split(/,/).map{|n| environment.people.find n.to_i} | |
39 | - | |
40 | - admins.each do |admin| | |
41 | - @community.add_member(admin) | |
42 | - @community.add_admin(admin) | |
43 | - end | |
44 | - end | |
45 | - if !environment.admins.include?(current_user.person) | |
46 | - session[:notice] = _('Your new software request will be evaluated by an administrator. You will be notified.') | |
47 | - redirect_to user.admin_url | |
48 | - else | |
49 | - redirect_to :controller => 'profile_editor', :action => 'edit', :profile => @community.identifier | |
50 | - end | |
32 | + send_software_to_moderation | |
51 | 33 | else |
52 | - | |
53 | - @errors = [] | |
54 | - @errors |= @community.errors.full_messages | |
55 | - @errors |= @software_info.errors.full_messages | |
56 | - @errors |= @license_info.errors.full_messages | |
34 | + add_software_erros | |
57 | 35 | end |
58 | 36 | end |
59 | 37 | |
... | ... | @@ -64,77 +42,41 @@ class MpogSoftwarePluginMyprofileController < MyProfileController |
64 | 42 | end |
65 | 43 | |
66 | 44 | def edit_software |
67 | - @software_info = @profile.software_info | |
68 | - @list_libraries = @software_info.libraries | |
69 | - @list_databases = @software_info.software_databases | |
70 | - @list_languages = @software_info.software_languages | |
71 | - @list_operating_systems = @software_info.operating_systems | |
72 | - @software_categories = @software_info.software_categories | |
73 | - @software_categories = SoftwareCategories.new if @software_categories.blank? | |
74 | - | |
75 | - @disabled_public_software_field = disabled_public_software_field | |
76 | - | |
77 | - if request.post? | |
78 | - params[:software][:public_software] ||= false | |
79 | - @software_info = @profile.software_info | |
80 | - @license = LicenseInfo.find(params[:license][:license_infos_id]) | |
81 | - @software_info.license_info = @license | |
82 | - @software_info.update_attributes(params[:software]) | |
83 | - | |
84 | - @list_libraries = LibraryHelper.list_libraries(params[:library]) | |
85 | - @list_languages = SoftwareLanguageHelper.list_language(params[:language]) | |
86 | - @list_databases = DatabaseHelper.list_database(params[:database]) | |
87 | - @software_categories = SoftwareCategories::new params[:software_categories] | |
88 | - @list_operating_systems = OperatingSystemHelper.list_operating_system(params[:operating_system]) | |
89 | - @software_info.software_categories = @software_categories unless params[:software_categories].nil? | |
90 | - | |
91 | - software_info_insert_models.call(@list_libraries,'libraries') | |
92 | - | |
93 | - if not @list_languages.nil? | |
94 | - @software_info.software_languages.destroy_all | |
95 | - @list_languages.each do |language| | |
96 | - @software_info.software_languages << language | |
97 | - end | |
98 | - end | |
99 | - | |
100 | - if not @list_databases.nil? | |
101 | - @software_info.software_databases.destroy_all | |
102 | - @list_databases.each do |database| | |
103 | - @software_info.software_databases << database | |
104 | - end | |
105 | - end | |
106 | - | |
107 | - if not @list_operating_systems.nil? | |
108 | - @software_info.operating_systems.destroy_all | |
109 | - @list_operating_systems.each do |operating_system| | |
110 | - @software_info.operating_systems << operating_system | |
111 | - end | |
112 | - end | |
113 | - | |
114 | - begin | |
115 | - @software_info.save! | |
116 | - if params[:commit] == _('Save and Configure Community') | |
117 | - redirect_to :controller => 'profile_editor', :action => 'edit' | |
118 | - else | |
119 | - redirect_to :controller => 'profile_editor', :action => 'index' | |
120 | - end | |
121 | - rescue ActiveRecord::RecordInvalid => invalid | |
45 | + update_software_atributes | |
46 | + | |
47 | + return unless request.post? | |
48 | + constroy_software | |
49 | + software_info_insert_models.call(@list_libraries, 'libraries') | |
50 | + software_info_insert_models.call(@list_languages, 'software_languages') | |
51 | + software_info_insert_models.call(@list_operating_systems, 'operating_systems') | |
52 | + | |
53 | + begin | |
54 | + @software_info.save! | |
55 | + if params[:commit] == _('Save and Configure Community') | |
56 | + redirect_to :controller => 'profile_editor', :action => 'edit' | |
57 | + else | |
58 | + redirect_to :controller => 'profile_editor', :action => 'index' | |
122 | 59 | end |
60 | + rescue ActiveRecord::RecordInvalid => invalid | |
123 | 61 | end |
124 | 62 | end |
125 | 63 | |
126 | - def software_info_insert_models | |
127 | - proc { |list,model_attr| @software_info.send(model_attr).destroy_all; list.collect!{|m| @software_info.send(model_attr) << m } unless list.nil? } | |
128 | - end | |
129 | - | |
130 | 64 | def disabled_public_software_field |
131 | 65 | !environment.admins.include?(current_user.person) |
132 | 66 | end |
133 | 67 | |
134 | 68 | def community_must_be_approved |
135 | 69 | end |
70 | + | |
136 | 71 | private |
137 | 72 | |
73 | + def add_software_erros | |
74 | + @errors = [] | |
75 | + @errors |= @community.errors.full_messages | |
76 | + @errors |= @software_info.errors.full_messages | |
77 | + @errors |= @license_info.errors.full_messages | |
78 | + end | |
79 | + | |
138 | 80 | def update_institution |
139 | 81 | @institution.community.update_attributes(params[:community]) |
140 | 82 | @institution.update_attributes(params[:institutions].except(:governmental_power, :governmental_sphere, :juridical_nature)) |
... | ... | @@ -159,4 +101,61 @@ class MpogSoftwarePluginMyprofileController < MyProfileController |
159 | 101 | @institution.save |
160 | 102 | end |
161 | 103 | |
104 | + def software_info_insert_models | |
105 | + proc { |list,model_attr| | |
106 | + @software_info.send(model_attr).destroy_all | |
107 | + list.collect!{|m| @software_info.send(model_attr) << m } unless list.nil? | |
108 | + } | |
109 | + end | |
110 | + | |
111 | + def constroy_software | |
112 | + params[:software][:public_software] ||= false | |
113 | + @software_info = @profile.software_info | |
114 | + @license = LicenseInfo.find(params[:license][:license_infos_id]) | |
115 | + @software_info.license_info = @license | |
116 | + @software_info.update_attributes(params[:software]) | |
117 | + | |
118 | + @list_libraries = LibraryHelper.list_libraries(params[:library]) | |
119 | + @list_languages = SoftwareLanguageHelper.list_language(params[:language]) | |
120 | + @list_databases = DatabaseHelper.list_database(params[:database]) | |
121 | + @software_categories = SoftwareCategories::new params[:software_categories] | |
122 | + @list_operating_systems = OperatingSystemHelper.list_operating_system(params[:operating_system]) | |
123 | + @software_info.software_categories = @software_categories unless params[:software_categories].nil? | |
124 | + end | |
125 | + | |
126 | + def send_software_to_moderation | |
127 | + @software_info = SoftwareInfo.create_after_moderation(user, | |
128 | + params[:software_info].merge({ | |
129 | + :environment => environment, | |
130 | + :name => params[:community][:name], | |
131 | + :license_info => @license_info })) | |
132 | + unless params[:q].nil? | |
133 | + admins = params[:q].split(/,/).map{ |n| environment.people.find n.to_i } | |
134 | + | |
135 | + admins.each do |admin| | |
136 | + @community.add_member(admin) | |
137 | + @community.add_admin(admin) | |
138 | + end | |
139 | + end | |
140 | + if !environment.admins.include?(current_user.person) | |
141 | + session[:notice] = _('Your new software request will be evaluated by an'\ | |
142 | + 'administrator. You will be notified.') | |
143 | + redirect_to user.admin_url | |
144 | + else | |
145 | + redirect_to :controller => 'profile_editor', | |
146 | + :action => 'edit', | |
147 | + :profile => @community.identifier | |
148 | + end | |
149 | + end | |
150 | + | |
151 | + def update_software_atributes | |
152 | + @software_info = @profile.software_info | |
153 | + @list_libraries = @software_info.libraries | |
154 | + @list_databases = @software_info.software_databases | |
155 | + @list_languages = @software_info.software_languages | |
156 | + @list_operating_systems = @software_info.operating_systems | |
157 | + @software_categories = @software_info.software_categories | |
158 | + @software_categories = SoftwareCategories.new if @software_categories.blank? | |
159 | + @disabled_public_software_field = disabled_public_software_field | |
160 | + end | |
162 | 161 | end | ... | ... |