diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0e21a96..9cc1c7a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -8,6 +8,8 @@ module ApplicationHelper include PermissionNameHelper + include UrlHelper + include ModalHelper include BoxesHelper diff --git a/app/helpers/url_helper.rb b/app/helpers/url_helper.rb new file mode 100644 index 0000000..01fb3a7 --- /dev/null +++ b/app/helpers/url_helper.rb @@ -0,0 +1,7 @@ +module UrlHelper + + def back_url + 'javascript:history.back()' + end + +end diff --git a/app/models/article.rb b/app/models/article.rb index 6ac31e0..73df0ac 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -789,7 +789,7 @@ class Article < ActiveRecord::Base end def activity - ActionTracker::Record.find_by_target_type_and_target_id 'Article', self.id + ActionTracker::Record.where(target_type: 'Article', target_id: self.id).first end def create_activity diff --git a/app/models/environment.rb b/app/models/environment.rb index ca13af3..a563760 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -960,7 +960,7 @@ class Environment < ActiveRecord::Base end def highlighted_products_with_image(options = {}) - self.products.where(highlighted: true).joins(:image) + self.products.where(highlighted: true).joins(:image).order('created_at ASC') end settings_items :home_cache_in_minutes, :type => :integer, :default => 5 diff --git a/app/models/event.rb b/app/models/event.rb index dbcb332..cfa63ea 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -36,7 +36,7 @@ class Event < Article scope :by_day, -> (date) { where('start_date >= :start_date AND start_date <= :end_date AND end_date IS NULL OR (start_date <= :end_date AND end_date >= :start_date)', - {:start_date => date.beginning_of_day, :end_date => date.end_of_day}). + start_date: date.beginning_of_day, end_date: date.end_of_day). order('start_date ASC') } diff --git a/plugins/driven_signup/Gemfile b/plugins/driven_signup/Gemfile new file mode 100644 index 0000000..78209f7 --- /dev/null +++ b/plugins/driven_signup/Gemfile @@ -0,0 +1,2 @@ +gem 'slim' + diff --git a/plugins/driven_signup/controllers/public/driven_signup_plugin/account_controller.rb b/plugins/driven_signup/controllers/public/driven_signup_plugin/account_controller.rb index 3d3afca..de37355 100644 --- a/plugins/driven_signup/controllers/public/driven_signup_plugin/account_controller.rb +++ b/plugins/driven_signup/controllers/public/driven_signup_plugin/account_controller.rb @@ -25,9 +25,11 @@ class DrivenSignupPlugin::AccountController < PublicController protected - def default_url_options - # avoid rails' use_relative_controller! - {use_route: '/'} + # inherit routes from core skipping use_relative_controller! + def url_for options + options[:controller] = "/#{options[:controller]}" if options.is_a? Hash + super options end + helper_method :url_for end diff --git a/plugins/driven_signup/test/functional/account_controller_test.rb b/plugins/driven_signup/test/functional/account_controller_test.rb deleted file mode 100644 index 8b901e9..0000000 --- a/plugins/driven_signup/test/functional/account_controller_test.rb +++ /dev/null @@ -1,45 +0,0 @@ -require 'test_helper' - -# Re-raise errors caught by the controller. -class AccountController; def rescue_action(e) raise e end; end - -class AccountControllerTest < ActionController::TestCase - - def setup - @controller = AccountController.new - @request = ActionController::TestRequest.new - @response = ActionController::TestResponse.new - - e = Environment.default - e.enable 'skip_new_user_email_confirmation', true - disable_signup_bot_check e - end - - should 'use the parameters' do - community = create Community, name: 'base', identifier: 'base1' - subcommunity = create Community, name: 'sub', identifier: 'base11' - subcommunity.reload - - # simulate DrivenSignupPlugin::AccountController - session[:driven_signup] = true - session[:base_organization] = community.identifier - session[:find_suborganization] = true - session[:suborganization_members_limit] = 50 - - post :signup, user: {login: 'quire', password: 'quire', password_confirmation: 'quire', name: 'quire', email: 'test@example.com'} - assert_response :redirect - assert_redirected_to subcommunity.url - - user = Profile['quire'] - assert user - assert_includes subcommunity.members, user - end - - private - - def disable_signup_bot_check environment = Environment.default - environment.min_signup_delay = 0 - environment.save! - end - -end diff --git a/plugins/driven_signup/test/integration/account_controller_test.rb b/plugins/driven_signup/test/integration/account_controller_test.rb new file mode 100644 index 0000000..1dd6fe4 --- /dev/null +++ b/plugins/driven_signup/test/integration/account_controller_test.rb @@ -0,0 +1,44 @@ +require 'test_helper' + +# Re-raise errors caught by the controller. +class AccountController; def rescue_action(e) raise e end; end + +class AccountControllerTest < ActionDispatch::IntegrationTest + + def setup + @controller = AccountController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + e = Environment.default + e.enable 'skip_new_user_email_confirmation', true + disable_signup_bot_check e + end + + should 'use the parameters' do + token = '131324' + Environment.default.driven_signup_auths.create! token: token + community = create Community, name: 'base', identifier: 'base1' + subcommunity = create Community, name: 'sub', identifier: 'base11' + subcommunity.reload + + # simulate DrivenSignupPlugin::AccountController + session[:driven_signup] = true + session[:base_organization] = community.identifier + session[:find_suborganization] = true + session[:suborganization_members_limit] = 50 + + post url_for(controller: 'driven_signup_plugin/account', action: :signup, token: token, signup: {login: 'quire', name: 'quire', email: 'test@example.com'}) + assert_response :redirect + assert_redirected_to url_for(controller: '/account', action: :signup, user: {login: 'quire', email: 'test@example.com',}, + profile_data: {name: 'quire'}) + end + + private + + def disable_signup_bot_check environment = Environment.default + environment.min_signup_delay = 0 + environment.save! + end + +end diff --git a/plugins/fb_app/controllers/public/fb_app_plugin_page_tab_controller.rb b/plugins/fb_app/controllers/public/fb_app_plugin_page_tab_controller.rb index 39c2239..142a23e 100644 --- a/plugins/fb_app/controllers/public/fb_app_plugin_page_tab_controller.rb +++ b/plugins/fb_app/controllers/public/fb_app_plugin_page_tab_controller.rb @@ -88,7 +88,7 @@ class FbAppPluginPageTabController < FbAppPluginController end def enterprise_search - scope = environment.enterprises.enabled.public + scope = environment.enterprises.enabled.is_public @query = params[:query] @profiles = scope.limit(10).order('name ASC'). where(['name ILIKE ? OR name ILIKE ? OR identifier LIKE ?', "#{@query}%", "% #{@query}%", "#{@query}%"]) diff --git a/plugins/oauth_client/lib/ext/profile.rb b/plugins/oauth_client/lib/ext/profile.rb index b0ca647..c657b89 100644 --- a/plugins/oauth_client/lib/ext/profile.rb +++ b/plugins/oauth_client/lib/ext/profile.rb @@ -1,8 +1,10 @@ require_dependency 'profile' -class Profile +Profile.descendants.each do |subclass| + subclass.class_eval do - has_many :oauth_auths, class_name: 'OauthClientPlugin::Auth', dependent: :destroy - has_many :oauth_providers, through: :oauth_auths, source: :provider + has_many :oauth_auths, foreign_key: :profile_id, class_name: 'OauthClientPlugin::Auth', dependent: :destroy + has_many :oauth_providers, through: :oauth_auths, source: :provider + end end diff --git a/plugins/open_graph/controllers/myprofile/open_graph_plugin/myprofile_controller.rb b/plugins/open_graph/controllers/myprofile/open_graph_plugin/myprofile_controller.rb index 5603be9..c10f15a 100644 --- a/plugins/open_graph/controllers/myprofile/open_graph_plugin/myprofile_controller.rb +++ b/plugins/open_graph/controllers/myprofile/open_graph_plugin/myprofile_controller.rb @@ -4,11 +4,11 @@ class OpenGraphPlugin::MyprofileController < MyProfileController before_filter :set_context def enterprise_search - scope = environment.enterprises.enabled.public + scope = environment.enterprises.enabled.is_public profile_search scope end def community_search - scope = environment.communities.public + scope = environment.communities.is_public profile_search scope end def friend_search @@ -38,10 +38,13 @@ class OpenGraphPlugin::MyprofileController < MyProfileController OpenGraphPlugin.context = self.context end - def default_url_options - # avoid rails' use_relative_controller! - {use_route: '/'} + # inherit routes from core skipping use_relative_controller! + def url_for options + options[:controller] = "/#{options[:controller]}" if options.is_a? Hash + super options end + helper_method :url_for + end diff --git a/plugins/open_graph/lib/ext/profile.rb b/plugins/open_graph/lib/ext/profile.rb index 09e144f..cd0fe06 100644 --- a/plugins/open_graph/lib/ext/profile.rb +++ b/plugins/open_graph/lib/ext/profile.rb @@ -7,11 +7,21 @@ Profile.descendants.each do |subclass| subclass.class_eval do attr_accessible :open_graph_settings + has_many :open_graph_tracks, class_name: 'OpenGraphPlugin::Track', source: :tracker_id, foreign_key: :tracker_id + + has_many :open_graph_activities, class_name: 'OpenGraphPlugin::Activity', source: :tracker_id, foreign_key: :tracker_id + + has_many :open_graph_track_configs, class_name: 'OpenGraphPlugin::TrackConfig', source: :tracker_id, foreign_key: :tracker_id + OpenGraphPlugin::TrackConfig::Types.each do |track, klass| klass = "OpenGraphPlugin::#{klass}".constantize attributes = "#{klass.association}_attributes" profile_ids = "open_graph_#{track}_profiles_ids" + association = klass.association + has_many association, class_name: klass.name, foreign_key: :tracker_id + accepts_nested_attributes_for association, allow_destroy: true, reject_if: :open_graph_reject_empty_object_type + attr_accessible attributes attr_accessible profile_ids end @@ -27,19 +37,11 @@ class Profile end alias_method :open_graph_settings=, :open_graph_settings - has_many :open_graph_tracks, class_name: 'OpenGraphPlugin::Track', source: :tracker_id, foreign_key: :tracker_id - - has_many :open_graph_activities, class_name: 'OpenGraphPlugin::Activity', source: :tracker_id, foreign_key: :tracker_id - - has_many :open_graph_track_configs, class_name: 'OpenGraphPlugin::TrackConfig', source: :tracker_id, foreign_key: :tracker_id OpenGraphPlugin::TrackConfig::Types.each do |track, klass| klass = "OpenGraphPlugin::#{klass}".constantize association = klass.association profile_ids = "open_graph_#{track}_profiles_ids" - has_many association, class_name: klass.name, foreign_key: :tracker_id - accepts_nested_attributes_for association, allow_destroy: true, reject_if: :open_graph_reject_empty_object_type - define_method "#{profile_ids}=" do |ids| cids = self.send(association).order('created_at ASC').map(&:object_data_id) nids = if ids.is_a? Array then ids else ids.split ',' end diff --git a/plugins/open_graph/lib/open_graph_plugin/settings.rb b/plugins/open_graph/lib/open_graph_plugin/settings.rb index 9bf7970..55095d5 100644 --- a/plugins/open_graph/lib/open_graph_plugin/settings.rb +++ b/plugins/open_graph/lib/open_graph_plugin/settings.rb @@ -6,7 +6,7 @@ class OpenGraphPlugin::Settings < Noosfero::Plugin::Settings OpenGraphPlugin::TrackConfig::Types.each do |track, klass| define_method "#{track}_track_enabled=" do |value| - super ActiveRecord::ConnectionAdapters::Column.value_to_boolean(value) + super ActiveRecord::Type::Boolean.new.send :cast_value, value end end diff --git a/plugins/open_graph/models/open_graph_plugin/enterprise_track_config.rb b/plugins/open_graph/models/open_graph_plugin/enterprise_track_config.rb index 3138559..38a995f 100644 --- a/plugins/open_graph/models/open_graph_plugin/enterprise_track_config.rb +++ b/plugins/open_graph/models/open_graph_plugin/enterprise_track_config.rb @@ -14,7 +14,7 @@ class OpenGraphPlugin::EnterpriseTrackConfig < OpenGraphPlugin::TrackConfig end def self.profile_track_objects profile - (profile.enterprises.public.enabled + profile.favorite_enterprises.public.enabled).uniq + (profile.enterprises.is_public.enabled + profile.favorite_enterprises.is_public.enabled).uniq end end diff --git a/plugins/open_graph/views/open_graph_plugin/myprofile/_track_enterprise.html.erb b/plugins/open_graph/views/open_graph_plugin/myprofile/_track_enterprise.html.erb index 481ffb5..b6f0e1c 100644 --- a/plugins/open_graph/views/open_graph_plugin/myprofile/_track_enterprise.html.erb +++ b/plugins/open_graph/views/open_graph_plugin/myprofile/_track_enterprise.html.erb @@ -13,7 +13,7 @@ <%= t('open_graph_plugin.views.track.config.enterprise.memberships') %>