Adding resource category edit abilities

This commit is contained in:
2014-02-14 00:02:11 -07:00
parent 3f5a7012bd
commit 3d97e92eb7
19 changed files with 173 additions and 37 deletions

View File

@@ -5,6 +5,7 @@ class Ability
can :read, Mac # Anonymous can read mac
can :scan, Mac # Need anonymous so CRON can scan
can :read, Resource
can :read, ResourceCategory
if !user.nil?
@@ -36,7 +37,8 @@ class Ability
unless user.orientation.blank?
can [:read,:new_member_report,:activity], User, :hidden => [nil,false]
can :read, UserCertification
can [:create,:update,:destroy], Resource, :user_id => [nil,user.id]
can [:create,:update], Resource, :user_id => [nil,user.id]
can [:create,:update,:destroy], ResourceCategory
end
# Accountants can manage payments

View File

@@ -1,9 +1,9 @@
class Resource < ActiveRecord::Base
attr_accessible :supercategory, :user_id, :category_id, :name, :serial, :specs, :status, :donatable, :picture, :picture_file_name, :picture_content_type, :picture_file_size, :picture_updated_at, :notes, :estimated_value, :disposed_at, :modified_by
attr_accessible :supercategory, :user_id, :resource_category_id, :name, :serial, :specs, :status, :donatable, :picture, :picture_file_name, :picture_content_type, :picture_file_size, :picture_updated_at, :notes, :estimated_value, :disposed_at, :modified_by
belongs_to :owner, :class_name => "ToolshareUser" #TODO: remove owner
belongs_to :user
belongs_to :category, :class_name => "ResourceCategory"
belongs_to :resource_category
has_attached_file :picture, #TODO: move to local storage
:styles => { :medium => "300x300>",
:thumb => "100x100>",
@@ -13,7 +13,7 @@ class Resource < ActiveRecord::Base
:path => ":attachment/:id/:style.:extension",
:bucket => 'Toolshare'
def category_name
self.category.name if self.category
def resource_category_name
resource_category.name if resource_category
end
end

View File

@@ -1,3 +1,13 @@
class ResourceCategory < ActiveRecord::Base
has_many :resources
attr_accessible :name
before_destroy :has_resources?
private
def has_resources?
errors.add(:base, "Cannot delete category with associated resources") unless resources.count == 0
errors.blank? #return false, to not destroy the element, otherwise, it will delete.
end
end