Class: HasHelpers::OrganizationLink

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/has_helpers/organization_link.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#placeholderObject

Returns the value of attribute placeholder.



10
11
12
# File 'app/models/has_helpers/organization_link.rb', line 10

def placeholder
  @placeholder
end

Instance Method Details

#available_resourcesObject

instance methods ######



42
43
44
45
46
47
# File 'app/models/has_helpers/organization_link.rb', line 42

def available_resources
  HasHelpers::Resource.where(
    resource_type_id: "HasHelpers::ResourceType::::Base",
    application_id: ::HasHelpers::Application.current_application.id
  )
end

#has_access?(user) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'app/models/has_helpers/organization_link.rb', line 58

def has_access?(user)
  persisted? && (try("team").blank? || try("team").users.include?(user) || user.is_super_user?)
end

#placeholdersObject

overrided on agencies initializer to use webhook placeholders



50
51
52
# File 'app/models/has_helpers/organization_link.rb', line 50

def placeholders
  [{ name: "Id", value: "id" }]
end

#replaced_placeholder_url(base_resource) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'app/models/has_helpers/organization_link.rb', line 68

def replaced_placeholder_url(base_resource)
  return url if resource.blank?
  view = Mustache.new
  view.template = url.gsub(/{{(?<control_char>[\/#!\^]?)\s*(?<key>.+?)\s*}}/) { "{{#{ $~[:control_char] } #{ normalize_key($~[:key]) } }}" }
  view.template.tags.map do |name|
    value = base_resource.try(name.to_sym)
    view[name.to_sym] = value
  end
  view.render
end

#teamsObject



54
55
56
# File 'app/models/has_helpers/organization_link.rb', line 54

def teams
  []
end

#url_valueObject



62
63
64
65
66
# File 'app/models/has_helpers/organization_link.rb', line 62

def url_value
  if placeholder.present?
    self.url += self.url.end_with?("/") ? "{{#{placeholder}}}" : "/{{#{placeholder}}}"
  end
end