[Git][noosfero/noosfero][master] 2 commits: cms-controller and work_assignment_plugin_myprofile_controller now using a…

Rodrigo Souto gitlab at mg.gitlab.com
Thu Oct 5 09:21:52 BRT 2017


Rodrigo Souto pushed to branch master at Noosfero / noosfero


Commits:
e5a50b03 by Euler at 2017-06-27T16:37:22-03:00
cms-controller and work_assignment_plugin_myprofile_controller now using a single method search_article_privacy_exceptions my_profile_controller

- - - - -
3a2cf221 by Rodrigo Souto at 2017-10-05T12:21:39+00:00
Merge branch 'solid_euler_e' into 'master'

Applied SOLID principles

See merge request noosfero/noosfero!1267
- - - - -


6 changed files:

- app/controllers/my_profile/cms_controller.rb
- app/controllers/my_profile_controller.rb
- app/models/community.rb
- app/models/organization.rb
- plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb
- test/unit/organization_test.rb


Changes:

=====================================
app/controllers/my_profile/cms_controller.rb
=====================================
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -364,12 +364,6 @@ class CmsController < MyProfileController
     render :text => article_list_to_json(results).html_safe, :content_type => 'application/json'
   end
 
-  def search_article_privacy_exceptions
-    arg = params[:q].downcase
-    result = profile.members.where('LOWER(name) LIKE ?', "%#{arg}%")
-    render :text => prepare_to_token_input(result).to_json
-  end
-
   def media_upload
     parent = check_parent(params[:parent_id])
     if request.post?


=====================================
app/controllers/my_profile_controller.rb
=====================================
--- a/app/controllers/my_profile_controller.rb
+++ b/app/controllers/my_profile_controller.rb
@@ -13,7 +13,7 @@ class MyProfileController < ApplicationController
   #
   # The above controller will reject every request to it unless the current
   # profile (as indicated by the first URL component) is of class Person (or of
-  # a subclass of Person) 
+  # a subclass of Person)
   def self.requires_profile_class(some_class)
     before_filter do |controller|
       unless controller.send(:profile).kind_of?(some_class)
@@ -22,4 +22,10 @@ class MyProfileController < ApplicationController
     end
   end
 
+  def search_article_privacy_exceptions
+    arg = params[:q].downcase
+    result = profile.members.where('LOWER(name) LIKE ?', "%#{arg}%")
+    render :text => prepare_to_token_input(result).to_json
+  end
+
 end


=====================================
app/models/community.rb
=====================================
--- a/app/models/community.rb
+++ b/app/models/community.rb
@@ -94,13 +94,9 @@ class Community < Organization
 
   def default_set_of_blocks
     return angular_theme_default_set_of_blocks if Theme.angular_theme?(environment.theme)
-    links = [
-      {:name => _('Community\'s profile'), :address => '/profile/{profile}', :icon => 'ok'},
-      {:name => _('Invite Friends'), :address => '/profile/{profile}/invite/friends', :icon => 'send'},
-      {:name => _('Agenda'), :address => '/profile/{profile}/events', :icon => 'event'},
-      {:name => _('Image gallery'), :address => '/{profile}/gallery', :icon => 'photos'},
-      {:name => _('Blog'), :address => '/{profile}/blog', :icon => 'edit'},
-    ]
+
+    links = set_links
+
     [
       [MainBlock.new],
       [ProfileImageBlock.new(:show_name => true), LinkListBlock.new(:links => links), RecentDocumentsBlock.new]


=====================================
app/models/organization.rb
=====================================
--- a/app/models/organization.rb
+++ b/app/models/organization.rb
@@ -159,7 +159,7 @@ class Organization < Profile
     true
   end
 
-  def default_set_of_blocks
+  def set_links
     links = [
       {:name => _("Community's profile"), :address => '/profile/{profile}', :icon => 'ok'},
       {:name => _('Invite Friends'), :address => '/profile/{profile}/invite/friends', :icon => 'send'},
@@ -167,6 +167,10 @@ class Organization < Profile
       {:name => _('Image gallery'), :address => '/{profile}/gallery', :icon => 'photos'},
       {:name => _('Blog'), :address => '/{profile}/blog', :icon => 'edit'},
     ]
+  end
+
+  def default_set_of_blocks
+    links = set_links
     [
       [MainBlock.new],
       [ProfileImageBlock.new, LinkListBlock.new(:links => links)],


=====================================
plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb
=====================================
--- a/plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb
+++ b/plugins/work_assignment/controllers/work_assignment_plugin_myprofile_controller.rb
@@ -20,12 +20,6 @@ def edit_visibility
   end
  end
 
-  def search_article_privacy_exceptions
-    arg = params[:q].downcase
-    result = profile.members.where('LOWER(name) LIKE ?', "%#{arg}%")
-    render :text => prepare_to_token_input(result).to_json
-  end
-
   protected
 
   def protect_if


=====================================
test/unit/organization_test.rb
=====================================
--- a/test/unit/organization_test.rb
+++ b/test/unit/organization_test.rb
@@ -32,6 +32,22 @@ class OrganizationTest < ActiveSupport::TestCase
     end
   end
 
+  should 'set links correctly' do
+    org = Organization.new
+    links = org.set_links
+    assert_not_nil links
+  end
+
+  should 'have the same behaviour' do
+    org = Organization.new
+    blocks = org.default_set_of_blocks
+
+    links = blocks[1][1].settings[:links]
+    links_by_set_links = org.set_links
+
+    assert_equal links, links_by_set_links
+  end
+
   should 'reference region' do
     org = Organization.new
     assert_raise ActiveRecord::AssociationTypeMismatch do



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/796a915fcd90c8a7408194e66133640080386344...3a2cf2215a6d1396f8c7f45f0df1f3d464327a78

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/796a915fcd90c8a7408194e66133640080386344...3a2cf2215a6d1396f8c7f45f0df1f3d464327a78
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/20171005/2c992022/attachment-0001.html>


More information about the Noosfero-dev mailing list