2021-12-20 12:32:51 +00:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
# Copyright (C) 2021 OKTET Labs Ltd. All rights reserved.
|
|
|
|
|
|
|
|
#
|
|
|
|
# Class DiaryEnv for Diary Management Application.
|
|
|
|
#
|
|
|
|
|
2024-01-10 06:54:07 +00:00
|
|
|
require 'singleton'
|
2021-12-20 12:32:51 +00:00
|
|
|
require_relative 'ldap_record'
|
|
|
|
require_relative 'diary_datamapper'
|
|
|
|
|
|
|
|
class DiaryEnv
|
|
|
|
include Singleton
|
|
|
|
|
|
|
|
DB_HOST = "localhost"
|
|
|
|
DB_USERNAME = "diary"
|
|
|
|
DB_PASSWORD = "diary_pass"
|
|
|
|
DB_DATABASE = "diary"
|
|
|
|
|
|
|
|
LDAP_HOST = 'ldap.example.com'
|
2022-01-17 11:50:26 +00:00
|
|
|
LDAP_PORT = 389
|
2021-12-20 12:32:51 +00:00
|
|
|
LDAP_ROOT = "ou=People,dc=example,dc=com"
|
2022-01-17 11:50:26 +00:00
|
|
|
LDAP_VER = 3
|
|
|
|
LDAP_BIND_DN = ""
|
|
|
|
LDAP_BIND_PW = ""
|
2021-12-20 12:32:51 +00:00
|
|
|
|
|
|
|
HOME_ORGANIZATION = "Example ORG"
|
|
|
|
HOME_OU = "Employees"
|
|
|
|
|
|
|
|
SMTP_HOST = 'mail.example.com'
|
|
|
|
SMTP_FROM = 'diary@example.com'
|
|
|
|
|
|
|
|
# Maximum age of diary entry (in days) to accept (approval mode only)
|
|
|
|
DIARY_MAX_AGE = 2
|
|
|
|
|
|
|
|
def initialize
|
|
|
|
@confirmation = Array.new
|
|
|
|
Person.setup(:host => LDAP_HOST,
|
2022-01-17 11:50:26 +00:00
|
|
|
:port => LDAP_PORT,
|
|
|
|
:root => LDAP_ROOT,
|
|
|
|
:ver => LDAP_VER,
|
|
|
|
:binddn => LDAP_BIND_DN,
|
|
|
|
:bindpw => LDAP_BIND_PW,
|
|
|
|
:key => "uid")
|
2021-12-20 12:32:51 +00:00
|
|
|
Person.set_local(HOME_ORGANIZATION, HOME_OU)
|
2022-02-02 14:21:36 +00:00
|
|
|
DataMapper.setup(:adapter => "Mysql2",
|
2021-12-20 12:32:51 +00:00
|
|
|
:database => DB_DATABASE,
|
|
|
|
:host => DB_HOST,
|
|
|
|
:username => DB_USERNAME,
|
|
|
|
:password => DB_PASSWORD)
|
2022-02-02 14:21:36 +00:00
|
|
|
cmd = "SELECT nick FROM director"
|
|
|
|
@director = []
|
|
|
|
DataMapper.database.query(cmd, as: :hash, symbolize_keys: false).each do |q|
|
2021-12-20 12:32:51 +00:00
|
|
|
raise "'Director' table is not filled" unless
|
2024-01-10 06:54:07 +00:00
|
|
|
q and name = q.fetch('nick')
|
2022-02-02 14:21:36 +00:00
|
|
|
@director.push(Person.new(name))
|
2021-12-20 12:32:51 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def user=(name)
|
|
|
|
@user = Person.find(name)
|
|
|
|
raise "Invalid user #{name}" unless @user
|
|
|
|
@policy = @user.employee? ? EmployeePolicy.new(@user) :
|
|
|
|
CustomerPolicy.new(@user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def confirmation=(value)
|
|
|
|
if value.is_a? Array
|
|
|
|
@confirmation = value
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_reader :director, :confirmation, :policy, :user
|
|
|
|
def self.director
|
|
|
|
instance.director
|
|
|
|
end
|
|
|
|
def self.confirmed?(token)
|
|
|
|
instance.confirmation.include?(token)
|
|
|
|
end
|
|
|
|
end
|