From d9861a6912319e96d5542228a9df42f8e79956be Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Wed, 26 Sep 2007 20:09:11 +0000 Subject: [PATCH] ActionItem5: linked the functionlity of managing members of profiles and editing the enterprise info --- app/controllers/application.rb | 6 +++--- app/controllers/profile_admin/enterprise_editor_controller.rb | 5 ++++- app/models/enterprise.rb | 10 +++++----- app/models/profile.rb | 1 + app/models/role.rb | 1 - app/views/enterprise_editor/index.rhtml | 4 ++++ app/views/membership_editor/index.rhtml | 5 ++++- app/views/profile_members/index.rhtml | 2 ++ test/fixtures/roles.yml | 3 ++- 9 files changed, 25 insertions(+), 12 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index d56a750..c49b74b 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -57,9 +57,9 @@ class ApplicationController < ActionController::Base # * +permission+ must be a symbol or string naming the needed permission. # * +target+ is the object over witch the user would need the specified permission. def self.protect(actions, permission, target = nil) - before_filter :only => actions do |controller| - unless controller.send(:logged_in?) and controller.send(:current_user).person.has_permission?(permission, target) - controller.send(:render, {:file => 'app/views/shared/access_denied.rhtml', :layout => true}) + before_filter :only => actions do |c| + unless c.send(:logged_in?) && c.send(:current_user).person.has_permission?(permission.to_s, c.send(target)) + c.send(:render, {:file => 'app/views/shared/access_denied.rhtml', :layout => true}) end end end diff --git a/app/controllers/profile_admin/enterprise_editor_controller.rb b/app/controllers/profile_admin/enterprise_editor_controller.rb index 0ec7150..40a6b27 100644 --- a/app/controllers/profile_admin/enterprise_editor_controller.rb +++ b/app/controllers/profile_admin/enterprise_editor_controller.rb @@ -1,7 +1,10 @@ class EnterpriseEditorController < ProfileAdminController before_filter :logon, :check_enterprise - + protect [:edit, :update], :edit_profile, :profile + protect [:destroy], :destroy_profile, @profile + + # Show details about an enterprise def index @enterprise = @profile diff --git a/app/models/enterprise.rb b/app/models/enterprise.rb index 55d5924..8e7c9a2 100644 --- a/app/models/enterprise.rb +++ b/app/models/enterprise.rb @@ -8,11 +8,11 @@ class Enterprise < Organization end # Test that an enterprise can't be activated unless was previously approved - def validate - if self.active && !self.approved? - errors.add('active', _('Not approved enterprise can\'t be activated')) - end - end +# def validate +# if self.active && !self.approved? +# errors.add('active', _('Not approved enterprise can\'t be activated')) +# end +# end # Activate the enterprise so it can be seen by other users def activate diff --git a/app/models/profile.rb b/app/models/profile.rb index 1ad2291..be166bb 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -50,6 +50,7 @@ class Profile < ActiveRecord::Base validates_presence_of :identifier, :name validates_format_of :identifier, :with => IDENTIFIER_FORMAT validates_exclusion_of :identifier, :in => RESERVED_IDENTIFIERS + validates_uniqueness_of :identifier # A profile_owner cannot have more than one profile, but many profiles can exist # without being associated to a particular user. diff --git a/app/models/role.rb b/app/models/role.rb index de21468..27f535b 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -6,7 +6,6 @@ class Role < ActiveRecord::Base 'destroy_profile' => N_('Destroy profile'), 'manage_memberships' => N_('Manage memberships'), 'post_content' => N_('Post content'), - 'moderate_content' => N_('Moderate content'), }, :system => { } diff --git a/app/views/enterprise_editor/index.rhtml b/app/views/enterprise_editor/index.rhtml index 8f39e8f..a492a91 100644 --- a/app/views/enterprise_editor/index.rhtml +++ b/app/views/enterprise_editor/index.rhtml @@ -1,5 +1,7 @@

<%= @profile.name %>

+<%= error_messages_for 'profile' %> +

<%= _('Identifier: ') %> <%= @profile.identifier %>

<%= _('Address: ') %> <%= @profile.address %>

<%= _('Contact phone: ') %> <%= @profile.contact_phone %>

@@ -17,3 +19,5 @@ <%= help _('Remove the enterprise from the system') %> <%= link_to _('Activate'), :action => 'activate', :id => @profile unless @profile.active? %> <%= help _('Activate an approved enterprise') unless @profile.active? %> + +<%= link_to _('Back'), :controller => :profile_editor %> diff --git a/app/views/membership_editor/index.rhtml b/app/views/membership_editor/index.rhtml index eaae374..1b4346b 100644 --- a/app/views/membership_editor/index.rhtml +++ b/app/views/membership_editor/index.rhtml @@ -2,7 +2,10 @@ diff --git a/app/views/profile_members/index.rhtml b/app/views/profile_members/index.rhtml index 33bfc4e..22ecbea 100644 --- a/app/views/profile_members/index.rhtml +++ b/app/views/profile_members/index.rhtml @@ -9,3 +9,5 @@ <%= link_to _('Remove member'), :action => 'unassociate', :id => m %> <% end %> + +<%= link_to _('Back'), :controller => 'profile_editor' %> diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml index dea5f01..8422c30 100644 --- a/test/fixtures/roles.yml +++ b/test/fixtures/roles.yml @@ -8,6 +8,8 @@ two: id: 2 name: 'owner' permissions: + - menage_memberships + - post_content - destroy_profile - edit_profile three: @@ -15,4 +17,3 @@ three: name: 'moderator' permissions: - manage_memberships - - moderate_content -- libgit2 0.21.2