summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-02-22 07:08:23 -0500
committerPeter Kozak <spag@golwen.net>2013-02-22 07:08:23 -0500
commit2a9b798f9e122582abb36605a7d4a1da0e70eca9 (patch)
tree45fe362d677cb243fba57dc7c0c23d01e653863e /app
parentd6009d77ffa221c14a4536be98a04e8e4b6474a9 (diff)
pickup group permission model added
Diffstat (limited to 'app')
-rw-r--r--app/controllers/group_memberships_controller.rb51
-rw-r--r--app/controllers/group_permissions_controller.rb48
-rw-r--r--app/controllers/groups_controller.rb49
-rw-r--r--app/helpers/group_memberships_helper.rb2
-rw-r--r--app/helpers/group_permissions_helper.rb2
-rw-r--r--app/helpers/groups_helper.rb2
-rw-r--r--app/models/group.rb11
-rw-r--r--app/models/group_membership.rb37
-rw-r--r--app/models/group_permission.rb24
-rw-r--r--app/views/group_memberships/_form.html.haml7
-rw-r--r--app/views/group_memberships/_form_core.html.haml4
-rw-r--r--app/views/group_memberships/_index_core.html.haml11
-rw-r--r--app/views/group_memberships/edit.html.haml3
-rw-r--r--app/views/group_memberships/index.html.haml6
-rw-r--r--app/views/group_memberships/new.html.haml3
-rw-r--r--app/views/group_memberships/show.html.haml10
-rw-r--r--app/views/group_permissions/_form.html.haml7
-rw-r--r--app/views/group_permissions/_form_core.html.haml3
-rw-r--r--app/views/group_permissions/_index_core.html.haml11
-rw-r--r--app/views/group_permissions/edit.html.haml3
-rw-r--r--app/views/group_permissions/index.html.haml6
-rw-r--r--app/views/group_permissions/new.html.haml3
-rw-r--r--app/views/group_permissions/show.html.haml10
-rw-r--r--app/views/groups/_form.html.haml7
-rw-r--r--app/views/groups/_form_core.html.haml4
-rw-r--r--app/views/groups/_index_core.html.haml13
-rw-r--r--app/views/groups/edit.html.haml3
-rw-r--r--app/views/groups/index.html.haml6
-rw-r--r--app/views/groups/new.html.haml3
-rw-r--r--app/views/groups/show.html.haml25
30 files changed, 374 insertions, 0 deletions
diff --git a/app/controllers/group_memberships_controller.rb b/app/controllers/group_memberships_controller.rb
new file mode 100644
index 0000000..df9f6b3
--- /dev/null
+++ b/app/controllers/group_memberships_controller.rb
@@ -0,0 +1,51 @@
+class GroupMembershipsController < ApplicationController
+ load_and_authorize_resource :group
+ load_and_authorize_resource :group_membership, :through => [:group]
+
+ def index
+ end
+
+ def show
+ end
+
+ def new
+ end
+
+ def create
+ if params[:group_membership][:item_type].blank?
+ params[:group_membership][:item_type] = @group.group_memberships.first.item_type
+ end
+ @group_membership = @group.group_memberships.new(params[:group_membership])
+ if @group_membership.save
+ redirect_to action: "index", :notice => t('group_memberships.controller.successfuly_created')
+ else
+ render :new
+ end
+ end
+
+ def edit
+ end
+
+ def update
+ if @group_membership.update_attributes(params[:group_membership])
+ redirect_to action: "index", :notice => t('group_memberships.controller.successfuly_updated')
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @group_membership.destroy
+ redirect_to action: "index", :notice => t('group_memberships.controller.successfuly_destroyed')
+ end
+
+ private
+ def spread_breadcrumbs
+ add_breadcrumb t("groups.index.page_title"), groups_path
+ add_breadcrumb @group, group_path(@group)
+ add_breadcrumb t("group_memberships.index.page_title"), group_group_memberships_path(@group)
+ if @group_membership && !@group_membership.new_record?
+ add_breadcrumb @group_membership, group_group_membership_path(@group, @group_membership)
+ end
+ end
+end
diff --git a/app/controllers/group_permissions_controller.rb b/app/controllers/group_permissions_controller.rb
new file mode 100644
index 0000000..3abdc51
--- /dev/null
+++ b/app/controllers/group_permissions_controller.rb
@@ -0,0 +1,48 @@
+class GroupPermissionsController < ApplicationController
+ load_and_authorize_resource :group
+ load_and_authorize_resource :group_permission, :through => [:group]
+
+ def index
+ end
+
+ def show
+ end
+
+ def new
+ end
+
+ def create
+ @group_permission = @group.group_permissions.new(params[:group_permission])
+ if @group_permission.save
+ redirect_to action: "index", :notice => t('group_permissions.controller.successfuly_created')
+ else
+ render :new
+ end
+ end
+
+ def edit
+ end
+
+ def update
+ if @group_permission.update_attributes(params[:group_permission])
+ redirect_to action: "index", :notice => t('group_permissions.controller.successfuly_updated')
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @group_permission.destroy
+ redirect_to action: "index", :notice => t('group_permissions.controller.successfuly_destroyed')
+ end
+
+ private
+ def spread_breadcrumbs
+ add_breadcrumb t("groups.index.page_title"), groups_path
+ add_breadcrumb @group, group_path(@group)
+ add_breadcrumb t("group_permissions.index.page_title"), group_group_permissions_path(@group)
+ if @group_permission && !@group_permission.new_record?
+ add_breadcrumb @group_permission, group_group_permission_path(@group, @group_permission)
+ end
+ end
+end
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb
new file mode 100644
index 0000000..1ab7a4f
--- /dev/null
+++ b/app/controllers/groups_controller.rb
@@ -0,0 +1,49 @@
+class GroupsController < ApplicationController
+ def index
+ @groups = Group.all
+ end
+
+ def show
+ @group = Group.find(params[:id])
+ end
+
+ def new
+ @group = Group.new
+ end
+
+ def create
+ @group = Group.new(params[:group])
+ if @group.save
+ redirect_to @group, :notice => t('groups.controller.successfuly_created')
+ else
+ render :new
+ end
+ end
+
+ def edit
+ @group = Group.find(params[:id])
+ end
+
+ def update
+ @group = Group.find(params[:id])
+ if @group.update_attributes(params[:group])
+ redirect_to @group, :notice => t('groups.controller.successfuly_updated')
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @group = Group.find(params[:id])
+ @group.destroy
+ redirect_to groups_url, :notice => t('groups.controller.successfuly_destroyed')
+ end
+
+ private
+ def spread_breadcrumbs
+ add_breadcrumb t("groups.index.page_title"), groups_path
+ if @group && !@group.new_record?
+ add_breadcrumb @group, @group
+ end
+ end
+end
diff --git a/app/helpers/group_memberships_helper.rb b/app/helpers/group_memberships_helper.rb
new file mode 100644
index 0000000..837bafd
--- /dev/null
+++ b/app/helpers/group_memberships_helper.rb
@@ -0,0 +1,2 @@
+module GroupMembershipsHelper
+end
diff --git a/app/helpers/group_permissions_helper.rb b/app/helpers/group_permissions_helper.rb
new file mode 100644
index 0000000..45571d0
--- /dev/null
+++ b/app/helpers/group_permissions_helper.rb
@@ -0,0 +1,2 @@
+module GroupPermissionsHelper
+end
diff --git a/app/helpers/groups_helper.rb b/app/helpers/groups_helper.rb
new file mode 100644
index 0000000..c091b2f
--- /dev/null
+++ b/app/helpers/groups_helper.rb
@@ -0,0 +1,2 @@
+module GroupsHelper
+end
diff --git a/app/models/group.rb b/app/models/group.rb
new file mode 100644
index 0000000..e0cfaab
--- /dev/null
+++ b/app/models/group.rb
@@ -0,0 +1,11 @@
+class Group < ActiveRecord::Base
+ attr_accessible :name, :active, :comment
+
+ has_many :group_memberships, :dependent => :destroy
+ has_many :group_permissions, :dependent => :destroy
+ has_many :permittances, :foreign_key => :target_group_id, :class_name => "GroupPermission", :dependent => :destroy
+
+ def to_s
+ self.name
+ end
+end
diff --git a/app/models/group_membership.rb b/app/models/group_membership.rb
new file mode 100644
index 0000000..0f04ae1
--- /dev/null
+++ b/app/models/group_membership.rb
@@ -0,0 +1,37 @@
+class GroupMembership < ActiveRecord::Base
+ attr_accessible :group_id, :item_type, :item_id
+
+ belongs_to :group
+ belongs_to :item, :polymorphic => true
+
+ validates :item_id,
+ :presence => true,
+ :uniqueness => { :scope => [:group_id, :item_type] }
+
+ validates :item_type,
+ :presence => true,
+ :uniqueness => { :scope => [:group_id, :item_id] }
+
+ validate :validate_item_type_consitency
+
+ validates :item,
+ :presence => true
+
+ def to_s
+ "#{self.item_type}: #{self.item}"
+ end
+
+ def item_type_allowed
+ fist_item = self.group.group_memberships.first.try(:item)
+ if fist_item
+ return fist_item.class.name
+ end
+ end
+
+ def validate_item_type_consitency
+ type_allowed = self.item_type_allowed
+ if type_allowed && type_allowed != self.item_type
+ errors.add(:item_type, "must be of type: #{type_allowed}")
+ end
+ end
+end
diff --git a/app/models/group_permission.rb b/app/models/group_permission.rb
new file mode 100644
index 0000000..fe988ba
--- /dev/null
+++ b/app/models/group_permission.rb
@@ -0,0 +1,24 @@
+class GroupPermission < ActiveRecord::Base
+ attr_accessible :group_id, :permission, :target_group_id
+
+ PERMISSION_TYPES = ['pickup']
+
+ belongs_to :group
+ belongs_to :target_group, :class_name => "Group"
+
+ validates :target_group_id,
+ :presence => true,
+ :uniqueness => { :scope => [:group_id, :permission] }
+
+ validates :target_group,
+ :presence => true
+
+ validates :permission,
+ :presence => true,
+ :uniqueness => { :scope => [:group_id, :target_group_id] },
+ :inclusion => { :in => PERMISSION_TYPES }
+
+ def to_s
+ "#{self.permission} => #{self.target_group}"
+ end
+end
diff --git a/app/views/group_memberships/_form.html.haml b/app/views/group_memberships/_form.html.haml
new file mode 100644
index 0000000..c8a6a51
--- /dev/null
+++ b/app/views/group_memberships/_form.html.haml
@@ -0,0 +1,7 @@
+= simple_form_for([@group, @group_membership]) do |f|
+ = f.error_notification
+
+ = render "form_core", :f => f
+
+ .form-actions
+ = f.button :submit, conditional_t('group_memberships.form.submit')
diff --git a/app/views/group_memberships/_form_core.html.haml b/app/views/group_memberships/_form_core.html.haml
new file mode 100644
index 0000000..4a28a06
--- /dev/null
+++ b/app/views/group_memberships/_form_core.html.haml
@@ -0,0 +1,4 @@
+.inputs
+ - if @group.group_memberships.count < 1
+ = f.input :item_type, :label => t('group_memberships.form.item_type.label'), :hint => conditional_hint('group_memberships.form.item_type.hint')
+ = f.input :item_id, :label => t('group_memberships.form.item_id.label'), :hint => conditional_hint('group_memberships.form.item_id.hint')
diff --git a/app/views/group_memberships/_index_core.html.haml b/app/views/group_memberships/_index_core.html.haml
new file mode 100644
index 0000000..beeefc9
--- /dev/null
+++ b/app/views/group_memberships/_index_core.html.haml
@@ -0,0 +1,11 @@
+%table.table.table-striped
+ %tr
+ %th= t('group_memberships.index.item_type')
+ %th= t('group_memberships.index.item_id')
+
+
+ - for group_membership in group_memberships
+ %tr
+ %td= group_membership.item_type
+ %td= group_membership.item_id
+ =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => group_membership.group, :child => group_membership}
diff --git a/app/views/group_memberships/edit.html.haml b/app/views/group_memberships/edit.html.haml
new file mode 100644
index 0000000..643c095
--- /dev/null
+++ b/app/views/group_memberships/edit.html.haml
@@ -0,0 +1,3 @@
+- content_for :title, t("group_memberships.edit.page_title")
+
+= render "form" \ No newline at end of file
diff --git a/app/views/group_memberships/index.html.haml b/app/views/group_memberships/index.html.haml
new file mode 100644
index 0000000..b493017
--- /dev/null
+++ b/app/views/group_memberships/index.html.haml
@@ -0,0 +1,6 @@
+- content_for :title, t("group_memberships.index.page_title")
+
+- if @group_memberships && @group_memberships.count > 0
+ = render "index_core", :group_memberships => @group_memberships
+
+= render :partial => 'shared/create_link', :locals => {:parent => @group, :child_class => GroupMembership}
diff --git a/app/views/group_memberships/new.html.haml b/app/views/group_memberships/new.html.haml
new file mode 100644
index 0000000..6cf2ce7
--- /dev/null
+++ b/app/views/group_memberships/new.html.haml
@@ -0,0 +1,3 @@
+- content_for :title, t("group_memberships.new.page_title")
+
+= render "form" \ No newline at end of file
diff --git a/app/views/group_memberships/show.html.haml b/app/views/group_memberships/show.html.haml
new file mode 100644
index 0000000..0875f0b
--- /dev/null
+++ b/app/views/group_memberships/show.html.haml
@@ -0,0 +1,10 @@
+- content_for :title, t("group_memberships.show.page_title")
+
+%p
+ %strong= t('group_memberships.show.item_type') + ":"
+ = @group_membership.item_type
+%p
+ %strong= t('group_memberships.show.item_id') + ":"
+ = @group_membership.item_id
+
+= render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @group, :child => @group_membership }
diff --git a/app/views/group_permissions/_form.html.haml b/app/views/group_permissions/_form.html.haml
new file mode 100644
index 0000000..5f593f2
--- /dev/null
+++ b/app/views/group_permissions/_form.html.haml
@@ -0,0 +1,7 @@
+= simple_form_for([@group, @group_permission]) do |f|
+ = f.error_notification
+
+ = render "form_core", :f => f
+
+ .form-actions
+ = f.button :submit, conditional_t('group_permissions.form.submit')
diff --git a/app/views/group_permissions/_form_core.html.haml b/app/views/group_permissions/_form_core.html.haml
new file mode 100644
index 0000000..49c9e7c
--- /dev/null
+++ b/app/views/group_permissions/_form_core.html.haml
@@ -0,0 +1,3 @@
+.inputs
+ = f.input :permission, :collection => GroupPermission::PERMISSION_TYPES, :label => t('group_permissions.form.permission.label'), :hint => conditional_hint('group_permissions.form.permission.hint'), :include_blank => false
+ = f.input :target_group_id, :collection => Group.all.collect, :label => t('group_permissions.form.target_group_id.label'), :hint => conditional_hint('group_permissions.form.target_group_id.hint'), :include_blank => false
diff --git a/app/views/group_permissions/_index_core.html.haml b/app/views/group_permissions/_index_core.html.haml
new file mode 100644
index 0000000..ad06b38
--- /dev/null
+++ b/app/views/group_permissions/_index_core.html.haml
@@ -0,0 +1,11 @@
+%table.table.table-striped
+ %tr
+ %th= t('group_permissions.index.permission')
+ %th= t('group_permissions.index.target_group_id')
+
+
+ - for group_permission in group_permissions
+ %tr
+ %td= group_permission.permission
+ %td= group_permission.target_group
+ =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => group_permission.group, :child => group_permission}
diff --git a/app/views/group_permissions/edit.html.haml b/app/views/group_permissions/edit.html.haml
new file mode 100644
index 0000000..c673eea
--- /dev/null
+++ b/app/views/group_permissions/edit.html.haml
@@ -0,0 +1,3 @@
+- content_for :title, t("group_permissions.edit.page_title")
+
+= render "form" \ No newline at end of file
diff --git a/app/views/group_permissions/index.html.haml b/app/views/group_permissions/index.html.haml
new file mode 100644
index 0000000..0bc0c37
--- /dev/null
+++ b/app/views/group_permissions/index.html.haml
@@ -0,0 +1,6 @@
+- content_for :title, t("group_permissions.index.page_title")
+
+- if @group_permissions && @group_permissions.count > 0
+ = render "index_core", :group_permissions => @group_permissions
+
+= render :partial => 'shared/create_link', :locals => {:parent => @group, :child_class => GroupPermission} \ No newline at end of file
diff --git a/app/views/group_permissions/new.html.haml b/app/views/group_permissions/new.html.haml
new file mode 100644
index 0000000..8012273
--- /dev/null
+++ b/app/views/group_permissions/new.html.haml
@@ -0,0 +1,3 @@
+- content_for :title, t("group_permissions.new.page_title")
+
+= render "form" \ No newline at end of file
diff --git a/app/views/group_permissions/show.html.haml b/app/views/group_permissions/show.html.haml
new file mode 100644
index 0000000..402c5ce
--- /dev/null
+++ b/app/views/group_permissions/show.html.haml
@@ -0,0 +1,10 @@
+- content_for :title, t("group_permissions.show.page_title")
+
+%p
+ %strong= t('group_permissions.show.permission') + ":"
+ = @group_permission.permission
+%p
+ %strong= t('group_permissions.show.target_group_id') + ":"
+ = @group_permission.target_group_id
+
+= render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @group, :child => @group_permission }
diff --git a/app/views/groups/_form.html.haml b/app/views/groups/_form.html.haml
new file mode 100644
index 0000000..f5bdece
--- /dev/null
+++ b/app/views/groups/_form.html.haml
@@ -0,0 +1,7 @@
+= simple_form_for(@group) do |f|
+ = f.error_notification
+
+ = render "form_core", :f => f
+
+ .form-actions
+ = f.button :submit, conditional_t('groups.form.submit')
diff --git a/app/views/groups/_form_core.html.haml b/app/views/groups/_form_core.html.haml
new file mode 100644
index 0000000..1f9a39f
--- /dev/null
+++ b/app/views/groups/_form_core.html.haml
@@ -0,0 +1,4 @@
+.inputs
+ = f.input :name, :label => t('groups.form.name.label'), :hint => conditional_hint('groups.form.name.hint')
+ = f.input :active, :label => t('groups.form.active.label'), :hint => conditional_hint('groups.form.active.hint')
+ = f.input :comment, :label => t('groups.form.comment.label'), :hint => conditional_hint('groups.form.comment.hint')
diff --git a/app/views/groups/_index_core.html.haml b/app/views/groups/_index_core.html.haml
new file mode 100644
index 0000000..d99874a
--- /dev/null
+++ b/app/views/groups/_index_core.html.haml
@@ -0,0 +1,13 @@
+%table.table.table-striped
+ %tr
+ %th= t('groups.index.name')
+ %th= t('groups.index.active')
+ %th= t('groups.index.comment')
+
+
+ - for group in groups
+ %tr
+ %td= group.name
+ %td= group.active
+ %td= group.comment
+ =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => group} \ No newline at end of file
diff --git a/app/views/groups/edit.html.haml b/app/views/groups/edit.html.haml
new file mode 100644
index 0000000..7a3f784
--- /dev/null
+++ b/app/views/groups/edit.html.haml
@@ -0,0 +1,3 @@
+- content_for :title, t("groups.edit.page_title")
+
+= render "form" \ No newline at end of file
diff --git a/app/views/groups/index.html.haml b/app/views/groups/index.html.haml
new file mode 100644
index 0000000..7984b9e
--- /dev/null
+++ b/app/views/groups/index.html.haml
@@ -0,0 +1,6 @@
+- content_for :title, t("groups.index.page_title")
+
+- if @groups && @groups.count > 0
+ = render "index_core", :groups => @groups
+
+= render :partial => 'shared/create_link', :locals => {:child_class => Group} \ No newline at end of file
diff --git a/app/views/groups/new.html.haml b/app/views/groups/new.html.haml
new file mode 100644
index 0000000..e8017a8
--- /dev/null
+++ b/app/views/groups/new.html.haml
@@ -0,0 +1,3 @@
+- content_for :title, t("groups.new.page_title")
+
+= render "form" \ No newline at end of file
diff --git a/app/views/groups/show.html.haml b/app/views/groups/show.html.haml
new file mode 100644
index 0000000..fc291f3
--- /dev/null
+++ b/app/views/groups/show.html.haml
@@ -0,0 +1,25 @@
+- content_for :title, t("groups.show.page_title")
+
+%p
+ %strong= t('groups.show.name') + ":"
+ = @group.name
+%p
+ %strong= t('groups.show.active') + ":"
+ = @group.active
+%p
+ %strong= t('groups.show.comment') + ":"
+ = @group.comment
+
+= render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @group }
+
+%h3= t('group_permissions.index.page_title')
+- if @group.group_permissions.any?
+ = render "group_permissions/index_core", :group_permissions => @group.group_permissions
+ %br
+= render :partial => 'shared/create_link', :locals => { :parent => @group, :child_class => GroupPermission }
+
+%h3= t('group_memberships.index.page_title')
+- if @group.group_memberships.any?
+ = render "group_memberships/index_core", :group_memberships => @group.group_memberships
+ %br
+= render :partial => 'shared/create_link', :locals => { :parent => @group, :child_class => GroupMembership }