[Git][noosfero/noosfero][master] 3 commits: menu-block: add control panel

Leandro Nunes gitlab at mg.gitlab.com
Mon Feb 13 14:49:45 BRST 2017


Leandro Nunes pushed to branch master at Noosfero / noosfero


Commits:
9b5a500a by Victor Costa at 2017-02-08T09:08:47-03:00
menu-block: add control panel

- - - - -
e894cece by Victor Costa at 2017-02-08T10:11:18-03:00
Define default set of blocks for angular-theme

- - - - -
7fd27fee by Leandro Nunes at 2017-02-13T16:49:39+00:00
Merge branch 'person-default-blocks' into 'master'

Define a new default set of blocks

See merge request !1108
- - - - -


6 changed files:

- app/models/menu_block.rb
- app/models/person.rb
- app/models/theme.rb
- test/unit/menu_block_test.rb
- test/unit/person_test.rb
- test/unit/theme_test.rb


Changes:

=====================================
app/models/menu_block.rb
=====================================
--- a/app/models/menu_block.rb
+++ b/app/models/menu_block.rb
@@ -20,6 +20,7 @@ class MenuBlock < Block
     links << {title: _('Communities'), controller: 'memberships', action: 'index'} if display_communities?(user)
     links << {title: _('People'), controller: 'friends', action: 'index'} if display_friends?(user)
     links << {title: _('People'), controller: 'profile_members', action: 'index'} if display_members?(user)
+    links << {title: _('Control Panel')}.merge(owner.admin_url) if display_control_panel?(user)
     links
   end
 
@@ -33,6 +34,10 @@ class MenuBlock < Block
   end
 
   protected
+
+  def display_control_panel?(user)
+    user && user.has_permission?('edit_profile', owner)
+  end
     
   def display_activities?(user)
     AccessLevels.can_access?(owner.wall_access, user, owner)


=====================================
app/models/person.rb
=====================================
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -377,6 +377,7 @@ class Person < Profile
   end
 
   def default_set_of_blocks
+    return angular_theme_default_set_of_blocks if Theme.angular_theme?(environment.theme)
     links = [
       {:name => _('Profile'), :address => '/profile/{profile}', :icon => 'menu-people'},
       {:name => _('Image gallery'), :address => '/{profile}/gallery', :icon => 'photos'},
@@ -390,6 +391,15 @@ class Person < Profile
     ]
   end
 
+  def angular_theme_default_set_of_blocks
+    @boxes_limit = 2
+    self.layout_template = 'rightbar'
+    [
+      [MenuBlock.new, MainBlock.new],
+      [FriendsBlock.new, CommunitiesBlock.new, TagsBlock.new]
+    ]
+  end
+
   def default_set_of_articles
     [
       Blog.new(:name => _('Blog')),


=====================================
app/models/theme.rb
=====================================
--- a/app/models/theme.rb
+++ b/app/models/theme.rb
@@ -28,6 +28,15 @@ class Theme
       Theme.new(id, attributes).save
     end
 
+    def find_system_theme(theme_id)
+      Theme.system_themes.find { |t| t.id == theme_id }
+    end
+
+    def angular_theme?(theme_id)
+      theme = Theme.find_system_theme(theme_id)
+      !theme.nil? && theme.config['angular_theme']
+    end
+
     def find(the_id)
       if File.directory?(File.join(user_themes_dir, the_id))
         Theme.new(the_id)
@@ -97,6 +106,14 @@ class Theme
     config['public'] = value
   end
 
+  def angular_theme
+    config['angular_theme'] || false
+  end
+
+  def angular_theme=(value)
+    config['angular_theme'] = value
+  end
+
   def public_path
     File.join('/', self.class.relative_themes_dir, self.id)
   end


=====================================
test/unit/menu_block_test.rb
=====================================
--- a/test/unit/menu_block_test.rb
+++ b/test/unit/menu_block_test.rb
@@ -39,12 +39,12 @@ class MenuBlockTest < ActiveSupport::TestCase
   should 'return all community links for an owner' do
     profile.add_admin(person)
     links = block.enabled_links(person)
-    assert_equal ['Activities', 'People'], links.map { |l| l[:title] }
+    assert_equal ['Activities', 'People', 'Control Panel'], links.map { |l| l[:title] }
   end
 
   should 'return all person links for the current person' do
     block.box = create(Box, owner: person)
     links = block.enabled_links(person)
-    assert_equal ['Activities', 'About', 'Communities', 'People'], links.map { |l| l[:title] }
+    assert_equal ['Activities', 'About', 'Communities', 'People', 'Control Panel'], links.map { |l| l[:title] }
   end
 end


=====================================
test/unit/person_test.rb
=====================================
--- a/test/unit/person_test.rb
+++ b/test/unit/person_test.rb
@@ -194,6 +194,19 @@ class PersonTest < ActiveSupport::TestCase
     refute p.boxes[2].blocks.empty?, 'person must have blocks in area 3'
   end
 
+  should 'create a default set of blocks for angular theme' do
+    e = Environment.default
+    e.update_attribute(:theme, 'angular-theme')
+    Theme.expects(:angular_theme?).with('angular-theme').returns(true)
+    p = create(User).person
+
+    assert_equal 2, p.boxes_limit
+    assert_equal 'rightbar', p.layout_template
+    refute p.boxes[0].blocks.empty?, 'person must have blocks in area 1'
+    refute p.boxes[1].blocks.empty?, 'person must have blocks in area 2'
+    assert p.boxes[2].blocks.empty?, 'person must not have blocks in area 3'
+  end
+
   should 'link to all articles created by default' do
     p = create(User).person
     blocks = p.blocks.select { |b| b.is_a?(LinkListBlock) }


=====================================
test/unit/theme_test.rb
=====================================
--- a/test/unit/theme_test.rb
+++ b/test/unit/theme_test.rb
@@ -209,4 +209,17 @@ class ThemeTest < ActiveSupport::TestCase
       assert_not_includes themes, t3
     end
   end
+
+  should 'find system theme by id' do
+    assert_not_nil Theme.find_system_theme('noosfero')
+  end
+
+  should 'return nil when find an invalid system theme' do
+    assert_nil Theme.find_system_theme('noosfero-invalid')
+  end
+
+  should 'return when theme was made for angular' do
+    Theme.expects(:find_system_theme).with('angular').returns(Theme.new('angular', { angular_theme: true }))
+    assert Theme.angular_theme?('angular')
+  end
 end



View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/af6618310ad3afe325b9115a00dc1fdc9ad7e95a...7fd27fee726d1e18cc9a8097d2f0078f481c90bd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20170213/50bd63a6/attachment-0001.html>


More information about the Noosfero-dev mailing list