Commit 738808cfbc4e0527a7839143925d1af013df6818
1 parent
0cc53433
Exists in
article_blog_visualization_format
Remove date_format from profile and add it to environment
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
15 changed files
with
79 additions
and
116 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
@@ -188,18 +188,6 @@ class CmsController < MyProfileController | @@ -188,18 +188,6 @@ class CmsController < MyProfileController | ||
188 | render :action => 'edit' | 188 | render :action => 'edit' |
189 | end | 189 | end |
190 | 190 | ||
191 | - def general_configuration | ||
192 | - @profile_data = profile | ||
193 | - if request.post? | ||
194 | - if @profile_data.update_attributes(params[:profile_data]) | ||
195 | - session[:notice] = _("Article date format updated successfully") | ||
196 | - else | ||
197 | - session[:notice] = _("Could not update article's date format") | ||
198 | - end | ||
199 | - redirect_to :action => 'index' | ||
200 | - end | ||
201 | - end | ||
202 | - | ||
203 | post_only :set_home_page | 191 | post_only :set_home_page |
204 | def set_home_page | 192 | def set_home_page |
205 | return render_access_denied unless user.can_change_homepage? | 193 | return render_access_denied unless user.can_change_homepage? |
app/helpers/content_viewer_helper.rb
@@ -37,7 +37,7 @@ module ContentViewerHelper | @@ -37,7 +37,7 @@ module ContentViewerHelper | ||
37 | end | 37 | end |
38 | 38 | ||
39 | def show_with_right_format_date article | 39 | def show_with_right_format_date article |
40 | - date_format = article.profile.date_format | 40 | + date_format = Environment.default.date_format |
41 | use_numbers = false | 41 | use_numbers = false |
42 | year = true | 42 | year = true |
43 | left_time = false | 43 | left_time = false |
app/models/environment.rb
@@ -3,7 +3,17 @@ | @@ -3,7 +3,17 @@ | ||
3 | # domains. | 3 | # domains. |
4 | class Environment < ActiveRecord::Base | 4 | class Environment < ActiveRecord::Base |
5 | 5 | ||
6 | - attr_accessible :name, :is_default, :signup_welcome_text_subject, :signup_welcome_text_body, :terms_of_use, :message_for_disabled_enterprise, :news_amount_by_folder, :default_language, :languages, :description, :organization_approval_method, :enabled_plugins, :enabled_features, :redirection_after_login, :redirection_after_signup, :contact_email, :theme, :reports_lower_bound, :noreply_email, :signup_welcome_screen_body, :members_whitelist_enabled, :members_whitelist, :highlighted_news_amount, :portal_news_amount | 6 | + attr_accessible :name, :is_default, :signup_welcome_text_subject, |
7 | + :signup_welcome_text_body, :terms_of_use, | ||
8 | + :message_for_disabled_enterprise, :news_amount_by_folder, | ||
9 | + :default_language, :languages, :description, | ||
10 | + :organization_approval_method, :enabled_plugins, | ||
11 | + :enabled_features, :redirection_after_login, | ||
12 | + :redirection_after_signup, :contact_email, :theme, | ||
13 | + :reports_lower_bound, :noreply_email, | ||
14 | + :signup_welcome_screen_body, :members_whitelist_enabled, | ||
15 | + :members_whitelist, :highlighted_news_amount, | ||
16 | + :portal_news_amount, :date_format | ||
7 | 17 | ||
8 | has_many :users | 18 | has_many :users |
9 | 19 | ||
@@ -14,6 +24,12 @@ class Environment < ActiveRecord::Base | @@ -14,6 +24,12 @@ class Environment < ActiveRecord::Base | ||
14 | 24 | ||
15 | IDENTIFY_SCRIPTS = /(php[0-9s]?|[sp]htm[l]?|pl|py|cgi|rb)/ | 25 | IDENTIFY_SCRIPTS = /(php[0-9s]?|[sp]htm[l]?|pl|py|cgi|rb)/ |
16 | 26 | ||
27 | + validates_inclusion_of :date_format, | ||
28 | + :in => [ 'numbers_with_year', 'numbers', | ||
29 | + 'month_name_with_year', 'month_name', | ||
30 | + 'past_time'], | ||
31 | + :if => :date_format | ||
32 | + | ||
17 | def self.verify_filename(filename) | 33 | def self.verify_filename(filename) |
18 | filename += '.txt' if File.extname(filename) =~ IDENTIFY_SCRIPTS | 34 | filename += '.txt' if File.extname(filename) =~ IDENTIFY_SCRIPTS |
19 | filename | 35 | filename |
app/models/profile.rb
@@ -13,7 +13,7 @@ class Profile < ActiveRecord::Base | @@ -13,7 +13,7 @@ class Profile < ActiveRecord::Base | ||
13 | :contact_email, :redirect_l10n, | 13 | :contact_email, :redirect_l10n, |
14 | :notification_time, :redirection_after_login, | 14 | :notification_time, :redirection_after_login, |
15 | :email_suggestions, :allow_members_to_invite, | 15 | :email_suggestions, :allow_members_to_invite, |
16 | - :invite_friends_only, :secret, :date_format | 16 | + :invite_friends_only, :secret |
17 | 17 | ||
18 | # use for internationalizable human type names in search facets | 18 | # use for internationalizable human type names in search facets |
19 | # reimplement on subclasses | 19 | # reimplement on subclasses |
@@ -191,12 +191,6 @@ class Profile < ActiveRecord::Base | @@ -191,12 +191,6 @@ class Profile < ActiveRecord::Base | ||
191 | 191 | ||
192 | validates_length_of :description, :maximum => 550, :allow_nil => true | 192 | validates_length_of :description, :maximum => 550, :allow_nil => true |
193 | 193 | ||
194 | - validates_inclusion_of :date_format, | ||
195 | - :in => [ 'numbers_with_year', 'numbers', | ||
196 | - 'month_name_with_year', 'month_name', | ||
197 | - 'past_time'], | ||
198 | - :if => :date_format | ||
199 | - | ||
200 | # Valid identifiers must match this format. | 194 | # Valid identifiers must match this format. |
201 | IDENTIFIER_FORMAT = /^#{Noosfero.identifier_format}$/ | 195 | IDENTIFIER_FORMAT = /^#{Noosfero.identifier_format}$/ |
202 | 196 |
app/views/admin_panel/_site_info.html.erb
@@ -3,6 +3,21 @@ | @@ -3,6 +3,21 @@ | ||
3 | <%= labelled_form_field(_('No reply email'), text_field(:environment, :noreply_email)) %> | 3 | <%= labelled_form_field(_('No reply email'), text_field(:environment, :noreply_email)) %> |
4 | <% themes_options = Theme.system_themes.map {|theme| [theme.name, theme.id] }.sort %> | 4 | <% themes_options = Theme.system_themes.map {|theme| [theme.name, theme.id] }.sort %> |
5 | <%= labelled_form_field(_('Theme'), select(:environment, :theme, options_for_select(themes_options, environment.theme))) %> | 5 | <%= labelled_form_field(_('Theme'), select(:environment, :theme, options_for_select(themes_options, environment.theme))) %> |
6 | + | ||
7 | +<%= labelled_form_field( | ||
8 | + _("Article's date format"), | ||
9 | + select(:environment, :date_format, | ||
10 | + options_for_select([ | ||
11 | + [ _('mm/dd/yyyy'), 'numbers_with_year'], | ||
12 | + [ _('mm/dd'), 'numbers'], | ||
13 | + [ _('Month dd, yyyy'), 'month_name_with_year'], | ||
14 | + [ _('Month dd'), 'month_name'], | ||
15 | + [ _('X minutes/hours/days/months/years ago'), 'past_time'] | ||
16 | + ], environment.date_format | ||
17 | + ) | ||
18 | + ) | ||
19 | +) %> | ||
20 | + | ||
6 | <%= required f.text_field(:reports_lower_bound, :size => 3) %> | 21 | <%= required f.text_field(:reports_lower_bound, :size => 3) %> |
7 | <%= labelled_form_field(_('Default language'), select(:environment, :default_language, environment.locales.invert, { :selected => environment.default_locale, :include_blank => true })) %> | 22 | <%= labelled_form_field(_('Default language'), select(:environment, :default_language, environment.locales.invert, { :selected => environment.default_locale, :include_blank => true })) %> |
8 | <%= label_tag :languages, _('Available languages') %> | 23 | <%= label_tag :languages, _('Available languages') %> |
app/views/cms/general_configuration.html.erb
@@ -1,25 +0,0 @@ | @@ -1,25 +0,0 @@ | ||
1 | -<div class="general-configuration"> | ||
2 | - | ||
3 | -<h2> <%= _('General Configuration:') %> </h2> | ||
4 | -<%= labelled_form_for :profile_data do |f|%> | ||
5 | - <h2><%= _("Article's date format") %> </h2> | ||
6 | - | ||
7 | - <%= _("This option will define how article's date will be showed") %> | ||
8 | - <br> | ||
9 | - <br> | ||
10 | - <%= select_tag('profile_data[date_format]', options_for_select([ | ||
11 | - [ _('mm/dd/yyyy'), 'numbers_with_year'], | ||
12 | - [ _('mm/dd'), 'numbers'], | ||
13 | - [ _('Month dd, yyyy'), 'month_name_with_year'], | ||
14 | - [ _('Month dd'), 'month_name'], | ||
15 | - [ _('X minutes/hours/days/months/years ago'), 'past_time'] | ||
16 | - ], @profile_data.date_format)) %> | ||
17 | - | ||
18 | - <br> | ||
19 | - <br> | ||
20 | - | ||
21 | - <%= submit_button('save', _('Save')) %> | ||
22 | - <%= modal_close_button(_('Cancel')) %> | ||
23 | -<% end %> | ||
24 | - | ||
25 | -</div> |
app/views/cms/view.html.erb
@@ -18,7 +18,6 @@ | @@ -18,7 +18,6 @@ | ||
18 | <% parent_id = ((@article && @article.allow_children?) ? @article : nil) %> | 18 | <% parent_id = ((@article && @article.allow_children?) ? @article : nil) %> |
19 | 19 | ||
20 | <%= modal_button('new', _('New content'), :action => 'new', :parent_id => parent_id, :cms => true) %> | 20 | <%= modal_button('new', _('New content'), :action => 'new', :parent_id => parent_id, :cms => true) %> |
21 | - <%= modal_button('edit', _('General Configuration'), :action => 'general_configuration', :parent_id => parent_id, :cms => true) %> | ||
22 | <%= button(:back, _('Back to control panel'), :controller => 'profile_editor', :action => "index") %> | 21 | <%= button(:back, _('Back to control panel'), :controller => 'profile_editor', :action => "index") %> |
23 | <% end %> | 22 | <% end %> |
24 | 23 |
db/migrate/20150529180110_add_date_format_to_environment.rb
0 → 100644
db/migrate/20150529180110_add_date_format_to_profile.rb
db/schema.rb
@@ -331,6 +331,7 @@ ActiveRecord::Schema.define(:version => 20150602142030) do | @@ -331,6 +331,7 @@ ActiveRecord::Schema.define(:version => 20150602142030) do | ||
331 | t.string "default_language" | 331 | t.string "default_language" |
332 | t.string "noreply_email" | 332 | t.string "noreply_email" |
333 | t.string "redirection_after_signup", :default => "keep_on_same_page" | 333 | t.string "redirection_after_signup", :default => "keep_on_same_page" |
334 | + t.string "date_format", :default => "month_name_with_year" | ||
334 | end | 335 | end |
335 | 336 | ||
336 | create_table "external_feeds", :force => true do |t| | 337 | create_table "external_feeds", :force => true do |t| |
@@ -535,16 +536,15 @@ ActiveRecord::Schema.define(:version => 20150602142030) do | @@ -535,16 +536,15 @@ ActiveRecord::Schema.define(:version => 20150602142030) do | ||
535 | t.boolean "is_template", :default => false | 536 | t.boolean "is_template", :default => false |
536 | t.integer "template_id" | 537 | t.integer "template_id" |
537 | t.string "redirection_after_login" | 538 | t.string "redirection_after_login" |
538 | - t.integer "friends_count", :default => 0, :null => false | ||
539 | - t.integer "members_count", :default => 0, :null => false | ||
540 | - t.integer "activities_count", :default => 0, :null => false | 539 | + t.integer "friends_count", :default => 0, :null => false |
540 | + t.integer "members_count", :default => 0, :null => false | ||
541 | + t.integer "activities_count", :default => 0, :null => false | ||
541 | t.string "personal_website" | 542 | t.string "personal_website" |
542 | t.string "jabber_id" | 543 | t.string "jabber_id" |
543 | t.integer "welcome_page_id" | 544 | t.integer "welcome_page_id" |
544 | t.boolean "allow_members_to_invite", :default => true | 545 | t.boolean "allow_members_to_invite", :default => true |
545 | t.boolean "invite_friends_only", :default => false | 546 | t.boolean "invite_friends_only", :default => false |
546 | t.boolean "secret", :default => false | 547 | t.boolean "secret", :default => false |
547 | - t.string "date_format", :default => "month_name_with_year" | ||
548 | end | 548 | end |
549 | 549 | ||
550 | add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count" | 550 | add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count" |
public/stylesheets/application.css
@@ -3462,11 +3462,6 @@ table.cms-articles .icon:hover { | @@ -3462,11 +3462,6 @@ table.cms-articles .icon:hover { | ||
3462 | width: 455px; | 3462 | width: 455px; |
3463 | } | 3463 | } |
3464 | 3464 | ||
3465 | -.general-configuration { | ||
3466 | - padding: 5px 20px; | ||
3467 | - width: 455px; | ||
3468 | -} | ||
3469 | - | ||
3470 | .article-types { | 3465 | .article-types { |
3471 | padding-left: 5px; | 3466 | padding-left: 5px; |
3472 | margin-top: 20px; | 3467 | margin-top: 20px; |
test/functional/cms_controller_test.rb
@@ -1869,24 +1869,6 @@ class CmsControllerTest < ActionController::TestCase | @@ -1869,24 +1869,6 @@ class CmsControllerTest < ActionController::TestCase | ||
1869 | assert_equal '[{"label":"linux","value":"linux"}]', @response.body | 1869 | assert_equal '[{"label":"linux","value":"linux"}]', @response.body |
1870 | end | 1870 | end |
1871 | 1871 | ||
1872 | - should 'save general configuration when is passed a valid value' do | ||
1873 | - post :general_configuration, profile: profile.identifier, :profile_data => { date_format: "numbers_with_year" } | ||
1874 | - profile.reload | ||
1875 | - | ||
1876 | - assert_equal profile.date_format, "numbers_with_year" | ||
1877 | - end | ||
1878 | - | ||
1879 | - should 'not save general configuration when is not passed a valid value' do | ||
1880 | - profile.date_format = "month_name_with_year" | ||
1881 | - profile.save! | ||
1882 | - | ||
1883 | - post :general_configuration, profile: profile.identifier, :profile_data => { date_format: "invalid_format" } | ||
1884 | - profile.reload | ||
1885 | - | ||
1886 | - assert_equal profile.date_format, "month_name_with_year" | ||
1887 | - end | ||
1888 | - | ||
1889 | - | ||
1890 | protected | 1872 | protected |
1891 | 1873 | ||
1892 | # FIXME this is to avoid adding an extra dependency for a proper JSON parser. | 1874 | # FIXME this is to avoid adding an extra dependency for a proper JSON parser. |
test/unit/content_viewer_helper_test.rb
@@ -113,37 +113,37 @@ class ContentViewerHelperTest < ActionView::TestCase | @@ -113,37 +113,37 @@ class ContentViewerHelperTest < ActionView::TestCase | ||
113 | end | 113 | end |
114 | 114 | ||
115 | should 'show date with mm/dd/yyyy' do | 115 | should 'show date with mm/dd/yyyy' do |
116 | + Environment.any_instance.stubs(:date_format).returns('numbers_with_year') | ||
116 | article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile) | 117 | article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile) |
117 | article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45) | 118 | article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45) |
118 | article.save! | 119 | article.save! |
119 | - profile.date_format = "numbers_with_year" | ||
120 | result = show_with_right_format_date article | 120 | result = show_with_right_format_date article |
121 | assert_match /2\/1\/2007/, result | 121 | assert_match /2\/1\/2007/, result |
122 | end | 122 | end |
123 | 123 | ||
124 | should 'show date with mm/dd' do | 124 | should 'show date with mm/dd' do |
125 | + Environment.any_instance.stubs(:date_format).returns('numbers') | ||
125 | article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile) | 126 | article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile) |
126 | article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45) | 127 | article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45) |
127 | article.save! | 128 | article.save! |
128 | - profile.date_format = "numbers" | ||
129 | result = show_with_right_format_date article | 129 | result = show_with_right_format_date article |
130 | assert_match /2\/1/, result | 130 | assert_match /2\/1/, result |
131 | end | 131 | end |
132 | 132 | ||
133 | should 'show date with month name' do | 133 | should 'show date with month name' do |
134 | + Environment.any_instance.stubs(:date_format).returns('month_name') | ||
134 | article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile) | 135 | article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile) |
135 | article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45) | 136 | article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45) |
136 | article.save! | 137 | article.save! |
137 | - profile.date_format = "month_name" | ||
138 | result = show_with_right_format_date article | 138 | result = show_with_right_format_date article |
139 | assert_match /February 1/, result | 139 | assert_match /February 1/, result |
140 | end | 140 | end |
141 | 141 | ||
142 | should 'show date with month name and year' do | 142 | should 'show date with month name and year' do |
143 | + Environment.any_instance.stubs(:date_format).returns('month_name_with_year') | ||
143 | article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile) | 144 | article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile) |
144 | article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45) | 145 | article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45) |
145 | article.save! | 146 | article.save! |
146 | - profile.date_format = "month_name_with_year" | ||
147 | result = show_with_right_format_date article | 147 | result = show_with_right_format_date article |
148 | assert_match /February 1, 2007/, result | 148 | assert_match /February 1, 2007/, result |
149 | end | 149 | end |
test/unit/environment_test.rb
@@ -1703,4 +1703,32 @@ class EnvironmentTest < ActiveSupport::TestCase | @@ -1703,4 +1703,32 @@ class EnvironmentTest < ActiveSupport::TestCase | ||
1703 | assert !e.has_license? | 1703 | assert !e.has_license? |
1704 | end | 1704 | end |
1705 | 1705 | ||
1706 | + should 'validates_inclusion_of date format' do | ||
1707 | + environment = fast_create(Environment) | ||
1708 | + | ||
1709 | + environment.date_format = "invalid_format" | ||
1710 | + environment.valid? | ||
1711 | + assert environment.errors[:date_format.to_s].present? | ||
1712 | + | ||
1713 | + environment.date_format = "numbers_with_year" | ||
1714 | + environment.valid? | ||
1715 | + assert !environment.errors[:date_format.to_s].present? | ||
1716 | + | ||
1717 | + environment.date_format = "numbers" | ||
1718 | + environment.valid? | ||
1719 | + assert !environment.errors[:date_format.to_s].present? | ||
1720 | + | ||
1721 | + environment.date_format = "month_name_with_year" | ||
1722 | + environment.valid? | ||
1723 | + assert !environment.errors[:date_format.to_s].present? | ||
1724 | + | ||
1725 | + environment.date_format = "month_name" | ||
1726 | + environment.valid? | ||
1727 | + assert !environment.errors[:date_format.to_s].present? | ||
1728 | + | ||
1729 | + environment.date_format = "past_time" | ||
1730 | + environment.valid? | ||
1731 | + assert !environment.errors[:date_format.to_s].present? | ||
1732 | + end | ||
1733 | + | ||
1706 | end | 1734 | end |
test/unit/profile_test.rb
@@ -2176,33 +2176,4 @@ class ProfileTest < ActiveSupport::TestCase | @@ -2176,33 +2176,4 @@ class ProfileTest < ActiveSupport::TestCase | ||
2176 | assert_includes Profile.enabled, p2 | 2176 | assert_includes Profile.enabled, p2 |
2177 | assert_not_includes Profile.enabled, p3 | 2177 | assert_not_includes Profile.enabled, p3 |
2178 | end | 2178 | end |
2179 | - | ||
2180 | - should 'validates_inclusion_of date format' do | ||
2181 | - profile = fast_create(Profile) | ||
2182 | - | ||
2183 | - profile.date_format = "invalid_format" | ||
2184 | - profile.valid? | ||
2185 | - assert profile.errors[:date_format.to_s].present? | ||
2186 | - | ||
2187 | - profile.date_format = "numbers_with_year" | ||
2188 | - profile.valid? | ||
2189 | - assert !profile.errors[:date_format.to_s].present? | ||
2190 | - | ||
2191 | - profile.date_format = "numbers" | ||
2192 | - profile.valid? | ||
2193 | - assert !profile.errors[:date_format.to_s].present? | ||
2194 | - | ||
2195 | - profile.date_format = "month_name_with_year" | ||
2196 | - profile.valid? | ||
2197 | - assert !profile.errors[:date_format.to_s].present? | ||
2198 | - | ||
2199 | - profile.date_format = "month_name" | ||
2200 | - profile.valid? | ||
2201 | - assert !profile.errors[:date_format.to_s].present? | ||
2202 | - | ||
2203 | - profile.date_format = "past_time" | ||
2204 | - profile.valid? | ||
2205 | - assert !profile.errors[:date_format.to_s].present? | ||
2206 | - | ||
2207 | - end | ||
2208 | end | 2179 | end |