diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb index d4a0330..4512674 100644 --- a/app/controllers/my_profile/profile_editor_controller.rb +++ b/app/controllers/my_profile/profile_editor_controller.rb @@ -17,7 +17,7 @@ class ProfileEditorController < MyProfileController Profile.transaction do Image.transaction do if profile.update_attributes!(params[:profile_data]) - redirect_to :action => 'index' + redirect_to :action => 'index', :profile => profile.identifier end end end diff --git a/app/models/environment.rb b/app/models/environment.rb index 5c895c3..06b3e93 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -127,6 +127,7 @@ class Environment < ActiveRecord::Base 'display_header_footer_explanation' => N_("Display explanation about header and footer"), 'articles_dont_accept_comments_by_default' => N_("Articles don't accept comments by default"), 'organizations_are_moderated_by_default' => N_("Organizations have moderated publication by default"), + 'enable_organization_url_change' => N_("Enable organizations to change its address"), } end diff --git a/app/models/person.rb b/app/models/person.rb index 0a7fde1..4dbae16 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -12,6 +12,15 @@ class Person < Profile Friendship.find(:all, :conditions => { :friend_id => person.id}).each { |friendship| friendship.destroy } end + # Sets the identifier for this person. Raises an exception when called on a + # existing person (since peoples' identifiers cannot be changed) + def identifier=(value) + unless self.new_record? + raise ArgumentError.new(_('An existing person cannot be renamed.')) + end + self[:identifier] = value + end + settings_items :last_lang, :type => :string def last_lang if self.data[:last_lang].nil? or self.data[:last_lang].empty? diff --git a/app/models/profile.rb b/app/models/profile.rb index 5ed0956..83f2ba2 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -194,15 +194,6 @@ class Profile < ActiveRecord::Base end @top_level_articles ||= Article.top_level_for(self) end - - # Sets the identifier for this profile. Raises an exception when called on a - # existing profile (since profiles cannot be renamed) - def identifier=(value) - unless self.new_record? - raise ArgumentError.new(_('An existing profile cannot be renamed.')) - end - self[:identifier] = value - end def self.is_available?(identifier) !(identifier =~ IDENTIFIER_FORMAT).nil? && !RESERVED_IDENTIFIERS.include?(identifier) && Profile.find(:first, :conditions => ['environment_id = ? and identifier = ?', Environment.default.id, identifier]).nil? diff --git a/app/views/profile_editor/_organization.rhtml b/app/views/profile_editor/_organization.rhtml index f37d201..323161b 100644 --- a/app/views/profile_editor/_organization.rhtml +++ b/app/views/profile_editor/_organization.rhtml @@ -2,14 +2,59 @@ <%= required_fields_message if @profile.required_fields.any? %> +<% if @environment.enabled?('enable_organization_url_change') %> + +<% end %> +
- <%= text_field_tag 'profile_data[nickname]', @profile_data.nickname, :id => 'profile_data_nickname', :size => 30, :maxlength => 16 %> + <%= text_field_tag 'profile_data[nickname]', @profile_data.nickname, :id => 'profile_data_nickname', :size => 30, :maxlength => 16, :onchange => (@environment.enabled?('enable_organization_url_change') ? "updateUrlField(this, 'profile_data_identifier')" : "") %> <%= _('A short name by which the organization is know.')%> +
- +<% if @environment.enabled?('enable_organization_url_change') %> + + + <%= hidden_field_tag 'old_profile_identifier', @profile.identifier %> +
+ <%= labelled_form_field( _('Address'), + '' + url_for(profile.url).gsub(/#{profile.identifier}$/, '') + + text_field(:profile_data, :identifier, :onchange => "warn_value_change(this)", :size => 15) + '' + + content_tag('div', '' + _('WARNING:') + ' ' + _("the address was changed, this might break any external links to this profile and articles in this profile, you really want to change? ") + + '
' + button_to_function(:ok, _("Yes"), 'hide_warning()') + ' ' + + button_to_function(:cancel, _('No'), '$("profile_data_identifier").value = $("old_profile_identifier").value; hide_warning()') + '
', + :id => 'identifier-change-confirmation' + ) + ) + %> +
+<% end %> + <%= f.text_field(:acronym) %> <%= f.text_field(:foundation_year) %> <%= optional_field(@profile, 'contact_person', f.text_field(:contact_person)) %> diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 74d618e..aaf73ed 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -29,6 +29,11 @@ function focus_first_field() { /* * * Convert a string to a valid login name * * */ function convToValidLogin( str ) { + return convToValidIdentifier(str, '') +} + +/* * * Convert a string to a valid login name * * */ +function convToValidIdentifier( str, sep ) { return str.toLowerCase() .replace( /@.*$/, "" ) .replace( /á|à|ã|â/g, "a" ) @@ -38,7 +43,7 @@ function convToValidLogin( str ) { .replace( /ú|ũ|ü/g, "u" ) .replace( /ñ/g, "n" ) .replace( /ç/g, "c" ) - .replace( /[^-_a-z0-9]+/g, "" ) + .replace( /[^-_a-z0-9]+/g, sep ) } document.observe("dom:loaded", function() { diff --git a/public/stylesheets/button.css b/public/stylesheets/button.css index c338939..b52f377 100644 --- a/public/stylesheets/button.css +++ b/public/stylesheets/button.css @@ -96,3 +96,7 @@ input.button.with-text:hover { border: none; } +input.disabled { + opacity: 0.5; + filter-opacity: 50%; +} diff --git a/public/stylesheets/controller_profile_editor.css b/public/stylesheets/controller_profile_editor.css index d4b7d15..1381210 100644 --- a/public/stylesheets/controller_profile_editor.css +++ b/public/stylesheets/controller_profile_editor.css @@ -31,6 +31,21 @@ -moz-border-radius: 3px; } +#identifier-change-confirmation { + background-color: #EE4444; + padding: 3px 20px 3px 20px; + margin: 5px 30px 10px 30px; +} + +#identifier-change-confirmation div { + text-align: right; + padding: 0px 10px 5px 0px; +} + +code input { + font-family: monospace; +} + a.control-panel-groups { background-image: url(../images/control-panel/system-users.png) } .msie6 a.control-panel-groups { background-image: url(../images/control-panel/system-users.gif) } @@ -87,3 +102,4 @@ a.control-panel-validation {background-image: url(../images/control-panel/applic a.control-panel-mail {background-image: url(../images/control-panel/email.png)} .msie6 a.control-panel-mail {background-image: url(../images/control-panel/email.gif)} + diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index ba90fb3..8531470 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -724,5 +724,37 @@ class ProfileEditorControllerTest < Test::Unit::TestCase assert_no_tag :tag => 'div', :attributes => { :id => 'activation_enterprise' }, :descendant => {:tag => 'form', :attributes => {:action => '/account/activation_question'}} end + should 'have url field for identifier when environment allows' do + c = Community.create!(:name => 'test community', :identifier => 'test_comm') + env = c.environment + env.enable('enable_organization_url_change') + env.save! + + get :edit, :profile => c.identifier + assert_tag :tag => 'div', + :attributes => { :class => 'formfield type-text' }, + :content => /https?:\/\/#{c.environment.default_hostname}\//, + :descendant => {:tag => 'input', :attributes => {:id => 'profile_data_identifier'} } + end + + should 'not have url field for identifier when environment not allows' do + c = Community.create!(:name => 'test community', :identifier => 'test_comm') + env = c.environment + env.disable('enable_organization_url_change') + env.save! + + get :edit, :profile => c.identifier + assert_no_tag :tag => 'div', + :attributes => { :class => 'formfield type-text' }, + :content => /https?:\/\/#{c.environment.default_hostname}\//, + :descendant => {:tag => 'input', :attributes => {:id => 'profile_data_identifier'} } + end + + should 'redirect to new url when is changed' do + c = Community.create!(:name => 'test community', :identifier => 'test_comm') + post :edit, :profile => c.identifier, :profile_data => {:identifier => 'new_address'} + assert_response :redirect + assert_redirected_to :action => 'index', :profile => 'new_address' + end end diff --git a/test/unit/organization_test.rb b/test/unit/organization_test.rb index d5a6ece..8bcfd05 100644 --- a/test/unit/organization_test.rb +++ b/test/unit/organization_test.rb @@ -232,4 +232,11 @@ class OrganizationTest < Test::Unit::TestCase assert p.has_permission?(:moderate_comments, o) end + should 'be able to change identifier' do + o = Organization.create!(:name => 'Test Org', :identifier => 'test_org') + assert_nothing_raised do + o.identifier = 'test_org_new_url' + end + end + end diff --git a/test/unit/person_test.rb b/test/unit/person_test.rb index 537795f..f48318b 100644 --- a/test/unit/person_test.rb +++ b/test/unit/person_test.rb @@ -574,4 +574,11 @@ class PersonTest < Test::Unit::TestCase end end + should 'not rename' do + assert_valid p = create_user('test_user').person + assert_raise ArgumentError do + p.identifier = 'other_person_name' + end + end + end diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb index d6799d1..ee3d087 100644 --- a/test/unit/profile_test.rb +++ b/test/unit/profile_test.rb @@ -72,13 +72,6 @@ class ProfileTest < Test::Unit::TestCase assert_equal Environment.default, e end - def test_cannot_rename - assert_valid p = Profile.create(:name => 'new_profile', :identifier => 'new_profile') - assert_raise ArgumentError do - p.identifier = 'other_profile' - end - end - should 'provide access to home page' do profile = Profile.create!(:identifier => 'newprofile', :name => 'New Profile') assert_kind_of Article, profile.home_page -- libgit2 0.21.2