Class: Permission
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Permission
- Defined in:
- app/models/permission.rb
Overview
SocialStream provides a system of permissions based on the relations of the social network as roles.
Permissions and Relations
Permissions are assigned to Relations, and through relations, to Ties. When a sender establishes a Tie with a receiver, she is granting to the receiver the permissions assigned to Relation of the Tie she has just established.
For example, when Alice establishes a friend tie to Bob, she is granting him the permissions associated with her friend relation. Alice’s friend relation may have different permissions from Bob’s friend relation.
Permissions description
Permissions are composed by action and object. Action and object are typical in content management systems, e.g. create activity
, update tie
, read post
.
Actions
Current available actions are:
create
-
add a new instance of something (activity, tie, post, etc)
read
-
view something
update
-
modify something
destroy
-
delete something
follow
-
subscribe to activity updates from the receiver of the tie
represent
-
give the receiver rights to act as if he were me.
Objectives
activity
-
all the objects in a wall: posts, comments
Other objects currently not implemented could be tie
, post
, comment
or message
Class Method Summary collapse
-
.available(subject) ⇒ Object
Obtains the available permissions for subject, as they are configured in config.available_permissions entry in config/initializers/social_stream.rb.
-
.instances(ary) ⇒ Object
Finds or creates in the database the instances of the permissions described in ary by arrays of [ action, object ].
Instance Method Summary collapse
-
#description(options = {}) ⇒ Object
The permission description.
-
#title(options = {}) ⇒ Object
The permission title.
Class Method Details
.available(subject) ⇒ Object
Obtains the available permissions for subject, as they are configured in config.available_permissions entry in config/initializers/social_stream.rb
It takes STI into account, so it will try to load the permissions of the base_class if the class is not found
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'app/models/permission.rb', line 52 def available(subject) class_name = subject.class.to_s.underscore # TODO add further classes base_class_name = subject.class.base_class.to_s.underscore candidates = [ class_name ] if class_name != base_class_name candidates += [ base_class_name ] end list = nil candidates.each do |n| list = SocialStream..with_indifferent_access[n] break if list.present? end if list.blank? raise "You need to configure SocialStream.available_permissions[:#{ class_name }] in config/initializers/social_stream.rb" end instances list end |
.instances(ary) ⇒ Object
Finds or creates in the database the instances of the permissions described in ary by arrays of [ action, object ]
80 81 82 |
# File 'app/models/permission.rb', line 80 def instances ary ary.map{ |p| find_or_create_by_action_and_object *p } end |
Instance Method Details
#description(options = {}) ⇒ Object
The permission description
91 92 93 |
# File 'app/models/permission.rb', line 91 def description( = {}) i18n_description :detailed, end |
#title(options = {}) ⇒ Object
The permission title
86 87 88 |
# File 'app/models/permission.rb', line 86 def title( = {}) i18n_description :brief, end |