Class: StoreAgent::Node::Permission

Inherits:
Attachment show all
Defined in:
lib/store_agent/node/attachment/permission.rb

Overview

オブジェクトの権限情報

Instance Attribute Summary

Attributes inherited from Attachment

#object

Instance Method Summary collapse

Methods inherited from Attachment

#create, #data, #delete, #initialize, #inspect, #load, #reload, #save

Methods included from Validator

#validates_to_be_excluded_slash!, #validates_to_be_not_guest_identifier!, #validates_to_be_not_nil_value!, #validates_to_be_not_superuser_identifier!, #validates_to_be_string_or_symbol!

Constructor Details

This class inherits a constructor from StoreAgent::Node::Attachment

Instance Method Details

#allow?(permission_name) ⇒ Boolean

オブジェクトに対して、引数で受け取った権限を持つなら true を返す

Returns:

  • (Boolean)


22
23
24
25
26
27
28
29
30
31
# File 'lib/store_agent/node/attachment/permission.rb', line 22

def allow?(permission_name)
  case
  when current_user.super_user?
    true
  when !(permission_value = get_permission_value(permission_name)).nil?
    permission_value
  else
    !!data["guest"][permission_name]
  end
end

#base_pathObject

:nodoc:



59
60
61
# File 'lib/store_agent/node/attachment/permission.rb', line 59

def base_path # :nodoc:
  "#{@object.workspace.permission_dirname}#{@object.path}"
end

#file_pathObject

オブジェクトの権限情報を保存しているファイルの絶対パス



64
65
66
# File 'lib/store_agent/node/attachment/permission.rb', line 64

def file_path
  "#{base_path}#{StoreAgent.config.permission_extension}"
end

#set!(identifier: nil, permission_values: {}) ⇒ Object

権限を設定する



34
35
36
37
38
39
40
41
42
43
# File 'lib/store_agent/node/attachment/permission.rb', line 34

def set!(identifier: nil, permission_values: {})
  return if permission_values.empty?
  user_permission = [identifier].flatten.inject(data["users"]) do |r, id|
    r[id] ||= {}
  end
  permission_values.each do |permission_name, value|
    user_permission[permission_name] = value
  end
  save
end

#unset!(identifier: nil, permission_names: []) ⇒ Object

権限を解除する



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/store_agent/node/attachment/permission.rb', line 46

def unset!(identifier: nil, permission_names: [])
  identifiers = [identifier].flatten
  permission_names = [permission_names].flatten
  user_permission = find_permission(data["users"], identifiers)
  if user_permission
    user_permission.delete_if do |permission_name, _|
      permission_names.include?(permission_name)
    end
    sweep_permission(data["users"], identifiers)
    save
  end
end