Adding resource category edit abilities
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user