[Git][noosfero/noosfero][master] 2 commits: Extracting duplicate code in products and push_notification plugins

Rodrigo Souto gitlab at mg.gitlab.com
Thu Jun 29 12:35:52 BRT 2017


Rodrigo Souto pushed to branch master at Noosfero / noosfero


Commits:
99441c1e by Victor Navarro at 2017-06-28T22:03:15-03:00
Extracting duplicate code in products and push_notification plugins

- - - - -
0201cfb3 by Rodrigo Souto at 2017-06-29T13:03:10+00:00
Merge branch 'solid_mes' into 'master'

Removing code duplication in Products and Push Notification plugins.

See merge request !1260
- - - - -


7 changed files:

- plugins/products/controllers/profile/products_plugin/catalog_controller.rb
- plugins/products/controllers/profile/products_plugin/page_controller.rb
- plugins/products/controllers/public/products_plugin/search_controller.rb
- plugins/products/lib/products_plugin/products_helper.rb
- plugins/push_notification/lib/push_notification_plugin/observers/approve_article_observer.rb
- + plugins/push_notification/lib/push_notification_plugin/observers/observers_helper.rb
- plugins/push_notification/lib/push_notification_plugin/observers/suggest_article_observer.rb


Changes:

=====================================
plugins/products/controllers/profile/products_plugin/catalog_controller.rb
=====================================
--- a/plugins/products/controllers/profile/products_plugin/catalog_controller.rb
+++ b/plugins/products/controllers/profile/products_plugin/catalog_controller.rb
@@ -16,12 +16,5 @@ module ProductsPlugin
       redirect_to controller: 'profile', profile: profile.identifier, action: 'index'
     end
 
-    # inherit routes from core skipping use_relative_controller!
-    def url_for options
-      options[:controller] = "/#{options[:controller]}" if options.is_a? Hash and options[:controller] and not options[:controller].to_s.starts_with? '/'
-      super options
-    end
-    helper_method :url_for
-
   end
 end


=====================================
plugins/products/controllers/profile/products_plugin/page_controller.rb
=====================================
--- a/plugins/products/controllers/profile/products_plugin/page_controller.rb
+++ b/plugins/products/controllers/profile/products_plugin/page_controller.rb
@@ -220,12 +220,5 @@ module ProductsPlugin
       end
     end
 
-    # inherit routes from core skipping use_relative_controller!
-    def url_for options
-      options[:controller] = "/#{options[:controller]}" if options.is_a? Hash and options[:controller] and not options[:controller].to_s.starts_with? '/'
-      super options
-    end
-    helper_method :url_for
-
   end
 end


=====================================
plugins/products/controllers/public/products_plugin/search_controller.rb
=====================================
--- a/plugins/products/controllers/public/products_plugin/search_controller.rb
+++ b/plugins/products/controllers/public/products_plugin/search_controller.rb
@@ -8,14 +8,5 @@ module ProductsPlugin
       full_text_search
     end
 
-    protected
-
-    # inherit routes from core skipping use_relative_controller!
-    def url_for options
-      options[:controller] = "/#{options[:controller]}" if options.is_a? Hash and options[:controller] and not options[:controller].to_s.starts_with? '/'
-      super options
-    end
-    helper_method :url_for
-
   end
 end


=====================================
plugins/products/lib/products_plugin/products_helper.rb
=====================================
--- a/plugins/products/lib/products_plugin/products_helper.rb
+++ b/plugins/products/lib/products_plugin/products_helper.rb
@@ -1,5 +1,10 @@
 module ProductsPlugin::ProductsHelper
 
+  def url_for options
+    options[:controller] = "/#{options[:controller]}" if options.is_a? Hash and options[:controller] and not options[:controller].to_s.starts_with? '/'
+    super options
+  end
+
   protected
 
   def product_path(product)
@@ -316,4 +321,5 @@ module ProductsPlugin::ProductsHelper
     _("%{currency} %{production_cost} of %{currency} %{product_price}").html_safe % {currency: currency, production_cost: content_tag('span', production_cost, class: 'production_cost'), product_price: content_tag('span', product_price, class: 'product_price')}
   end
 
+
 end


=====================================
plugins/push_notification/lib/push_notification_plugin/observers/approve_article_observer.rb
=====================================
--- a/plugins/push_notification/lib/push_notification_plugin/observers/approve_article_observer.rb
+++ b/plugins/push_notification/lib/push_notification_plugin/observers/approve_article_observer.rb
@@ -1,14 +1,11 @@
 module PushNotificationPlugin::Observers
+
+  include ObserversHelper
+
   module ApproveArticleObserver
     def approve_article_after_create_callback(approve_article)
-      requestor = approve_article.requestor
-      target = approve_article.target
-
-      if target.person?
-        users = [target.user]
-      elsif target.organization?
-        users = target.admins.map{|person| person.user}
-      end
+      target, requestor = get_target_and_requestor approve_article
+      users = get_users_info target
 
       send_to_users("approve_article",
                     users,


=====================================
plugins/push_notification/lib/push_notification_plugin/observers/observers_helper.rb
=====================================
--- /dev/null
+++ b/plugins/push_notification/lib/push_notification_plugin/observers/observers_helper.rb
@@ -0,0 +1,15 @@
+module PushNotificationPlugin::Observers::ObserversHelper
+
+  def get_target_and_requestor(article)
+    target = article.target, requestor = article.requestor
+  end
+
+  def get_users_info(target)
+    if target.person?
+      users = [target.user]
+    elsif target.organization?
+      users = target.admins.map{|person| person.user}
+    end
+  end
+
+end


=====================================
plugins/push_notification/lib/push_notification_plugin/observers/suggest_article_observer.rb
=====================================
--- a/plugins/push_notification/lib/push_notification_plugin/observers/suggest_article_observer.rb
+++ b/plugins/push_notification/lib/push_notification_plugin/observers/suggest_article_observer.rb
@@ -1,14 +1,11 @@
 module PushNotificationPlugin::Observers
+
+  include ObserversHelper
+
   module SuggestArticleObserver
     def suggest_article_after_create_callback(suggest_article)
-      requestor = suggest_article.requestor
-      target = suggest_article.target
-
-      if target.person?
-        users = [target.user]
-      elsif target.organization?
-        users = target.admins.map{|person| person.user}
-      end
+      target, requestor = get_target_and_requestor suggest_article
+      users = get_users_info target
 
       send_to_users("suggest_article",
                     users,



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/f335ae3a65b792cdf18f4107d13ed763ab37e2f2...0201cfb3290d834812a0e0dce04ab67ae0b81a2f

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/f335ae3a65b792cdf18f4107d13ed763ab37e2f2...0201cfb3290d834812a0e0dce04ab67ae0b81a2f
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170629/2686e7f5/attachment-0001.html>


More information about the Noosfero-dev mailing list