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 @@ +

<%= @member.name %>

+ +<% form_tag( {:action => 'give_role'}, {:method => :post}) do %> + <%= select_tag 'role', options_for_select(@roles.map{|r|[r.name,r.id]}) %> + <%= hidden_field_tag 'person', current_user.person.id %> + <%= submit_tag _('Affiliate') %> +<% end %> + +<%= link_to _('Back'), :action => 'index' %> diff --git a/app/views/environment_role_manager/change_role.rhtml b/app/views/environment_role_manager/change_role.rhtml new file mode 100644 index 0000000..f9523d1 --- /dev/null +++ b/app/views/environment_role_manager/change_role.rhtml @@ -0,0 +1,13 @@ +<%= _('Changing role of %s') % @admin.name %> + +<% labelled_form_for :member, @admin, :url => {:action => 'update_roles'} do |f| %> + + <%= _('Roles: ') %>
+ <% @roles.each do |r| %> + <%= labelled_form_field(r.name, (check_box_tag "roles[]", r.id, @admin.role_assignments.map{|ra|ra.role}.include?(r))) %> + <% end %> + <%= hidden_field_tag 'person', @admin.id %> + + <%= submit_tag _('Save changes') %> + <%= link_to _('Cancel'), :action => 'index' %> +<% end %> diff --git a/app/views/environment_role_manager/index.rhtml b/app/views/environment_role_manager/index.rhtml new file mode 100644 index 0000000..aa9c919 --- /dev/null +++ b/app/views/environment_role_manager/index.rhtml @@ -0,0 +1,13 @@ +

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

+ +<%= link_to _('Make new admin'), :action => 'make_admin' %> + + + +<%= link_to _('Back'), :controller => 'admin_panel' %> diff --git a/app/views/environment_role_manager/make_admin.rhtml b/app/views/environment_role_manager/make_admin.rhtml new file mode 100644 index 0000000..8c3efcd --- /dev/null +++ b/app/views/environment_role_manager/make_admin.rhtml @@ -0,0 +1,13 @@ +

<% _('Make new admin') %>

+ +<% labelled_form_for :person, @person, :url => {:action => 'update_roles'} do |f| %> + <%= _('Admin') %>
+ <% @people.each do |p| %> + <%= labelled_form_field(p.name, (radio_button_tag "person", p.id)) %> + <% end %> + <%= _('Roles: ') %>
+ <% @roles.each do |r| %> + <%= labelled_form_field(r.name, (check_box_tag "roles[]", r.id)) %> + <% end %> +<%= submit_tag _('Make') %> +<% end %> diff --git a/app/views/layouts/application.rhtml b/app/views/layouts/application.rhtml index 3b7c1c5..d282c7b 100644 --- a/app/views/layouts/application.rhtml +++ b/app/views/layouts/application.rhtml @@ -71,7 +71,7 @@ <%= @category.full_name %> <% else @category %>
- <%= user_options %> + <%= user_options.join(' ') %>
<% end %> diff --git a/app/views/role/_form.rhtml b/app/views/role/_form.rhtml index 9e7bf39..a496108 100644 --- a/app/views/role/_form.rhtml +++ b/app/views/role/_form.rhtml @@ -5,7 +5,7 @@ <%= f.text_field :name %> <%= _('Permissions: ') %>
- <% Profile::PERMISSIONS[:profile].keys.each do |p| %> + <% permissions.keys.each do |p| %> <%= labelled_form_field(permission_name(p), (check_box_tag "role[permissions][]", p, @role.has_permission?(p))) %> <% end %> diff --git a/app/views/role/new.rhtml b/app/views/role/new.rhtml index 2497ce5..e13d636 100644 --- a/app/views/role/new.rhtml +++ b/app/views/role/new.rhtml @@ -1,3 +1,6 @@

<%= _('New Role') %>

-<%= render :partial => 'form', :locals => { :mode => :new } %> +<% ActiveRecord::Base::PERMISSIONS.keys.each do |perm_class| %> +

<%= perm_class %>

+ <%= render :partial => 'form', :locals => { :mode => :new, :permissions => ActiveRecord::Base::PERMISSIONS[perm_class] } %> +<% end %> diff --git a/public/stylesheets/menu.css b/public/stylesheets/menu.css index aae3a51..591074f 100644 --- a/public/stylesheets/menu.css +++ b/public/stylesheets/menu.css @@ -358,3 +358,6 @@ li#category4 ul li a:hover { color: black; } +div#user_options *{ + color: white; +} diff --git a/test/functional/environment_role_manager_controller_test.rb b/test/functional/environment_role_manager_controller_test.rb new file mode 100644 index 0000000..e5adc1c --- /dev/null +++ b/test/functional/environment_role_manager_controller_test.rb @@ -0,0 +1,18 @@ +require File.dirname(__FILE__) + '/../test_helper' +require 'environment_role_manager_controller' + +# Re-raise errors caught by the controller. +class EnvironmentRoleManagerController; def rescue_action(e) raise e end; end + +class EnvironmentRoleManagerControllerTest < Test::Unit::TestCase + def setup + @controller = EnvironmentRoleManagerController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + end + + # Replace this with your real tests. + def test_truth + assert true + end +end -- libgit2 0.21.2