diff --git a/app/controllers/role_controller.rb b/app/controllers/role_controller.rb
new file mode 100644
index 0000000..a50b423
--- /dev/null
+++ b/app/controllers/role_controller.rb
@@ -0,0 +1,47 @@
+class RoleController < ApplicationController
+ def index
+ @roles = Role.find(:all)
+ end
+
+ def show
+ @role = Role.find(params[:id])
+ end
+
+ def new
+ @role = Role.new(:name => 'bla', :permissions => [])
+ end
+
+ def create
+ role = Role.new(params[:role])
+ if role.save
+ redirect_to :action => 'show', :id => role
+ else
+ flash[:notice] = _('Failed to create role')
+ redirect_to :action => 'index'
+ end
+ end
+
+ def edit
+ @role = Role.find(params[:id])
+ end
+
+ def update
+ role = Role.find(params[:id])
+ if role.update_attributes(params[:role])
+ redirect_to :action => 'show', :id => role
+ else
+ flash[:notice] = _('Failed to edit role')
+ render :action => 'edit'
+ end
+ end
+
+ def destroy
+ role = Role.find(params[:id])
+ if role.destroy
+ redirect_to :action => 'index'
+ else
+ flash[:notice] = _('Failed to edit role')
+ redirect_to :action => 'index'
+ end
+ end
+end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 6a1fdfa..0a92b9b 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -167,6 +167,8 @@ module ApplicationHelper
content_tag('div', content_tag('div', content_tag('label', label)) + html_for_field, :class => 'formfield')
end
+ alias_method :labelled_form_field, :display_form_field
+
def labelled_form_for(name, object = nil, options = {}, &proc)
object ||= instance_variable_get("@#{name}")
form_for(name, object, { :builder => NoosferoFormBuilder }.merge(options), &proc)
diff --git a/app/helpers/role_helper.rb b/app/helpers/role_helper.rb
new file mode 100644
index 0000000..244d2a2
--- /dev/null
+++ b/app/helpers/role_helper.rb
@@ -0,0 +1,2 @@
+module RoleHelper
+end
diff --git a/app/models/person.rb b/app/models/person.rb
index d3158fa..65757d1 100644
--- a/app/models/person.rb
+++ b/app/models/person.rb
@@ -14,6 +14,12 @@ class Person < Profile
has_many :people, :through => :person_friendships, :foreign_key => 'friend_id'
has_one :person_info
+ has_many :role_assignments
+
+ def has_permission?(perm, res=nil)
+ role_assignments.any? {|ra| ra.has_permission?(perm, res)}
+ end
+
def info
person_info
end
diff --git a/app/models/profile.rb b/app/models/profile.rb
index 891e301..01820ed 100644
--- a/app/models/profile.rb
+++ b/app/models/profile.rb
@@ -35,6 +35,8 @@ class Profile < ActiveRecord::Base
belongs_to :virtual_community
has_many :affiliations, :dependent => :destroy
has_many :people, :through => :affiliations
+
+ has_many :role_assignment, :as => :resource
# Sets the identifier for this profile. Raises an exception when called on a
diff --git a/app/models/role.rb b/app/models/role.rb
new file mode 100644
index 0000000..84d2fb3
--- /dev/null
+++ b/app/models/role.rb
@@ -0,0 +1,31 @@
+class Role < ActiveRecord::Base
+
+ PERMISSIONS = {
+ :profile => {
+ 'edit_profile' => N_('Edit profile'),
+ 'post_content' => N_('Post content'),
+ 'destroy_profile' => N_('Destroy profile'),
+ },
+ :system => {
+ }
+ }
+
+ def self.permission_name(p)
+# msgid = ...
+# gettext(msgid)
+ raise "Moises need to write me"
+ end
+
+ has_many :role_assignments
+
+ serialize :permissions, Array
+
+ def initialize(*args)
+ super(*args)
+ permissions = []
+ end
+
+ def has_permission?(perm)
+ permissions.include?(perm)
+ end
+end
diff --git a/app/models/role_assignment.rb b/app/models/role_assignment.rb
new file mode 100644
index 0000000..aa02c58
--- /dev/null
+++ b/app/models/role_assignment.rb
@@ -0,0 +1,9 @@
+class RoleAssignment < ActiveRecord::Base
+ belongs_to :role
+ belongs_to :person
+ belongs_to :resource, :polymorphic => true
+
+ def has_permission?(perm, res)
+ role.has_permission?(perm) && (resource == res)
+ end
+end
diff --git a/app/views/role/_form.rhtml b/app/views/role/_form.rhtml
new file mode 100644
index 0000000..1ed5c67
--- /dev/null
+++ b/app/views/role/_form.rhtml
@@ -0,0 +1,11 @@
+<%= error_messages_for :role %>
+
+<% labelled_form_for :role, @role do |f| %>
+
+ <%= f.text_field :name %>
+
+ <%= _('Permissions: ') %>
+ <% Role::PERMISSIONS[:profile].keys.each do |p| %>
+ <%= labelled_form_field("bla", (check_box_tag "role[permissions][#{p}]", @role.has_permission?(p))) %>
+ <% end %>
+<% end %>
diff --git a/app/views/role/index.rhtml b/app/views/role/index.rhtml
new file mode 100644
index 0000000..d358fe2
--- /dev/null
+++ b/app/views/role/index.rhtml
@@ -0,0 +1,10 @@
+<%= link_to _('New role'), :action => 'new' %>
+