diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb
index 007ae4b..d3c073c 100644
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -188,18 +188,6 @@ class CmsController < MyProfileController
render :action => 'edit'
end
- def general_configuration
- @profile_data = profile
- if request.post?
- if @profile_data.update_attributes(params[:profile_data])
- session[:notice] = _("Article date format updated successfully")
- else
- session[:notice] = _("Could not update article's date format")
- end
- redirect_to :action => 'index'
- end
- end
-
post_only :set_home_page
def set_home_page
return render_access_denied unless user.can_change_homepage?
diff --git a/app/helpers/content_viewer_helper.rb b/app/helpers/content_viewer_helper.rb
index 132c70f..536cf5f 100644
--- a/app/helpers/content_viewer_helper.rb
+++ b/app/helpers/content_viewer_helper.rb
@@ -37,7 +37,7 @@ module ContentViewerHelper
end
def show_with_right_format_date article
- date_format = article.profile.date_format
+ date_format = Environment.default.date_format
use_numbers = false
year = true
left_time = false
diff --git a/app/models/environment.rb b/app/models/environment.rb
index 502d07b..321551d 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -3,7 +3,17 @@
# domains.
class Environment < ActiveRecord::Base
- 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
+ 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, :date_format
has_many :users
@@ -14,6 +24,12 @@ class Environment < ActiveRecord::Base
IDENTIFY_SCRIPTS = /(php[0-9s]?|[sp]htm[l]?|pl|py|cgi|rb)/
+ validates_inclusion_of :date_format,
+ :in => [ 'numbers_with_year', 'numbers',
+ 'month_name_with_year', 'month_name',
+ 'past_time'],
+ :if => :date_format
+
def self.verify_filename(filename)
filename += '.txt' if File.extname(filename) =~ IDENTIFY_SCRIPTS
filename
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 3e53d7e..e7e80d5 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -13,7 +13,7 @@ class Profile < ActiveRecord::Base
:contact_email, :redirect_l10n,
:notification_time, :redirection_after_login,
:email_suggestions, :allow_members_to_invite,
- :invite_friends_only, :secret, :date_format
+ :invite_friends_only, :secret
# use for internationalizable human type names in search facets
# reimplement on subclasses
@@ -191,12 +191,6 @@ class Profile < ActiveRecord::Base
validates_length_of :description, :maximum => 550, :allow_nil => true
- validates_inclusion_of :date_format,
- :in => [ 'numbers_with_year', 'numbers',
- 'month_name_with_year', 'month_name',
- 'past_time'],
- :if => :date_format
-
# Valid identifiers must match this format.
IDENTIFIER_FORMAT = /^#{Noosfero.identifier_format}$/
diff --git a/app/views/admin_panel/_site_info.html.erb b/app/views/admin_panel/_site_info.html.erb
index 062b062..8641313 100644
--- a/app/views/admin_panel/_site_info.html.erb
+++ b/app/views/admin_panel/_site_info.html.erb
@@ -3,6 +3,21 @@
<%= labelled_form_field(_('No reply email'), text_field(:environment, :noreply_email)) %>
<% themes_options = Theme.system_themes.map {|theme| [theme.name, theme.id] }.sort %>
<%= labelled_form_field(_('Theme'), select(:environment, :theme, options_for_select(themes_options, environment.theme))) %>
+
+<%= labelled_form_field(
+ _("Article's date format"),
+ select(:environment, :date_format,
+ options_for_select([
+ [ _('mm/dd/yyyy'), 'numbers_with_year'],
+ [ _('mm/dd'), 'numbers'],
+ [ _('Month dd, yyyy'), 'month_name_with_year'],
+ [ _('Month dd'), 'month_name'],
+ [ _('X minutes/hours/days/months/years ago'), 'past_time']
+ ], environment.date_format
+ )
+ )
+) %>
+
<%= required f.text_field(:reports_lower_bound, :size => 3) %>
<%= labelled_form_field(_('Default language'), select(:environment, :default_language, environment.locales.invert, { :selected => environment.default_locale, :include_blank => true })) %>
<%= label_tag :languages, _('Available languages') %>
diff --git a/app/views/cms/general_configuration.html.erb b/app/views/cms/general_configuration.html.erb
deleted file mode 100644
index 2a07905..0000000
--- a/app/views/cms/general_configuration.html.erb
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
<%= _('General Configuration:') %>
-<%= labelled_form_for :profile_data do |f|%>
- <%= _("Article's date format") %>
-
- <%= _("This option will define how article's date will be showed") %>
-
-
- <%= select_tag('profile_data[date_format]', options_for_select([
- [ _('mm/dd/yyyy'), 'numbers_with_year'],
- [ _('mm/dd'), 'numbers'],
- [ _('Month dd, yyyy'), 'month_name_with_year'],
- [ _('Month dd'), 'month_name'],
- [ _('X minutes/hours/days/months/years ago'), 'past_time']
- ], @profile_data.date_format)) %>
-
-
-
-
- <%= submit_button('save', _('Save')) %>
- <%= modal_close_button(_('Cancel')) %>
-<% end %>
-
-
diff --git a/app/views/cms/view.html.erb b/app/views/cms/view.html.erb
index ec0af1b..b9a2b0c 100644
--- a/app/views/cms/view.html.erb
+++ b/app/views/cms/view.html.erb
@@ -18,7 +18,6 @@
<% parent_id = ((@article && @article.allow_children?) ? @article : nil) %>
<%= modal_button('new', _('New content'), :action => 'new', :parent_id => parent_id, :cms => true) %>
- <%= modal_button('edit', _('General Configuration'), :action => 'general_configuration', :parent_id => parent_id, :cms => true) %>
<%= button(:back, _('Back to control panel'), :controller => 'profile_editor', :action => "index") %>
<% end %>
diff --git a/db/migrate/20150529180110_add_date_format_to_environment.rb b/db/migrate/20150529180110_add_date_format_to_environment.rb
new file mode 100644
index 0000000..594818e
--- /dev/null
+++ b/db/migrate/20150529180110_add_date_format_to_environment.rb
@@ -0,0 +1,9 @@
+class AddDateFormatToEnvironment < ActiveRecord::Migration
+ def up
+ add_column :environments, :date_format, :string, :default => 'month_name_with_year'
+ end
+
+ def down
+ remove_column :environments, :date_format
+ end
+end
diff --git a/db/migrate/20150529180110_add_date_format_to_profile.rb b/db/migrate/20150529180110_add_date_format_to_profile.rb
deleted file mode 100644
index 36d4dee..0000000
--- a/db/migrate/20150529180110_add_date_format_to_profile.rb
+++ /dev/null
@@ -1,9 +0,0 @@
-class AddDateFormatToProfile < ActiveRecord::Migration
- def up
- add_column :profiles, :date_format, :string, :default => 'month_name_with_year'
- end
-
- def down
- remove_column :profiles, :date_format
- end
-end
diff --git a/db/schema.rb b/db/schema.rb
index 0cca7e3..eb64b94 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -331,6 +331,7 @@ ActiveRecord::Schema.define(:version => 20150602142030) do
t.string "default_language"
t.string "noreply_email"
t.string "redirection_after_signup", :default => "keep_on_same_page"
+ t.string "date_format", :default => "month_name_with_year"
end
create_table "external_feeds", :force => true do |t|
@@ -535,16 +536,15 @@ ActiveRecord::Schema.define(:version => 20150602142030) do
t.boolean "is_template", :default => false
t.integer "template_id"
t.string "redirection_after_login"
- t.integer "friends_count", :default => 0, :null => false
- t.integer "members_count", :default => 0, :null => false
- t.integer "activities_count", :default => 0, :null => false
+ t.integer "friends_count", :default => 0, :null => false
+ t.integer "members_count", :default => 0, :null => false
+ t.integer "activities_count", :default => 0, :null => false
t.string "personal_website"
t.string "jabber_id"
t.integer "welcome_page_id"
t.boolean "allow_members_to_invite", :default => true
t.boolean "invite_friends_only", :default => false
t.boolean "secret", :default => false
- t.string "date_format", :default => "month_name_with_year"
end
add_index "profiles", ["activities_count"], :name => "index_profiles_on_activities_count"
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 764d080..c441388 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -3462,11 +3462,6 @@ table.cms-articles .icon:hover {
width: 455px;
}
-.general-configuration {
- padding: 5px 20px;
- width: 455px;
-}
-
.article-types {
padding-left: 5px;
margin-top: 20px;
diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb
index 91be37c..11d1ed7 100644
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -1869,24 +1869,6 @@ class CmsControllerTest < ActionController::TestCase
assert_equal '[{"label":"linux","value":"linux"}]', @response.body
end
- should 'save general configuration when is passed a valid value' do
- post :general_configuration, profile: profile.identifier, :profile_data => { date_format: "numbers_with_year" }
- profile.reload
-
- assert_equal profile.date_format, "numbers_with_year"
- end
-
- should 'not save general configuration when is not passed a valid value' do
- profile.date_format = "month_name_with_year"
- profile.save!
-
- post :general_configuration, profile: profile.identifier, :profile_data => { date_format: "invalid_format" }
- profile.reload
-
- assert_equal profile.date_format, "month_name_with_year"
- end
-
-
protected
# FIXME this is to avoid adding an extra dependency for a proper JSON parser.
diff --git a/test/unit/content_viewer_helper_test.rb b/test/unit/content_viewer_helper_test.rb
index 9ba2fa5..9f8e0d6 100644
--- a/test/unit/content_viewer_helper_test.rb
+++ b/test/unit/content_viewer_helper_test.rb
@@ -113,37 +113,37 @@ class ContentViewerHelperTest < ActionView::TestCase
end
should 'show date with mm/dd/yyyy' do
+ Environment.any_instance.stubs(:date_format).returns('numbers_with_year')
article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile)
article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45)
article.save!
- profile.date_format = "numbers_with_year"
result = show_with_right_format_date article
assert_match /2\/1\/2007/, result
end
should 'show date with mm/dd' do
+ Environment.any_instance.stubs(:date_format).returns('numbers')
article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile)
article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45)
article.save!
- profile.date_format = "numbers"
result = show_with_right_format_date article
assert_match /2\/1/, result
end
should 'show date with month name' do
+ Environment.any_instance.stubs(:date_format).returns('month_name')
article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile)
article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45)
article.save!
- profile.date_format = "month_name"
result = show_with_right_format_date article
assert_match /February 1/, result
end
should 'show date with month name and year' do
+ Environment.any_instance.stubs(:date_format).returns('month_name_with_year')
article = TextileArticle.new(:name => 'post for test', :body => 'post for test', :profile => profile)
article.published_at = Time.zone.local(2007, 2, 1, 15, 30, 45)
article.save!
- profile.date_format = "month_name_with_year"
result = show_with_right_format_date article
assert_match /February 1, 2007/, result
end
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index 460fc74..1fed0f9 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -1703,4 +1703,32 @@ class EnvironmentTest < ActiveSupport::TestCase
assert !e.has_license?
end
+ should 'validates_inclusion_of date format' do
+ environment = fast_create(Environment)
+
+ environment.date_format = "invalid_format"
+ environment.valid?
+ assert environment.errors[:date_format.to_s].present?
+
+ environment.date_format = "numbers_with_year"
+ environment.valid?
+ assert !environment.errors[:date_format.to_s].present?
+
+ environment.date_format = "numbers"
+ environment.valid?
+ assert !environment.errors[:date_format.to_s].present?
+
+ environment.date_format = "month_name_with_year"
+ environment.valid?
+ assert !environment.errors[:date_format.to_s].present?
+
+ environment.date_format = "month_name"
+ environment.valid?
+ assert !environment.errors[:date_format.to_s].present?
+
+ environment.date_format = "past_time"
+ environment.valid?
+ assert !environment.errors[:date_format.to_s].present?
+ end
+
end
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 9c04760..7bf13da 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -2176,33 +2176,4 @@ class ProfileTest < ActiveSupport::TestCase
assert_includes Profile.enabled, p2
assert_not_includes Profile.enabled, p3
end
-
- should 'validates_inclusion_of date format' do
- profile = fast_create(Profile)
-
- profile.date_format = "invalid_format"
- profile.valid?
- assert profile.errors[:date_format.to_s].present?
-
- profile.date_format = "numbers_with_year"
- profile.valid?
- assert !profile.errors[:date_format.to_s].present?
-
- profile.date_format = "numbers"
- profile.valid?
- assert !profile.errors[:date_format.to_s].present?
-
- profile.date_format = "month_name_with_year"
- profile.valid?
- assert !profile.errors[:date_format.to_s].present?
-
- profile.date_format = "month_name"
- profile.valid?
- assert !profile.errors[:date_format.to_s].present?
-
- profile.date_format = "past_time"
- profile.valid?
- assert !profile.errors[:date_format.to_s].present?
-
- end
end
--
libgit2 0.21.2