Class: CantangoEditor::Permissions
- Inherits:
-
Object
- Object
- CantangoEditor::Permissions
- Defined in:
- app/models/cantango_editor/permissions.rb
Class Attribute Summary collapse
-
.permissions ⇒ Object
Returns the value of attribute permissions.
Class Method Summary collapse
- .configuration ⇒ Object
- .create_empty_permissions_file ⇒ Object
- .models_available_names ⇒ Object
- .permission_types_nil_hash ⇒ Object
- .permissions_file ⇒ Object
- .permissions_file_path ⇒ Object
- .persist_permissions! ⇒ Object
- .raw_file_content ⇒ Object
- .remove_and_save_permissions(permissions_hash) ⇒ Object
- .save_new_permissions(permissions_hash) ⇒ Object
- .update_new_permissions(permissions_hash) ⇒ Object
- .update_permissions!(params) ⇒ Object
- .update_remove_permissions(permissions_hash) ⇒ Object
- .validate_content(yml_content) ⇒ Object
- .yml_file_content ⇒ Object
Class Attribute Details
.permissions ⇒ Object
Returns the value of attribute permissions.
5 6 7 |
# File 'app/models/cantango_editor/permissions.rb', line 5 def @permissions end |
Class Method Details
.configuration ⇒ Object
14 15 16 |
# File 'app/models/cantango_editor/permissions.rb', line 14 def configuration CantangoEditor::Configuration end |
.create_empty_permissions_file ⇒ Object
106 107 108 109 110 111 112 |
# File 'app/models/cantango_editor/permissions.rb', line 106 def File.open(, 'w') do |file| YAML.dump(, file) end end |
.models_available_names ⇒ Object
18 19 20 |
# File 'app/models/cantango_editor/permissions.rb', line 18 def models_available_names models_available.map(&:name).unshift "all" end |
.permission_types_nil_hash ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'app/models/cantango_editor/permissions.rb', line 22 def .inject({}) do |result_hash, pt| roles_hash = ([pt] || []).inject({}) do |rh, r| rh.merge({r.to_s => nil}) end result_hash.merge!({pt.to_s => roles_hash}) end end |
.permissions_file ⇒ Object
100 101 102 103 104 |
# File 'app/models/cantango_editor/permissions.rb', line 100 def if !File.file? end |
.permissions_file_path ⇒ Object
114 115 116 |
# File 'app/models/cantango_editor/permissions.rb', line 114 def File.join Rails.root + "config/" + "permissions.yml" end |
.persist_permissions! ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/models/cantango_editor/permissions.rb', line 63 def yml = YAML.dump() # Sanitize permissions hash yml.gsub!(/\!map.*\s/,"\n") File.open(, 'w') do |out| out.write yml end end |
.raw_file_content ⇒ Object
75 76 77 78 79 80 81 82 83 84 |
# File 'app/models/cantango_editor/permissions.rb', line 75 def raw_file_content raw_content = "" File.open(, 'r') do |f| raw_content = f.read end raw_content rescue => e raise e end |
.remove_and_save_permissions(permissions_hash) ⇒ Object
49 50 51 52 53 54 |
# File 'app/models/cantango_editor/permissions.rb', line 49 def return unless end |
.save_new_permissions(permissions_hash) ⇒ Object
56 57 58 59 60 61 |
# File 'app/models/cantango_editor/permissions.rb', line 56 def return unless end |
.update_new_permissions(permissions_hash) ⇒ Object
41 42 43 |
# File 'app/models/cantango_editor/permissions.rb', line 41 def . end |
.update_permissions!(params) ⇒ Object
36 37 38 39 |
# File 'app/models/cantango_editor/permissions.rb', line 36 def params params[:new_permissions] params[:delete_permissions] end |
.update_remove_permissions(permissions_hash) ⇒ Object
45 46 47 |
# File 'app/models/cantango_editor/permissions.rb', line 45 def . end |
.validate_content(yml_content) ⇒ Object
95 96 97 98 |
# File 'app/models/cantango_editor/permissions.rb', line 95 def validate_content yml_content raise "#{} should contain Hash-based information" unless yml_content.is_a?(Hash) raise "#{} should not contain permission_types not listed in #permission_types_available" if (yml_content.keys - .to_strings).size > 0 end |
.yml_file_content ⇒ Object
86 87 88 89 90 91 92 93 |
# File 'app/models/cantango_editor/permissions.rb', line 86 def yml_file_content yml_content = YAML.load_file() validate_content yml_content PermissionsHash[yml_content] rescue => e raise e end |