noosfero | 2 new commits pushed to repository

Antonio Terceiro gitlab at gitlab.com
Tue Jan 20 17:52:41 BRST 2015


Antonio Terceiro pushed to refs/heads/master at <a href="https://gitlab.com/noosfero/noosfero">Noosfero / noosfero</a>

Commits:
<a href="https://gitlab.com/noosfero/noosfero/commit/6984558b1999dee376d38ced3deee8dfbca83ee7">6984558b</a> by Fabio Teixeira
Add UI to activate and deactivate profiles

(ActionItem3287)
It can be done while edit a profile or in environment administration panel

Signed-off-by: Arthur Del Esposte <arthurmde at gmail.com>
Signed-off-by: David Carlos <ddavidcarlos1392 at gmail.com>
Signed-off-by: Fabio Teixeira <fabio1079 at gmail.com>
Signed-off-by: Gabriela Navarro <navarro1703 at gmail.com>
Signed-off-by: Gustavo Jaruga <darksshades at gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr at gmail.com>
Signed-off-by: Parley Martins <parley at outlook.com>

- - - - -
<a href="https://gitlab.com/noosfero/noosfero/commit/46080e93ec7a770880da1bd5c79b67ca0f5f70ae">46080e93</a> by Antonio Terceiro
Merge branch 'AI3287_deactive_and_active_profile' into 'master'

Ai3287 deactive and active profile

Feature: https://noosfero.org/Development/ActionItem3287

This patch add the activate/deactivate feature for organizations. It also add a new administrator feature to manage organizations status in admin pannel.

See merge request !357

- - - - -


Changes:

=====================================
app/controllers/admin/admin_panel_controller.rb
=====================================
--- a/app/controllers/admin/admin_panel_controller.rb
+++ b/app/controllers/admin/admin_panel_controller.rb
@@ -71,4 +71,22 @@ class AdminPanelController < AdminController
       end
     end
   end
+
+  def manage_organizations_status
+    scope = environment.organizations
+    @filter = params[:filter] || 'any'
+    @title = "Organization profiles"
+    @title = @title+" - "+ at filter if @filter != 'any'
+
+    if @filter == 'enabled'
+      scope = scope.visible
+    elsif @filter == 'disabled'
+      scope = scope.disabled
+    end
+
+    scope = scope.order('name ASC')
+
+    @q = params[:q]
+    @collection = find_by_contents(:organizations, scope, @q, {:per_page => 10, :page => params[:npage]})[:results]
+  end
 end

=====================================
app/controllers/my_profile/profile_editor_controller.rb
=====================================
--- a/app/controllers/my_profile/profile_editor_controller.rb
+++ b/app/controllers/my_profile/profile_editor_controller.rb
@@ -74,10 +74,51 @@ class ProfileEditorController < MyProfileController
     if request.post?
       if @profile.destroy
         session[:notice] = _('The profile was deleted.')
-        redirect_to :controller => 'home'
+        if(params[:return_to])
+          redirect_to params[:return_to]
+        else
+          redirect_to :controller => 'home'
+        end
       else
         session[:notice] = _('Could not delete profile')
       end
     end
   end
+
+  def deactivate_profile
+    if environment.admins.include?(current_person)
+      profile = environment.profiles.find(params[:id])
+      if profile.disable
+        profile.save
+        session[:notice] = _("The profile '#{profile.name}' was deactivated.")
+      else
+        session[:notice] = _('Could not deactivate profile.')
+      end
+    end
+
+    redirect_to_previous_location
+  end
+
+  def activate_profile
+    if environment.admins.include?(current_person)
+      profile = environment.profiles.find(params[:id])
+
+      if profile.enable
+        session[:notice] = _("The profile '#{profile.name}' was activated.")
+      else
+        session[:notice] = _('Could not activate the profile.')
+      end
+    end
+
+    redirect_to_previous_location
+  end
+
+  protected
+
+  def redirect_to_previous_location
+    back = request.referer
+    back = "/" if back.nil?
+
+    redirect_to back
+  end
 end

=====================================
app/models/enterprise.rb
=====================================
--- a/app/models/enterprise.rb
+++ b/app/models/enterprise.rb
@@ -97,7 +97,12 @@ class Enterprise < Organization
     self.tasks.where(:type => 'EnterpriseActivation').first
   end
 
-  def enable(owner)
+  def enable(owner = nil)
+    if owner.nil?
+      self.visible = true
+      return self.save
+    end
+
     return if enabled
     # must be set first for the following to work
     self.enabled = true

=====================================
app/models/profile.rb
=====================================
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -121,6 +121,7 @@ class Profile < ActiveRecord::Base
   end
 
   scope :visible, :conditions => { :visible => true }
+  scope :disabled, :conditions => { :visible => false }
   scope :public, :conditions => { :visible => true, :public_profile => true }
 
   # Subclasses must override this method
@@ -775,7 +776,7 @@ private :generate_url, :url_options
   end
 
   include Noosfero::Plugin::HotSpot
