Class: Hippo::SystemSettings

Inherits:
Model
  • Object
show all
Defined in:
lib/hippo/system_settings.rb

Defined Under Namespace

Classes: ExtensionSettings

Constant Summary

Constants included from Concerns::ApiAttributeAccess

Concerns::ApiAttributeAccess::DEFAULT_BLACKLISTED

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

belongs_to_tenant, scoped_by_tenant?

Methods included from Concerns::ApiAttributeAccess

#_set_attribute_data_from_collection, #set_attribute_data, #setting_attribute_is_allowed?

Class Method Details

.configObject



42
43
44
# File 'lib/hippo/system_settings.rb', line 42

def config
    Tenant.current.system_settings || Tenant.current.create_system_settings
end

.for_ext(extension_id) ⇒ Object



50
51
52
# File 'lib/hippo/system_settings.rb', line 50

def for_ext(extension_id)
    config.for_ext(extension_id)
end

.get_handlerObject



60
61
62
63
64
65
66
67
68
69
# File 'lib/hippo/system_settings.rb', line 60

def get_handler
    Hippo::API::RequestWrapper.with_authenticated_user(
        role: 'administrator', with_transaction: false
    ) do |user, req|
        req.std_api_reply :get,
                      Hippo::SystemSettings.config.as_json(
                          include: ['logo', 'print_logo']
                      )
    end
end

.persist!(extension_id, update) ⇒ Object



54
55
56
57
58
# File 'lib/hippo/system_settings.rb', line 54

def persist!(extension_id, update)
    config.settings[extension_id] = update
    config.settings_will_change!
    config.save!
end

.public_jsonObject



46
47
48
# File 'lib/hippo/system_settings.rb', line 46

def public_json
    config.public_json
end

.update_handlerObject



71
72
73
74
75
76
77
78
79
80
81
# File 'lib/hippo/system_settings.rb', line 71

def update_handler
    Hippo::API::RequestWrapper.with_authenticated_user(
        role: 'administrator', with_transaction: false
    ) do |user, req|
        config = SystemSettings.config
        if req.data['settings'].is_a?(Hash)
            config.update_attributes!(settings: req.data['settings'])
        end
        req.std_api_reply :update, { settings: config.settings }, success: true
    end
end

Instance Method Details

#for_ext(extension_id) ⇒ Object



29
30
31
# File 'lib/hippo/system_settings.rb', line 29

def for_ext(extension_id)
    ExtensionSettings.new(extension_id, settings[extension_id.to_s])
end

#notify_updatedObject



25
26
27
# File 'lib/hippo/system_settings.rb', line 25

def notify_updated
    Hippo.redis_connection.publish('hippo-system-configuration-update', self.id)
end

#public_jsonObject



33
34
35
36
37
38
39
# File 'lib/hippo/system_settings.rb', line 33

def public_json
    {
        'logo' => Hippo::SystemSettings.config
                      .as_json(include: ['logo'])
                      .dig('logo', 'file_data')
    }
end