aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/permission.rb16
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/permission.rb b/lib/permission.rb
new file mode 100644
index 0000000..9a68a8e
--- /dev/null
+++ b/lib/permission.rb
@@ -0,0 +1,16 @@
+# methods one_permission and multi_permission are originally authored by ahenobarbi.
+# Refer to http://github.com/ahenobarbi/Gentoo-Recruiters-App/blob/master/lib/permissions/set.rb
+
+def one_permission(permission, &block)
+ define_method("#{permission.to_s}_permitted?", &block)
+end
+
+def multi_permission(*permission_list, &block)
+ permission_list.flatten.each do |target|
+ one_permission(target, &block)
+ end
+end
+
+def permitted_for_roles(*roles)
+ acting_user.signed_up? and roles.flatten.include?(acting_user.role.to_sym)
+end