-  
+
   def folder_types
     types = Article.folder_types
     plugins.dispatch(:content_types).each {|type|
@@ -899,6 +900,13 @@ private :generate_url, :url_options
   end
 
   def disable
+    self.visible = false
+    self.save
+  end
+
+  def enable
+    self.visible = true
+    self.save
   end
 
   def control_panel_settings_button

=====================================
app/views/admin_panel/index.html.erb
=====================================
--- a/app/views/admin_panel/index.html.erb
+++ b/app/views/admin_panel/index.html.erb
@@ -20,6 +20,7 @@
   <tr><td><%= link_to _('Users'), :controller => 'users' %></td></tr>
   <tr><td><%= link_to _('Profile templates'), :controller => 'templates' %></td></tr>
   <tr><td><%= link_to _('Fields'), :controller => 'features', :action => 'manage_fields' %></td></tr>
+  <tr><td><%= link_to _('Manage organizations status'), :action => 'manage_organizations_status' %></td></tr>
 </table>
 
 

=====================================
app/views/admin_panel/manage_organizations_status.html.erb
=====================================
--- /dev/null
+++ b/app/views/admin_panel/manage_organizations_status.html.erb
@@ -0,0 +1,69 @@
+<h1><%= _('Manage organizations') %></h1>
+
+<%= form_tag( { :action => 'manage_organizations_status' }, :method => 'get', :class => 'users-search' ) do %>
+
+  <div class="search-field">
+    <span class="formfield">
+      <%= text_field_tag 'q', @q, :title => _("Find profiles"), :style=>"width:85%" %>
+    </span>
+
+    <%= submit_button(:search, _('Search')) %>
+  </div>
+
+  <div class="environment-users-results-header">
+    <div id='environment-users-filter-title'><%= @title %></div>
+
+    <div id="environment-users-filter-filter">
+      <strong><%= _("Filter by: ") %></strong>
+
+      <select id="profile_filter_select">
+        <%= options_for_select([['Any', 'any'],["Disabled profiles", "disabled"], ["Enabled profiles", "enabled"]], @filter) %>
+      </select>
+    </div>
+    <div style="clear: both"></div>
+  </div>
+
+  <table>
+    <colgroup>
+      <col width="80%">
+      <col width="20%">
+    </colgroup>
+
+    <tr>
+      <th><%= _('Member') %></th>
+      <th><%= _('Actions') %></th>
+    </tr>
+
+    <% @collection.each do |p| %>
+      <tr title="<%= p.name %>">
+        <td><%= link_to_profile p.short_name, p.identifier, :title => p.name %> </td>
+
+        <td class='actions'>
+          <div class="members-buttons-cell">
+            <% if p.visible %>
+              <%= button_without_text :'deactivate-user', _('Deactivate'), {:controller => "profile_editor", :action => 'deactivate_profile', :profile => p.identifier, :id => p.id}, :confirm => _("Do you want to deactivate this profile ?") %>
+            <% else %>
+              <%= button_without_text :'activate-user', _('Activate'), {:controller => "profile_editor", :action => 'activate_profile', :profile => p.identifier, :id => p.id}, :confirm => _("Do you want to activate this profile ?") %>
+            <% end %>
+              <%= button_without_text :'delete', _('Remove'), {:controller => "profile_editor", :action => 'destroy_profile', :profile => p.identifier, :id => p.id, :return_to => "/admin/admin_panel/manage_organizations_status"}, :method => :post, :confirm => _("Do you want to deactivate this profile ?") %>
+         </div>
+        </td>
+      </tr>
+    <% end %>
+  </table>
+
+<% end %>
+
+<%= pagination_links @collection, {:param_name => 'npage', :page_links => true} %>
+
+<% button_bar do %>
+  <%= button :back, _('Back'), :controller => 'admin_panel' %>
+<% end %>
+
+<script type="text/javascript">
+  jQuery(document).ready(function(){
+    jQuery("#profile_filter_select").change(function(){
+      document.location.href = '/admin/admin_panel/manage_organizations_status?filter='+this.value;
+    });
+  });
+</script>
\ No newline at end of file

=====================================
app/views/profile_editor/edit.html.erb
=====================================
--- a/app/views/profile_editor/edit.html.erb
+++ b/app/views/profile_editor/edit.html.erb
@@ -1,5 +1,6 @@
 <h1><%= _('Profile settings for %s') % profile.name %></h1>
 
+<%= javascript_include_tag 'deactivate_profile' %>
 <%= error_messages_for :profile_data %>
 
 <%= labelled_form_for :profile_data, :html => { :id => 'profile-data', :multipart => true } do |f| %>
@@ -67,6 +68,15 @@
   <% if user && user.has_permission?('destroy_profile', profile) %>
     <% button_bar(:id => 'delete-profile') do %>
       <%= button(:remove, _('Delete profile'), {:action => :destroy_profile}) %>
+
+      <% if environment.admins.include?(current_person) %>
+
+        <% if profile.visible? %>
+          <%= button(:remove, _('Deactivate profile'), {:action => :deactivate_profile, :id=>profile.id}, :id=>'deactivate_profile_button', :data => {:confirm=>_("Are you sure you want to deactivate this profile?")}) %>
+        <% else %>
+          <%= button(:add, _('Activate profile'), {:action => :activate_profile, :id=>profile.id}, :data => {:confirm=>_("Are you sure you want to deactivate this profile?")}) %>
+        <% end %>
+      <% end %>
     <% end %>
   <% end %>
-<% end %>
+<% end %>
\ No newline at end of file

=====================================
test/functional/admin_panel_controller_test.rb
=====================================
--- a/test/functional/admin_panel_controller_test.rb
+++ b/test/functional/admin_panel_controller_test.rb
@@ -378,4 +378,35 @@ class AdminPanelControllerTest < ActionController::TestCase
     assert !Environment.default.signup_welcome_screen_body.blank?
   end
 
+  should 'show list to deactivate organizations' do
+    enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community")
+    disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community")
+    user = create_user('user')
+
+    disabled_community.disable
+
+    Environment.default.add_admin user.person
+    login_as('user')
+
+    get :manage_organizations_status, :filter=>"enabled"
+    assert_match(/Organization profiles - enabled/, @response.body)
+    assert_match(/enabled community/, @response.body)
+    assert_not_match(/disabled community/, @response.body)
+  end
+
+  should 'show list to activate organizations' do
+    enabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"enabled community")
+    disabled_community = fast_create(Community, :environment_id => Environment.default, :name=>"disabled community")
+    user = create_user('user')
+
+    disabled_community.disable
+
+    Environment.default.add_admin user.person
+    login_as('user')
+
+    get :manage_organizations_status, :filter=>"disabled"
+    assert_match(/Organization profiles - disabled/, @response.body)
+    assert_not_match(/enabled community/, @response.body)
+    assert_match(/disabled community/, @response.body)
+  end
 end

