Commit 28ca885dad773b1a6958da49658351340ede5b4b
Committed by
Thiago Ribeiro
1 parent
babb6d68
Exists in
refactor_software_info_365
Refactor software creation control
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com> Signed-off-by: Marcos Ronaldo <marcos.rpj2@gmail.com>
Showing
1 changed file
with
16 additions
and
23 deletions
Show diff stats
controllers/software_communities_plugin_myprofile_controller.rb
... | ... | @@ -9,19 +9,16 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController |
9 | 9 | |
10 | 10 | @community = Community.new(params[:community]) |
11 | 11 | @community.environment = environment |
12 | - @software_info = SoftwareInfo.new(params[:software_info]) | |
13 | 12 | |
14 | - @license_info = if params[:license].blank? or params[:license][:license_infos_id].blank? | |
15 | - LicenseInfo.new | |
16 | - else | |
17 | - LicenseInfo.find(params[:license][:license_infos_id]) | |
18 | - end | |
13 | + @license_info = LicenseInfo.find_by_id(params[:license][:license_infos_id]) if params[:license] | |
14 | + @license_info ||= LicenseInfo.new | |
19 | 15 | |
16 | + @software_info = SoftwareInfo.new(params[:software_info]) | |
20 | 17 | @software_info.community = @community |
21 | 18 | @software_info.license_info = @license_info |
22 | 19 | |
23 | 20 | control_software_creation |
24 | - update_new_software_errors | |
21 | + update_software_highlight_errors | |
25 | 22 | end |
26 | 23 | |
27 | 24 | def edit_software |
... | ... | @@ -48,7 +45,7 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController |
48 | 45 | session[:notice] = _('Software updated successfully') |
49 | 46 | end |
50 | 47 | rescue ActiveRecord::RecordInvalid => invalid |
51 | - update_new_software_errors | |
48 | + update_software_highlight_errors | |
52 | 49 | session[:notice] = _('Could not update software') |
53 | 50 | end |
54 | 51 | end |
... | ... | @@ -71,11 +68,15 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController |
71 | 68 | end |
72 | 69 | |
73 | 70 | def control_software_creation |
74 | - valid_models = request.post? && (@community.valid? && @software_info.valid? && @license_info.valid?) | |
75 | - if valid_models | |
76 | - send_software_to_moderation | |
77 | - else | |
78 | - add_software_erros | |
71 | + if request.post? | |
72 | + valid_models = @community.valid? | |
73 | + valid_models &= @software_info.valid? | |
74 | + valid_models &= @license_info.valid? | |
75 | + if valid_models | |
76 | + send_software_to_moderation | |
77 | + else | |
78 | + add_software_erros | |
79 | + end | |
79 | 80 | end |
80 | 81 | end |
81 | 82 | |
... | ... | @@ -133,7 +134,7 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController |
133 | 134 | |
134 | 135 | add_admin_to_community |
135 | 136 | |
136 | - if !environment.admins.include?(current_user.person) | |
137 | + if !environment.admins.include?(current_user.person) | |
137 | 138 | session[:notice] = _('Your new software request will be evaluated by an'\ |
138 | 139 | 'administrator. You will be notified.') |
139 | 140 | redirect_to user.admin_url |
... | ... | @@ -183,15 +184,7 @@ class SoftwareCommunitiesPluginMyprofileController < MyProfileController |
183 | 184 | end |
184 | 185 | end |
185 | 186 | |
186 | - def update_new_software_errors | |
187 | - if request.post? | |
188 | - @community.valid? if @community | |
189 | - @software_info.valid? if @software_info | |
190 | - @license_info.valid? if @license_info | |
191 | - add_software_erros | |
192 | - end | |
193 | - | |
194 | - | |
187 | + def update_software_highlight_errors | |
195 | 188 | @error_community_name = @community.errors.include?(:name) ? "highlight-error" : "" if @community |
196 | 189 | @error_software_acronym = @software_info.errors.include?(:acronym) ? "highlight-error" : "" if @software_info |
197 | 190 | @error_software_domain = @community.errors.include?(:identifier) ? "highlight-error" : "" if @community | ... | ... |