From 9b38a790fce2a99c7506ba544840e423015e5726 Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Mon, 15 Oct 2007 17:53:10 +0000 Subject: [PATCH] ActionItem75: some more changes to fit with the access_control plugin and to define the permissions --- app/controllers/application.rb | 1 - app/helpers/application_helper.rb | 3 ++- app/models/profile.rb | 7 +++++++ app/views/role/_form.rhtml | 4 ++-- app/views/role/show.rhtml | 2 +- test/fixtures/role_assignments.yml | 22 ++++++++++++++++++++++ test/fixtures/roles.yml | 19 +++++++++++++++++++ 7 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 test/fixtures/role_assignments.yml create mode 100644 test/fixtures/roles.yml diff --git a/app/controllers/application.rb b/app/controllers/application.rb index ee929e9..02e0df2 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -10,7 +10,6 @@ class ApplicationController < ActionController::Base # Be sure to include AuthenticationSystem in Application Controller instead include AuthenticatedSystem extend PermissionCheck - init_gettext 'noosfero' before_filter :detect_stuff_by_domain, :load_profile_from_params diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 36b17a5..c716990 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,7 +1,8 @@ # Methods added to this helper will be available to all templates in the # application. module ApplicationHelper - + include PermissionName + # Displays context help. You can pass the content of the help message as the # first parameter or using template code inside a block passed to this # method. *Note*: the block is ignored if content is not diff --git a/app/models/profile.rb b/app/models/profile.rb index aef8a31..c2b14f8 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -3,6 +3,13 @@ # which by default is the one returned by Environment:default. class Profile < ActiveRecord::Base + PERMISSIONS[:profile] = { + 'edit_profile' => N_('Edit profile'), + 'destroy_profile' => N_('Destroy profile'), + 'manage_memberships' => N_('Manage memberships'), + 'post_content' => N_('Post content'), + } + after_create do |profile| homepage = Article.new homepage.title = profile.name diff --git a/app/views/role/_form.rhtml b/app/views/role/_form.rhtml index ec337b0..9e7bf39 100644 --- a/app/views/role/_form.rhtml +++ b/app/views/role/_form.rhtml @@ -5,8 +5,8 @@ <%= f.text_field :name %> <%= _('Permissions: ') %>
- <% Role::PERMISSIONS[:profile].keys.each do |p| %> - <%= labelled_form_field(Role.permission_name(p), (check_box_tag "role[permissions][]", p, @role.has_permission?(p))) %> + <% Profile::PERMISSIONS[:profile].keys.each do |p| %> + <%= labelled_form_field(permission_name(p), (check_box_tag "role[permissions][]", p, @role.has_permission?(p))) %> <% end %> <%= submit_tag (mode == :edit) ? _('Save changes') : _('Create role')%> diff --git a/app/views/role/show.rhtml b/app/views/role/show.rhtml index 3e89eec..5db3517 100644 --- a/app/views/role/show.rhtml +++ b/app/views/role/show.rhtml @@ -3,7 +3,7 @@

<%= _('Permissions') %>

diff --git a/test/fixtures/role_assignments.yml b/test/fixtures/role_assignments.yml new file mode 100644 index 0000000..de54bed --- /dev/null +++ b/test/fixtures/role_assignments.yml @@ -0,0 +1,22 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +one: + id: 1 + accessor_id: 4 + accessor_type: 'Person' + role_id: 2 + resource_id: 5 + resource_type: 'Profile' +two: + id: 2 + accessor_id: 1 + accessor_type: 'Person' + role_id: 1 + resource_id: 5 + resource_type: 'Profile' +three: + id: 3 + accessor_id: 1 + accessor_type: 'Person' + role_id: 1 + resource_id: 6 + resource_type: 'Profile' diff --git a/test/fixtures/roles.yml b/test/fixtures/roles.yml new file mode 100644 index 0000000..8422c30 --- /dev/null +++ b/test/fixtures/roles.yml @@ -0,0 +1,19 @@ +# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html +one: + id: 1 + name: 'member' + permissions: + - post_content +two: + id: 2 + name: 'owner' + permissions: + - menage_memberships + - post_content + - destroy_profile + - edit_profile +three: + id: 3 + name: 'moderator' + permissions: + - manage_memberships -- libgit2 0.21.2