=====================================
test/functional/profile_editor_controller_test.rb
=====================================
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -1095,4 +1095,57 @@ class ProfileEditorControllerTest < ActionController::TestCase
     get :index, :profile => user.identifier
     assert_tag :tag => 'div', :descendant => { :tag => 'a', :content => 'Edit Header and Footer' }
   end
+
+  should 'deactivate organization profile' do
+    @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
+    user = create_user('user').person
+    Environment.default.add_admin user
+    login_as('user')
+
+    community = fast_create(Community)
+    assert_equal true, community.enable
+
+    get :index, :profile => community.identifier
+    get :deactivate_profile, {:profile => community.identifier, :id => community.id}
+    assert_equal @request.session[:notice], "The profile '#{community.name}' was deactivated."
+  end
+
+  should 'activate organization profile' do
+    @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
+    user = create_user('user').person
+    Environment.default.add_admin user
+    login_as('user')
+
+    community = fast_create(Community)
+    assert_equal true, community.disable
+
+    get :index, :profile => community.identifier
+    get :activate_profile, {:profile => community.identifier, :id => community.id}
+    assert_equal @request.session[:notice], "The profile '#{community.name}' was activated."
+  end
+
+  should 'not deactivate organization profile if user is not an admin' do
+    @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
+    user = create_user('user').person
+    login_as('user')
+
+    community = fast_create(Community)
+    get :index, :profile => community.identifier
+    get :deactivate_profile, {:profile => community.identifier, :id => community.id}
+    assert_not_equal @request.session[:notice], "The profile '#{community.name}' was disabled."
+  end
+
+  should 'destroy organization profile' do
+    @request.env['HTTP_REFERER'] = 'http://localhost:3000/admin/admin_panel/manage_organizations_status'
+    user = create_user('user').person
+    Environment.default.add_admin user
+    login_as('user')
+
+    community = fast_create(Community)
+    assert_equal true, community.enable
+
+    get :index, :profile => community.identifier
+    post :destroy_profile, {:profile => community.identifier, :id => community.id}
+    assert_equal @request.session[:notice], "The profile was deleted."
+  end
 end

=====================================
test/unit/profile_test.rb
=====================================
--- a/test/unit/profile_test.rb
+++ b/test/unit/profile_test.rb
@@ -1955,4 +1955,22 @@ class ProfileTest < ActiveSupport::TestCase
     p = fast_create(Profile)
     assert p.folder_types.include?('ProfileTest::Folder1')
   end
+
+  should 'enable profile visibility' do
+    profile = fast_create(Profile)
+
+    assert_equal true, profile.disable
+
+    assert_equal true, profile.enable
+    assert_equal true, profile.visible?
+  end
+
+  should 'disable profile visibility' do
+    profile = fast_create(Profile)
+
+    assert_equal true, profile.enable
+
+    assert_equal true, profile.disable
+    assert_equal false, profile.visible?
+  end
 end

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150120/95af033d/attachment-0001.html>


More information about the Noosfero-dev mailing list