From 3041e7ee8d303ed3166f233674c4726f7d6ca7af Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Wed, 26 Sep 2007 15:27:45 +0000 Subject: [PATCH] ActionItem5: cleaned some code and made some views more interconected and accessible --- app/controllers/profile_admin/enterprise_editor_controller.rb | 10 +--------- app/controllers/profile_admin/membership_editor_controller.rb | 4 ++-- app/models/person.rb | 2 +- app/models/profile.rb | 15 +++++++++------ app/models/role.rb | 4 ++-- app/views/account/index.rhtml | 4 ++++ app/views/enterprise_editor/_enterprise.rhtml | 17 ----------------- app/views/enterprise_editor/index.rhtml | 6 ++---- app/views/profile_editor/index.rhtml | 8 +++++++- app/views/profile_members/affiliate.rhtml | 2 ++ app/views/profile_members/change_role.rhtml | 1 + app/views/profile_members/index.rhtml | 2 +- test/fixtures/roles.yml | 10 ++++++++-- 13 files changed, 40 insertions(+), 45 deletions(-) delete mode 100644 app/views/enterprise_editor/_enterprise.rhtml diff --git a/app/controllers/profile_admin/enterprise_editor_controller.rb b/app/controllers/profile_admin/enterprise_editor_controller.rb index 7e06e5a..0ec7150 100644 --- a/app/controllers/profile_admin/enterprise_editor_controller.rb +++ b/app/controllers/profile_admin/enterprise_editor_controller.rb @@ -4,8 +4,7 @@ class EnterpriseEditorController < ProfileAdminController # Show details about an enterprise def index - @my_enterprises = @person.enterprises - @my_pending_enterprises = @person.pending_enterprises + @enterprise = @profile end # Provides an interface to editing the enterprise details @@ -23,13 +22,6 @@ class EnterpriseEditorController < ProfileAdminController render :action => 'edit' end end - - # Make the current user a new member of the enterprise - def affiliate - member_role = Role.find_by_name('member') || Role.create(:name => 'member') - @enterprise.affiliate(@person,member_role) - redirect_to :action => 'index' - end # Elimitates the enterprise of the system def destroy diff --git a/app/controllers/profile_admin/membership_editor_controller.rb b/app/controllers/profile_admin/membership_editor_controller.rb index 3683a1e..7046767 100644 --- a/app/controllers/profile_admin/membership_editor_controller.rb +++ b/app/controllers/profile_admin/membership_editor_controller.rb @@ -14,8 +14,8 @@ class MembershipEditorController < ProfileAdminController @enterprise = Enterprise.new(params[:enterprise]) @enterprise.organization_info = OrganizationInfo.new(params[:organization]) if @enterprise.save - @enterprise.affiliate(@person, Role.find_by_name('owner')) - flash[:notice] = _('The enterprise was succesfully created, the validation entity will cotact you as soon as your enterprise is approved') + @enterprise.affiliate(current_user.person, Role.find(:all, :conditions => {:name => ['owner', 'member', 'moderator']})) + flash[:notice] = _('The enterprise was successfully created, the validation entity will cotact you as soon as your enterprise is approved') redirect_to :action => 'index' else flash[:notice] = _('Enterprise was not created') diff --git a/app/models/person.rb b/app/models/person.rb index dc12b37..1e987b2 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -34,7 +34,7 @@ class Person < Profile :all, :conditions => self.class.conditions_for_profiles(conditions, self), :joins => "LEFT JOIN role_assignments ON profiles.id = role_assignments.resource_id AND role_assignments.resource_type = \"#{Profile.base_class.name}\"", - :select => 'profiles.*') + :select => 'profiles.*').uniq end def info diff --git a/app/models/profile.rb b/app/models/profile.rb index 93dfe95..1ad2291 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -102,11 +102,14 @@ class Profile < ActiveRecord::Base homepage.children.find(:all, :limit => limit, :order => 'created_on desc') end - def affiliate(person, role) - unless RoleAssignment.find(:first, :conditions => {:person_id => person, :role_id => role, :resource_id => self, :resource_type => self.class.base_class.name}) - RoleAssignment.new(:person => person, :role => role, :resource => self).save - else - false - end + def affiliate(person, roles) + roles = [roles] unless roles.kind_of?(Array) + roles.map do |role| + unless RoleAssignment.find(:first, :conditions => {:person_id => person, :role_id => role, :resource_id => self, :resource_type => self.class.base_class.name}) + RoleAssignment.new(:person => person, :role => role, :resource => self).save + else + false + end + end.any? end end diff --git a/app/models/role.rb b/app/models/role.rb index b83d1e3..de21468 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -3,9 +3,9 @@ class Role < ActiveRecord::Base PERMISSIONS = { :profile => { 'edit_profile' => N_('Edit profile'), - 'post_content' => N_('Post content'), 'destroy_profile' => N_('Destroy profile'), - 'manage_membership' => N_('Manage membership'), + 'manage_memberships' => N_('Manage memberships'), + 'post_content' => N_('Post content'), 'moderate_content' => N_('Moderate content'), }, :system => { diff --git a/app/views/account/index.rhtml b/app/views/account/index.rhtml index e644494..14bf650 100644 --- a/app/views/account/index.rhtml +++ b/app/views/account/index.rhtml @@ -20,6 +20,10 @@ <%= _('Manage your content.') %>

