diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 849fdbe..206486e 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -81,14 +81,11 @@ class CmsController < MyProfileController @type = params[:type] || @article.class.to_s refuse_blocks - if !@article.nil? && @article.blog? || !@type.nil? && @type == 'Blog' - @back_url = url_for(:controller => 'profile_editor', :profile => profile.identifier) - end - record_coming_from_public_view + record_coming if request.post? @article.last_changed_by = user if @article.update_attributes(params[:article]) - redirect_back + redirect_to @article.view_url return end end @@ -99,6 +96,7 @@ class CmsController < MyProfileController # user must choose an article type first + record_coming @type = params[:type] if @type.blank? @article_types = [] @@ -110,12 +108,9 @@ class CmsController < MyProfileController }) end @parent_id = params[:parent_id] - render :action => 'select_article_type', :layout => false + render :action => 'select_article_type', :layout => false, :back_to => @back_to return else - if @type == 'Blog' - @back_url = url_for(:controller => 'profile_editor', :profile => profile.identifier) - end refuse_blocks end @@ -131,13 +126,11 @@ class CmsController < MyProfileController @parent_id = parent.id end - record_creating_from_public_view - @article.profile = profile @article.last_changed_by = user if request.post? if @article.save - redirect_back + redirect_to @article.view_url return end end @@ -159,29 +152,36 @@ class CmsController < MyProfileController @article = @parent = check_parent(params[:parent_id]) @target = @parent ? ('/%s/%s' % [profile.identifier, @parent.full_name]) : '/%s' % profile.identifier @folders = Folder.find(:all, :conditions => { :profile_id => profile }) - record_coming_from_public_view if @article + @media_listing = params[:media_listing] + if @article && !@media_listing + record_coming + end if request.post? && params[:uploaded_files] params[:uploaded_files].each do |file| @uploaded_files << UploadedFile.create(:uploaded_data => file, :profile => profile, :parent => @parent) unless file == '' end @errors = @uploaded_files.select { |f| f.errors.any? } - @back_to = params[:back_to] if @errors.any? - if @back_to && @back_to == 'media_listing' + if @media_listing flash[:notice] = _('Could not upload all files') - redirect_back + redirect_to :action => 'media_listing' else render :action => 'upload_files', :parent_id => @parent_id end else - if params[:back_to] - redirect_back + if @media_listing + flash[:notice] = _('All files were uploaded successfully') + redirect_to :action => 'media_listing' else - redirect_to( if @parent - {:action => 'view', :id => @parent.id} + if @back_to + redirect_to @back_to else - {:action => 'index'} - end) + redirect_to( if @parent + {:action => 'view', :id => @parent.id} + else + {:action => 'index'} + end) + end end end end @@ -212,7 +212,7 @@ class CmsController < MyProfileController def publish @article = profile.articles.find(params[:id]) - record_coming_from_public_view + record_coming @groups = profile.memberships - [profile] @marked_groups = [] groups_ids = profile.memberships.map{|m|m.id.to_s} @@ -233,7 +233,11 @@ class CmsController < MyProfileController end if @failed.blank? flash[:notice] = _("Your publish request was sent successfully") - redirect_back + if @back_to + redirect_to @back_to + else + redirect_to @article.view_url + end end end end @@ -258,7 +262,7 @@ class CmsController < MyProfileController @image_folders = @folders.select {|f| f.children.any? {|c| c.image?} } @document_folders = @folders.select {|f| f.children.any? {|c| !c.image? && c.kind_of?(UploadedFile) } } - @back_to = 'media_listing' + @media_listing = true respond_to do |format| format.html { render :layout => false} @@ -273,42 +277,11 @@ class CmsController < MyProfileController protected - def redirect_back - if params[:back_to] == 'control_panel' - redirect_to :controller => 'profile_editor', :profile => @profile.identifier - elsif params[:back_to] == 'public_view' - redirect_to @article.view_url.merge(Noosfero.url_options) - elsif params[:back_to] == 'media_listing' - redirect_to :action => 'media_listing' - elsif @article.parent - redirect_to :action => 'view', :id => @article.parent - elsif @article.folder? && !@article.blog? && @article.parent - redirect_to :action => 'index' + def record_coming + if request.post? + @back_to = params[:back_to] else - redirect_back_or_default :action => 'index' - end - end - - def record_coming_from_public_view - referer = request.referer - referer.gsub!(/\?.*/, '') unless referer.nil? - if (maybe_ssl(url_for(@article.url)).include?(referer)) || (@article == profile.home_page && maybe_ssl(url_for(profile.url)).include?(referer)) - @back_to = 'public_view' - @back_url = @article.view_url - end - if !request.post? and @article.blog? - store_location(request.referer) - end - end - - def record_creating_from_public_view - referer = request.referer - if (referer =~ Regexp.new("^#{(url_for(profile.url).sub('https:', 'https?:'))}")) || params[:back_to] == 'public_view' - @back_to = 'public_view' - @back_url = referer - end - if !request.post? and @article.blog? - store_location(request.referer) + @back_to = params[:back_to] || request.referer end end diff --git a/app/controllers/public/content_viewer_controller.rb b/app/controllers/public/content_viewer_controller.rb index abcc58e..0c1ab29 100644 --- a/app/controllers/public/content_viewer_controller.rb +++ b/app/controllers/public/content_viewer_controller.rb @@ -67,9 +67,6 @@ class ContentViewerController < ApplicationController return end - # store location if the page is not a download - store_location - @form_div = params[:form] if request.post? && params[:comment] && params[self.icaptcha_field].blank? && params[:confirm] == 'true' && @page.accept_comments? diff --git a/app/controllers/public/invite_controller.rb b/app/controllers/public/invite_controller.rb index 8e94e8f..450d13e 100644 --- a/app/controllers/public/invite_controller.rb +++ b/app/controllers/public/invite_controller.rb @@ -23,7 +23,11 @@ class InviteController < PublicController elsif !contacts_to_invite.empty? Invitation.invite(current_user.person, contacts_to_invite, params[:mail_template], profile) flash[:notice] = _('Your invitations have been sent.') - redirect_back_or_default :controller => 'profile' + if profile.person? + redirect_to :controller => 'friends' + else + redirect_to :controller => 'profile_members' + end else flash.now[:notice] = _('Please enter a valid email address.') end @@ -31,8 +35,6 @@ class InviteController < PublicController @manual_import_addresses = manual_import_addresses || "" @webmail_import_addresses = webmail_import_addresses || [] end - else - store_location(request.referer) end @import_from = params[:import_from] || "manual" @mail_template = params[:mail_template] || environment.invitation_mail_template(profile) diff --git a/app/controllers/public/profile_controller.rb b/app/controllers/public/profile_controller.rb index 316be4c..2540a57 100644 --- a/app/controllers/public/profile_controller.rb +++ b/app/controllers/public/profile_controller.rb @@ -83,10 +83,9 @@ class ProfileController < PublicController redirect_to_before_join end else - store_location(request.referer) if current_user.person.memberships.include?(profile) flash[:notice] = _('You are already a member of "%s"') % profile.name - redirect_back_or_default profile.url + redirect_to profile.url return end if request.xhr? @@ -97,15 +96,16 @@ class ProfileController < PublicController def leave @wizard = params[:wizard] + @back_to = params[:back_to] || request.referer if request.post? && params[:confirmation] profile.remove_member(current_user.person) if @wizard redirect_to :controller => 'search', :action => 'assets', :asset => 'communities', :wizard => true else - redirect_back_or_default profile.url + back = @back_to || profile.url + redirect_to back end else - store_location(request.referer) if request.xhr? render :layout => false end @@ -146,7 +146,9 @@ class ProfileController < PublicController end def store_before_join - session[:before_join] = request.referer unless logged_in? + if session[:before_join].nil? + session[:before_join] = request.referer + end end def redirect_to_before_join @@ -155,7 +157,7 @@ class ProfileController < PublicController session[:before_join] = nil redirect_to back else - redirect_back_or_default profile.url + redirect_to profile.url end end diff --git a/app/models/profile.rb b/app/models/profile.rb index 2e22541..b7b39b7 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -383,7 +383,7 @@ class Profile < ActiveRecord::Base def url_options options = { :host => default_hostname, :profile => (own_hostname ? nil : self.identifier) } - options.merge(Noosfero.url_options.merge(options)) + options.merge(Noosfero.url_options) end private :generate_url, :url_options diff --git a/app/views/cms/_upload_file_form.rhtml b/app/views/cms/_upload_file_form.rhtml index dcf7141..2e3b0f8 100644 --- a/app/views/cms/_upload_file_form.rhtml +++ b/app/views/cms/_upload_file_form.rhtml @@ -15,10 +15,10 @@ <% button_bar do %> <%= add_upload_file_field(_('More files'), {:size => size}) %> - <% if @back_to == 'media_listing' %> + <% if @media_listing %> <%= submit_button :save, _('Upload') %> - <% elsif @back_url %> - <%= submit_button :save, _('Upload'), :cancel => @back_url %> + <% elsif @back_to %> + <%= submit_button :save, _('Upload'), :cancel => @back_to %> <% else %> <%= submit_button :save, _('Upload'), :cancel => {:action => (@parent ? 'view' : 'index'), :id => @parent } %> <% end %> diff --git a/app/views/cms/edit.rhtml b/app/views/cms/edit.rhtml index aee8956..3bebf61 100644 --- a/app/views/cms/edit.rhtml +++ b/app/views/cms/edit.rhtml @@ -37,10 +37,8 @@ <% button_bar do %> <%= submit_button :save, _('Save') %> - <% if @return_to %> - <%= button :cancel, _('Cancel'), @return_to %> - <% elsif @back_url %> - <%= button :cancel, _('Cancel'), @back_url %> + <% if @back_to %> + <%= button :cancel, _('Cancel'), @back_to %> <% elsif @parent_id || @article.parent %> <%= button :cancel, _('Cancel'), :action => 'view', :id => @parent_id || @article.parent %> <% else %> diff --git a/app/views/cms/media_listing.rhtml b/app/views/cms/media_listing.rhtml index ae510f8..331f375 100644 --- a/app/views/cms/media_listing.rhtml +++ b/app/views/cms/media_listing.rhtml @@ -39,7 +39,7 @@ <% form_for('uploaded_file', :url => {:action => 'upload_files'}, :html => {:multipart => true}) do |f| %> - <%= hidden_field_tag('back_to', @back_to) %> + <%= hidden_field_tag('media_listing', @media_listing) %> <%= render :partial => 'upload_file_form', :locals => { :size => '30' } %> <% end %> diff --git a/app/views/cms/publish.rhtml b/app/views/cms/publish.rhtml index ef429f3..fd06f54 100644 --- a/app/views/cms/publish.rhtml +++ b/app/views/cms/publish.rhtml @@ -26,7 +26,7 @@ <% end %> <% button_bar do %> - <%= submit_button 'spread', _('Publish') %> + <%= submit_button 'spread', _('Publish'), :cancel => @back_to %> <% end %> <% end %> <% else %> diff --git a/app/views/cms/select_article_type.rhtml b/app/views/cms/select_article_type.rhtml index 6121063..2534d13 100644 --- a/app/views/cms/select_article_type.rhtml +++ b/app/views/cms/select_article_type.rhtml @@ -3,7 +3,7 @@