diff --git a/app/controllers/profile_admin/enterprise_controller.rb b/app/controllers/profile_admin/enterprise_controller.rb deleted file mode 100644 index 82aa0d4..0000000 --- a/app/controllers/profile_admin/enterprise_controller.rb +++ /dev/null @@ -1,147 +0,0 @@ -# Manage enterprises by providing an interface to register, activate and manage them -class EnterpriseController < ProfileAdminController - - before_filter :logon, :my_enterprises - protect([:edit, :update, :activate, :destroy], 'edit_enterprise', @profile) - - # Redirects to show if there is only one action and to list otherwise - def index - if @person.enterprises.size == 1 - redirect_to :action => 'show', :id => @person.enterprises[0] - else - redirect_to :action => 'list' - end - @vitual_communities = Environment.find(:all) - @validation_entities = Organization.find(:all) - end - - # Lists all enterprises - def list - @enterprises = Enterprise.find(:all) - @person.enterprises - end - - # Show details about an enterprise - def show - @enterprise = Enterprise.find(params[:id]) - end - - # Make a form to the creation of an eterprise - def register_form - @enterprise = Enterprise.new() - @vitual_communities = Environment.find(:all) - @validation_entities = Organization.find(:all) - end - - # Saves the new created enterprise - def register - @enterprise = Enterprise.new(params[:enterprise]) - @enterprise.organization_info = OrganizationInfo.new(params[:organization]) - if @enterprise.save - @enterprise.people << @person - flash[:notice] = _('The enterprise was succesfully 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') - @vitual_communities = Environment.find(:all) - @validation_entities = Organization.find(:all) - render :action => 'register_form' - end - end - - # Provides an interface to editing the enterprise details - def edit - @enterprise = @person.enterprises(:id => params[:id])[0] - @validation_entities = Organization.find(:all) - [@enterprise] - end - - # Saves the changes made in an enterprise - def update - @enterprise = @person.enterprises(:id => params[:id])[0] - if @enterprise.update_attributes(params[:enterprise]) && @enterprise.organization_info.update_attributes(params[:organization_info]) - redirect_to :action => 'index' - else - flash[:notice] = _('Could not update the enterprise') - @validation_entities = Organization.find(:all) - [@enterprise] - render :action => 'edit' - end - end - - # Make the current user a new member of the enterprise - def affiliate - @enterprise = Enterprise.find(params[:id]) - 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 - @enterprise = @person.enterprises(:id => params[:id])[0] - if @enterprise - @enterprise.destroy - else - flash[:notice] = 'Can destroy only your enterprises' - end - redirect_to :action => 'index' - end - - # Search enterprises by name or tags - def search - @tagged_enterprises = Enterprise.search(params[:query]) - end - - # Activate a validated enterprise - def activate - @enterprise = Enterprise.find(params[:id]) - if @enterprise.activate - flash[:notice] = _('Enterprise successfuly activacted') - else - flash[:notice] = _('Failed to activate the enterprise') - end - redirect_to :action => 'index' - end - - # Validates an eterprise - def approve - @enterprise = Enterprise.find(params[:id]) - if @enterprise.approve - flash[:notice] = _('Enterprise successfuly approved') - else - flash[:notice] = _('Failed to approve the htmlenterprise') - end - redirect_to :action => 'index' - end - - # Rejects an enterprise - def reject - @enterprise = Enterprise.find(params[:id]) - if @enterprise.reject - flash[:notice] = _('Enterprise successfuly rejected') - else - flash[:notice] = _('Failed to reject the enterprise') - end - redirect_to :action => 'index' - end - - - protected - - # Make sure that the user is logged before access this controller - def logon - if logged_in? - @user = current_user - @person = @user.person - else - redirect_to :controller => 'account' unless logged_in? - end - end - - # Initializes some variables to contain the enterprises of the current user - def my_enterprises - if logged_in? - @my_active_enterprises = @person.active_enterprises - @my_pending_enterprises = @person.pending_enterprises - @my_enterprises = @person.enterprises - end - end -end diff --git a/app/controllers/profile_admin/enterprise_editor_controller.rb b/app/controllers/profile_admin/enterprise_editor_controller.rb new file mode 100644 index 0000000..7e06e5a --- /dev/null +++ b/app/controllers/profile_admin/enterprise_editor_controller.rb @@ -0,0 +1,67 @@ +class EnterpriseEditorController < ProfileAdminController + + before_filter :logon, :check_enterprise + + # Show details about an enterprise + def index + @my_enterprises = @person.enterprises + @my_pending_enterprises = @person.pending_enterprises + end + + # Provides an interface to editing the enterprise details + def edit + @validation_entities = Organization.find(:all) - [@enterprise] + end + + # Saves the changes made in an enterprise + def update + if @enterprise.update_attributes(params[:enterprise]) && @enterprise.organization_info.update_attributes(params[:organization_info]) + redirect_to :action => 'index' + else + flash[:notice] = _('Could not update the enterprise') + @validation_entities = Organization.find(:all) - [@enterprise] + 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 + if @enterprise + @enterprise.destroy + else + flash[:notice] = 'Can destroy only your enterprises' + end + redirect_to :action => 'index' + end + + # Activate a validated enterprise + def activate + if @enterprise.activate + flash[:notice] = _('Enterprise successfuly activacted') + else + flash[:notice] = _('Failed to activate the enterprise') + end + redirect_to :action => 'index' + end + + protected + + def logon + if logged_in? + @user = current_user + @person = @user.person + end + end + + def check_enterprise + raise 'It\'s not an enterprise' unless @profile.is_a?(Enterprise) + @enterprise = @profile + end +end diff --git a/app/controllers/profile_admin/membership_editor_controller.rb b/app/controllers/profile_admin/membership_editor_controller.rb new file mode 100644 index 0000000..6a9bde2 --- /dev/null +++ b/app/controllers/profile_admin/membership_editor_controller.rb @@ -0,0 +1,6 @@ +class MembershipEditorController < ProfileAdminController + + def index + @memberships = Profile.find(:all, :include => 'role_assignments', :conditions => ['role_assignments.person_id = ?', current_user.person.id]) + end +end diff --git a/app/controllers/profile_admin/profile_member_controller.rb b/app/controllers/profile_admin/profile_member_controller.rb deleted file mode 100644 index dfc293c..0000000 --- a/app/controllers/profile_admin/profile_member_controller.rb +++ /dev/null @@ -1,23 +0,0 @@ -class ProfileMemberController < ApplicationController - - def index - @members = @profile.people - end - - def affiliate - @member = Person.find(params[:id]) - @roles = Role.find(:all).select{ |r| r.has_kind?(:profile) } - end - - def give_role - @person = Person.find(params[:person]) - @role = Role.find(params[:role]) - if @profile.affiliate(@person, @role) - redirect_to :action => 'index' - else - @member = Person.find(params[:person]) - @roles = Role.find(:all).select{ |r| r.has_kind?(:profile) } - render :action => 'affiliate' - end - end -end diff --git a/app/controllers/profile_admin/profile_members_controller.rb b/app/controllers/profile_admin/profile_members_controller.rb new file mode 100644 index 0000000..075e6f0 --- /dev/null +++ b/app/controllers/profile_admin/profile_members_controller.rb @@ -0,0 +1,60 @@ +class ProfileMembersController < ProfileAdminController + + def index + @members = profile.people.uniq + end + + def change_roles + @member = Person.find(params[:id]) + @roles = Role.find(:all).select{ |r| r.has_kind?(:profile) } + end + + def update_roles + @roles = Role.find(params[:roles]) + @person = Person.find(params[:person]) + if @person.define_roles(@roles, profile) + flash[:notice] = 'Roles successfuly updated' + else + flash[:notice] = 'Couldn\'t change the roles' + end + redirect_to :action => :index + end + + def change_role + @roles = Role.find(:all).select{ |r| r.has_kind?(:profile) } + @member = Person.find(params[:id]) + @associations = RoleAssignment.find(:all, :conditions => {:person_id => @member, :resource_id => @profile, :resource_type => @profile.class.base_class.name}) + end + + def add_role + @person = Person.find(params[:person]) + @role = Role.find(params[:role]) + if @profile.affiliate(@person, @role) + redirect_to :action => 'index' + else + @member = Person.find(params[:person]) + @roles = Role.find(:all).select{ |r| r.has_kind?(:profile) } + render :action => 'affiliate' + end + end + + def remove_role + @association = RoleAssignment.find(params[:id]) + if @association.destroy + flash[:notice] = 'Member succefully unassociated' + else + flash[:notice] = 'Failed to unassociate member' + end + redirect_to :aciton => 'index' + end + + def unassociate + @association = RoleAssignment.find(params[:id]) + if @association.destroy + flash[:notice] = 'Member succefully unassociated' + else + flash[:notice] = 'Failed to unassociate member' + end + redirect_to :aciton => 'index' + end +end diff --git a/app/helpers/enterprise_editor_helper.rb b/app/helpers/enterprise_editor_helper.rb new file mode 100644 index 0000000..606cf04 --- /dev/null +++ b/app/helpers/enterprise_editor_helper.rb @@ -0,0 +1,2 @@ +module EnterpriseEditorHelper +end diff --git a/app/helpers/membership_editor_helper.rb b/app/helpers/membership_editor_helper.rb new file mode 100644 index 0000000..13de47e --- /dev/null +++ b/app/helpers/membership_editor_helper.rb @@ -0,0 +1,2 @@ +module MembershipEditorHelper +end diff --git a/app/models/person.rb b/app/models/person.rb index 247418c..3e4ff2c 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -16,6 +16,14 @@ class Person < Profile role_assignments.any? {|ra| ra.has_permission?(perm, res)} end + def define_roles(roles, resource) + associations = RoleAssignment.find(:all, :conditions => {:resource_id => resource.id, :resource_type => resource.class.base_class.name, :person_id => self.id }) + roles_add = roles - associations.map(&:role) + roles_remove = associations.map(&:role) - roles + associations.each { |a| a.destroy if roles_remove.include?(a.role) } + roles_add.each {|r| RoleAssignment.create(:person_id => self.id, :resource_id => resource.id, :resource_type => resource.class.base_class.name, :role_id => r.id) } + end + def self.conditions_for_profiles(conditions, person) new_conditions = sanitize_sql(['role_assignments.person_id = ?', person]) new_conditions << ' AND ' + sanitize_sql(conditions) unless conditions.blank? diff --git a/app/views/enterprise_editor/_enterprise.rhtml b/app/views/enterprise_editor/_enterprise.rhtml new file mode 100644 index 0000000..f2f72ec --- /dev/null +++ b/app/views/enterprise_editor/_enterprise.rhtml @@ -0,0 +1,17 @@ +
+<%= text_field 'enterprise', 'name', 'size' => 20 %>
+<%= text_field 'enterprise', 'address', 'size' => 50 %>
+<%= text_field 'enterprise', 'contact_phone', 'size' => 20 %>
+<%= text_field 'organization_info', 'contact_person', 'size' => 20 %>
+<%= text_field 'organization_info', 'acronym', 'size' => 20 %>
+<%= text_field 'organization_info', 'foundation_year', 'size' => 20 %>
+<%= text_field 'organization_info', 'legal_form', 'size' => 20 %>
+<%= text_field 'organization_info', 'economic_activity', 'size' => 20 %>
+<%= text_area 'organization_info', 'management_information', 'cols' => 40, 'rows' => 20 %>
+<%= select 'validation_entity', 'id', @validation_entities.map{|v| [v.name, v.id]}, :include_blank => true %>
+<%= text_field 'enterprise', 'tag_list', 'size' => 20 %>
<%= submit_tag _('Update') %> +<%= link_to _('Cancel'), :action => 'index' %>
+<% end %> diff --git a/app/views/enterprise_editor/index.rhtml b/app/views/enterprise_editor/index.rhtml new file mode 100644 index 0000000..2d05d56 --- /dev/null +++ b/app/views/enterprise_editor/index.rhtml @@ -0,0 +1,21 @@ +<%= _('Identifier: ') %> <%= @profile.identifier %>
+<%= _('Address: ') %> <%= @profile.address %>
+<%= _('Contact phone: ') %> <%= @profile.contact_phone %>
+<%= _('Contact person: ') %> <%= @profile.organization_info.contact_person %>
+<%= _('Acronym: ') %> <%= @profile.organization_info.acronym %>
+<%= _('Foundation year: ') %> <%= @profile.organization_info.foundation_year %>
+<%= _('Legal Form: ') %> <%= @profile.organization_info.legal_form %>
+<%= _('Economic activity: ') %> <%= @profile.organization_info.economic_activity %>
+<%= _('Management infomation: ') %> <%= @profile.organization_info.management_information %>
+<%= _('Tags:') %> <%= @profile.tag_list %>
+ +<%= link_to _('Edit enterprise'), :action => 'edit', :id => @profile %> +<%= 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) %> diff --git a/app/views/membership_editor/.index.rhtml.swp b/app/views/membership_editor/.index.rhtml.swp new file mode 100644 index 0000000..2ac1380 Binary files /dev/null and b/app/views/membership_editor/.index.rhtml.swp differ diff --git a/app/views/membership_editor/index.rhtml b/app/views/membership_editor/index.rhtml new file mode 100644 index 0000000..b57b6c9 --- /dev/null +++ b/app/views/membership_editor/index.rhtml @@ -0,0 +1,7 @@ +