+

+<%= link_to_myprofile(_('Manage memberships.'), :controller => 'membership_editor') %> +<%= _('Manage your affiliation with other profiles.') %> +

<%= link_to _('Logout.'), :action => 'logout' %> diff --git a/app/views/enterprise_editor/_enterprise.rhtml b/app/views/enterprise_editor/_enterprise.rhtml deleted file mode 100644 index f2f72ec..0000000 --- a/app/views/enterprise_editor/_enterprise.rhtml +++ /dev/null @@ -1,17 +0,0 @@ -

  • -<%= link_to enterprise.name, :action => 'show', :id => enterprise %> -<%= link_to _('Edit'), :action => 'edit', :id => enterprise %> -<%= help _('Change the infomation about the enterprise') %> -<%= link_to _('Delete'), :action => 'destroy', :id => enterprise %> -<%= help _('Remove the enterprise from the system') %> -<%= link_to _('Affiliate'), :action => 'affiliate', :id => enterprise unless @my_enterprises.include?(enterprise) %> -<%= help _('Be a member of the enterprise') unless @my_enterprises.include?(enterprise) %> -<%= link_to _('Activate'), :action => 'activate', :id => enterprise unless enterprise.active %> -<%= help _('Activate the profile of an approved enterprise') unless enterprise.active %> -<% unless enterprise.approved? %> - <%= link_to _('Approve'), :action => 'approve', :id => enterprise %> - <%= help _('Approve a submitted enterprise profile') %> - <%= link_to _('Reject'), :action => 'reject', :id => enterprise %> - <%= help _('Reject a submitted enterprise profile') %> -<% end %> -
  • diff --git a/app/views/enterprise_editor/index.rhtml b/app/views/enterprise_editor/index.rhtml index 2d05d56..8f39e8f 100644 --- a/app/views/enterprise_editor/index.rhtml +++ b/app/views/enterprise_editor/index.rhtml @@ -15,7 +15,5 @@ <%= help _('Change the information about the enterprise') %> <%= link_to _('Delete enterprise'), :action => 'destroy', :id => @profile %> <%= help _('Remove the enterprise from the system') %> -<%= link_to _('Affiliate'), :action => 'affiliate' unless @my_enterprises.include?(@profile) %> -<%= help _('Be a member of the enterprise') unless @my_enterprises.include?(@profile) %> -<%= link_to _('Activate'), :action => 'activate', :id => @profile if @my_pending_enterprises.include?(@profile) %> -<%= help _('Activate an approved enterprise') if @my_pending_enterprises.include?(@profile) %> +<%= link_to _('Activate'), :action => 'activate', :id => @profile unless @profile.active? %> +<%= help _('Activate an approved enterprise') unless @profile.active? %> diff --git a/app/views/profile_editor/index.rhtml b/app/views/profile_editor/index.rhtml index bf5a772..6fd43fb 100644 --- a/app/views/profile_editor/index.rhtml +++ b/app/views/profile_editor/index.rhtml @@ -2,4 +2,10 @@ <%= display_profile_info(profile) %> -<%= link_to _('Edit'), :action => 'edit' %> +

    <%= link_to _('Edit'), :action => 'edit' %>

    + +

    <%= link_to _('Manage members'), :controller => 'profile_members' %>

    + +<% if @profile.class == Enterprise %> +

    <%= link_to _('Edit enterprise info'), :controller => 'enterprise_editor'%>

    +<% end %> diff --git a/app/views/profile_members/affiliate.rhtml b/app/views/profile_members/affiliate.rhtml index 808326a..4f23242 100644 --- a/app/views/profile_members/affiliate.rhtml +++ b/app/views/profile_members/affiliate.rhtml @@ -5,3 +5,5 @@ <%= hidden_field_tag 'person', current_user.person.id %> <%= submit_tag _('Affiliate') %> <% end %> + +<%= link_to _('Back'), :action => 'index' %> diff --git a/app/views/profile_members/change_role.rhtml b/app/views/profile_members/change_role.rhtml index 8ad72af..254fae6 100644 --- a/app/views/profile_members/change_role.rhtml +++ b/app/views/profile_members/change_role.rhtml @@ -9,4 +9,5 @@ <%= hidden_field_tag 'person', @member.id %> <%= submit_tag _('Save changes') %> + <%= link_to _('Cancel'), :action => 'index' %> <% end %> diff --git a/app/views/profile_members/index.rhtml b/app/views/profile_members/index.rhtml index 7e5bc26..33bfc4e 100644 --- a/app/views/profile_members/index.rhtml +++ b/app/views/profile_members/index.rhtml @@ -1,6 +1,6 @@

    <%= _('Listing Members') %>

    -<%= link_to _('Affiliate'), :action => 'add_role', :person => current_user.person, :role => Role.find_by_name('member') %> +<%= link_to _('Affiliate yourself'), :action => 'add_role', :person => current_user.person, :role => Role.find_by_name('member') %>