diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index c86b40f..3d4a9c6 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -1107,7 +1107,7 @@ module ApplicationHelper
def manage_enterprises
if user && !user.enterprises.empty?
enterprises_link = user.enterprises.map do |enterprise|
- link_to(content_tag('strong', [_('Manage %s') % enterprise.short_name(25)]), "/myprofile/#{enterprise.identifier}", :class => "icon-menu-enterprise", :title => [_('Manage %s') % enterprise.short_name])
+ link_to(content_tag('strong', [_('Manage %s') % enterprise.short_name(25)]), @environment.top_url + "/myprofile/#{enterprise.identifier}", :class => "icon-menu-enterprise", :title => [_('Manage %s') % enterprise.short_name])
end
render :partial => 'shared/manage_enterprises', :locals => {:enterprises_link => enterprises_link}
end
@@ -1116,12 +1116,12 @@ module ApplicationHelper
def usermenu_logged_in
pending_tasks_count = ''
if user && user.all_pending_tasks.count > 0
- pending_tasks_count = link_to(user.all_pending_tasks.count.to_s, '/myprofile/{login}/tasks', :id => 'pending-tasks-count', :title => _("Manage your pending tasks"))
+ pending_tasks_count = link_to(user.all_pending_tasks.count.to_s, @environment.top_url + '/myprofile/{login}/tasks', :id => 'pending-tasks-count', :title => _("Manage your pending tasks"))
end
(_('Welcome, %s') % link_to('{login}', @environment.top_url + '/{login}', :id => "homepage-link", :title => _('Go to your homepage'))) +
render_environment_features(:usermenu) +
- link_to('' + _('Administration') + '', { :controller => 'admin_panel', :action => 'index' }, :id => "controlpanel", :title => _("Configure the environment"), :class => 'admin-link', :style => 'display: none') +
+ link_to('' + _('Administration') + '', { :host => @environment.default_hostname, :controller => 'admin_panel', :action => 'index' }, :id => "controlpanel", :title => _("Configure the environment"), :class => 'admin-link', :style => 'display: none') +
manage_enterprises.to_s +
link_to('' + _('Control panel') + '', @environment.top_url + '/myprofile/{login}', :id => "controlpanel", :title => _("Configure your personal account and content")) +
pending_tasks_count +
diff --git a/app/models/environment.rb b/app/models/environment.rb
index aca21c8..c82774d 100644
--- a/app/models/environment.rb
+++ b/app/models/environment.rb
@@ -518,12 +518,15 @@ class Environment < ActiveRecord::Base
# If #force_www is true, adds 'www.' at the beginning of the hostname. If the
# environment has not associated domains, returns 'localhost'.
def default_hostname(email_hostname = false)
- if self.domains(true).empty?
- 'localhost'
- else
+ domain = 'localhost'
+ unless self.domains(true).empty?
domain = (self.domains.find_by_is_default(true) || self.domains.find(:first, :order => 'id')).name
- email_hostname ? domain : (force_www ? ('www.' + domain) : domain)
+ domain = email_hostname ? domain : (force_www ? ('www.' + domain) : domain)
+ end
+ if Noosfero.url_options.has_key?(:port)
+ domain += ":#{Noosfero.url_options[:port]}"
end
+ domain
end
def top_url(ssl = false)
diff --git a/app/views/admin_panel/site_info.rhtml b/app/views/admin_panel/site_info.rhtml
index 59ebd41..93b4461 100644
--- a/app/views/admin_panel/site_info.rhtml
+++ b/app/views/admin_panel/site_info.rhtml
@@ -2,7 +2,7 @@
<%= render :file => 'shared/tiny_mce' %>
-<% labelled_form_for :environment, @environment do |f| %>
+<% labelled_form_for :environment, @environment, :url => {:host => @environment.default_hostname} do |f| %>
<%= labelled_form_field(_('Site name'), text_field(:environment, :name)) %>
diff --git a/app/views/users/send_mail.rhtml b/app/views/users/send_mail.rhtml
index f6033b1..1879b79 100644
--- a/app/views/users/send_mail.rhtml
+++ b/app/views/users/send_mail.rhtml
@@ -4,7 +4,7 @@
<%= render :file => 'shared/tiny_mce' %>
-<% form_for :mailing, :url => {:action => 'send_mail'} do |f| %>
+<% form_for :mailing, :url => {:action => 'send_mail', :host => @environment.default_hostname} do |f| %>
<%= labelled_form_field(_('Subject:'), f.text_field(:subject)) %>
<%= labelled_form_field(_('Body:'), f.text_area(:body, :class => 'mceEditor')) %>
<%= submit_button(:send, _('Send')) %>
diff --git a/features/profile_domain.feature b/features/profile_domain.feature
index f2dbc1b..3afbb08 100644
--- a/features/profile_domain.feature
+++ b/features/profile_domain.feature
@@ -64,3 +64,9 @@ Feature: domain for profile
When I open /something-that-does-not-exist
And I follow "Go to the home page"
Then the page title should be "Colivre.net"
+
+ @selenium
+ Scenario: Compose link to administration with environment domain
+ Given I am logged in as "joaosilva"
+ When I visit "/" and wait
+ Then I should see "Administration" linking to "http://127.0.0.1:3001/admin"
diff --git a/features/step_definitions/noosfero_steps.rb b/features/step_definitions/noosfero_steps.rb
index 692e4df..4a83a38 100644
--- a/features/step_definitions/noosfero_steps.rb
+++ b/features/step_definitions/noosfero_steps.rb
@@ -411,3 +411,7 @@ Given /^the environment domain is "([^\"]*)"$/ do |domain|
d = Domain.new :name => domain, :owner => Environment.default
d.save(false)
end
+
+Given /^"([^\"]*)" is admin of environment$/ do |id|
+ Environment.default.add_admin(Person[id])
+end
diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb
index 3842d28..7347b0b 100644
--- a/test/unit/environment_test.rb
+++ b/test/unit/environment_test.rb
@@ -1119,4 +1119,10 @@ class EnvironmentTest < Test::Unit::TestCase
assert_equal ["Meter", "Kilo", "Litre"], Environment.default.units.map(&:singular)
end
+ should 'include port in default hostname for development environment' do
+ env = Environment.new
+ Noosfero.expects(:url_options).returns({ :port => 9999 }).at_least_once
+ assert_equal 'localhost:9999', env.default_hostname
+ end
+
end
diff --git a/test/unit/profile_test.rb b/test/unit/profile_test.rb
index 570bef3..dc0e657 100644
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -260,7 +260,7 @@ class ProfileTest < Test::Unit::TestCase
should 'help developers by adding a suitable port to url' do
profile = build(Profile)
- Noosfero.expects(:url_options).returns({ :port => 9999 })
+ Noosfero.stubs(:url_options).returns({ :port => 9999 })
assert profile.url[:port] == 9999, 'Profile#url_options must include port option when running in development mode'
end
--
libgit2 0.21.2