diff --git a/app/controllers/environment_admin/environment_role_manager_controller.rb b/app/controllers/environment_admin/environment_role_manager_controller.rb new file mode 100644 index 0000000..7a41891 --- /dev/null +++ b/app/controllers/environment_admin/environment_role_manager_controller.rb @@ -0,0 +1,67 @@ +class EnvironmentRoleManagerController < ApplicationController + def index + @admins = Person.find(:all, :conditions => ['role_assignments.resource_type = ?', 'Environment'], :include => :role_assignments ) + end + + def change_roles + @admin = Person.find(params[:id]) + @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } + end + + def update_roles + @roles = params[:roles] ? Role.find(params[:roles]) : [] + @person = Person.find(params[:person]) + if @person.define_roles(@roles, environment) + 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?(:environment) } + @admin = Person.find(params[:id]) + @associations = RoleAssignment.find(:all, :conditions => {:accessor_id => @admin, + :accessor_type => @admin.class.base_class.name, + :resource_id => environment, + :resource_type => environment.class.base_class.name}) + end + + def add_role + @person = Person.find(params[:person]) + @role = Role.find(params[:role]) + if environment.affiliate(@person, @role) + redirect_to :action => 'index' + else + @admin = Person.find(params[:person]) + @roles = Role.find(:all).select{ |r| r.has_kind?(:environment) } + 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 + + def make_admin + @people = Person.find(:all) + @roles = Role.find(:all).select{|r|r.has_kind?(:environment)} + end +end diff --git a/app/controllers/profile_admin/profile_members_controller.rb b/app/controllers/profile_admin/profile_members_controller.rb index 075e6f0..60d2e7c 100644 --- a/app/controllers/profile_admin/profile_members_controller.rb +++ b/app/controllers/profile_admin/profile_members_controller.rb @@ -13,9 +13,9 @@ class ProfileMembersController < ProfileAdminController @roles = Role.find(params[:roles]) @person = Person.find(params[:person]) if @person.define_roles(@roles, profile) - flash[:notice] = 'Roles successfuly updated' + flash[:notice] = _('Roles successfuly updated') else - flash[:notice] = 'Couldn\'t change the roles' + flash[:notice] = _('Couldn\'t change the roles') end redirect_to :action => :index end diff --git a/app/controllers/public/account_controller.rb b/app/controllers/public/account_controller.rb index 80686b5..fe2b195 100644 --- a/app/controllers/public/account_controller.rb +++ b/app/controllers/public/account_controller.rb @@ -16,7 +16,8 @@ class AccountController < PublicController self.current_user.remember_me cookies[:auth_token] = { :value => self.current_user.remember_token , :expires => self.current_user.remember_token_expires_at } end - redirect_back_or_default(:controller => '/account', :action => 'index') +# redirect_back_or_default(:controller => '/account', :action => 'index') + redirect_back_or_default(homepage_path(:profile => current_user.login)) flash[:notice] = _("Logged in successfully") else flash[:notice] = _('Incorrect username or password') diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 7e152e5..f7ef37c 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -117,7 +117,8 @@ module ApplicationHelper links = [ ( link_to_homepage(current_user.login) ), ( link_to(_('My account'), { :controller => 'account' }) ), - ( link_to(_('Admin'), { :controller => 'admin_panel' }) ), + ( link_to_myprofile _('My Enterprises'), {:controller => 'membership_editor'} ), + ( link_to(_('Admin'), { :controller => 'admin_panel' }) if current_user.person.role_assignments.map{|ra| ra.role.permissions}.any?{|ps|ps.any?{|p|ActiveRecord::Base::PERMISSIONS[:environment].keys.include?(p)}}), ].join("\n") content_tag('span', links, :id => 'user_links') end @@ -171,33 +172,47 @@ module ApplicationHelper ] end - def profile_links + def person_links links = [ [(link_to_myprofile _('Edit visual design'), :controller => 'profile_editor', :action => 'design_editor'), 'edit_profile_design', profile], - [(link_to_myprofile _('Edit informations'), :controller => 'profile_editor'), 'edit_profile', profile], + [(link_to_myprofile _('Edit profile'), :controller => 'profile_editor'), 'edit_profile', profile], [(link_to_myprofile _('Manage content'), :controller => 'cms'), 'post_content', profile], ] - if profile.kind_of?(Enterprise) - links << [(link_to_myprofile _('Exclude'), :controller => 'enterprise_editor', :action => 'destroy'), 'edit_profile', profile] - else - links - end + end + + + def enterprise_links + links = [ + [(link_to_myprofile _('Edit visual design'), :controller => 'profile_editor', :action => 'design_editor'), 'edit_profile_design', profile], + [(link_to_myprofile _('Edit informations'), :controller => 'profile_editor'), 'edit_profile', profile], + [(link_to_myprofile _('Manage content'), :controller => 'cms'), 'post_content', profile], + [(link_to_myprofile _('Exclude'), :controller => 'enterprise_editor', :action => 'destroy'), 'edit_profile', profile], + ] end #FIXME: find a way of accessing environment from here def user_options + profile = params[:profile] case params[:controller] when 'admin_panel' admin_links when 'membership_editor' membership_links when 'profile_editor' - profile_links + if profile.kind_of?(Enterprise) + enterprise_links + elsif profile.kind_of?(Person) + person_links + else + [] + end + when 'content_viewer' + person_links else [] - end.map{|l| link_if_permitted(l[0], l[1], l[3]) } + end.map{|l| link_if_permitted(l[0], l[1], l[2]) } end def footer @@ -281,5 +296,4 @@ module ApplicationHelper ] select_tag "#{object}[#{method}]", options_for_select(options, @page.filter_type || Comatose.config.default_filter), { :id=> "#{object}_#{method}" }.merge(html_options) end - end diff --git a/app/helpers/environment_role_manager_helper.rb b/app/helpers/environment_role_manager_helper.rb new file mode 100644 index 0000000..5a42858 --- /dev/null +++ b/app/helpers/environment_role_manager_helper.rb @@ -0,0 +1,2 @@ +module EnvironmentRoleManagerHelper +end diff --git a/app/models/environment.rb b/app/models/environment.rb index 131d57a..410b3b7 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -3,6 +3,14 @@ # domains. class Environment < ActiveRecord::Base + PERMISSIONS[:environment] = { + 'edit_environment_features' => N_('Edit environment features'), + 'edit_environment_design' => N_('Edit environment design'), + 'manage_environment_categories' => N_('Manage environment categories'), + 'manage_environment_roles' => N_('Manage environment roles'), + 'manage_environment_validators' => N_('Manage environment validators'), + } + # returns the available features for a Environment, in the form of a # hash, with pairs in the form 'feature_name' => 'Feature name'. def self.available_features diff --git a/app/models/profile.rb b/app/models/profile.rb index 08f3dc9..7ed6016 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -8,6 +8,7 @@ class Profile < ActiveRecord::Base 'destroy_profile' => N_('Destroy profile'), 'manage_memberships' => N_('Manage memberships'), 'post_content' => N_('Post content'), + 'edit_profile_design' => N_('Edit profile design'), } after_create do |profile| diff --git a/app/views/environment_role_manager/affiliate.rhtml b/app/views/environment_role_manager/affiliate.rhtml new file mode 100644 index 0000000..4f23242 --- /dev/null +++ b/app/views/environment_role_manager/affiliate.rhtml @@ -0,0 +1,9 @@ +