Initial commit

This commit is contained in:
Holger Sielaff
2025-06-26 08:41:56 +02:00
commit 69e2718826
16 changed files with 808 additions and 0 deletions

62
models/res_users.py Normal file
View File

@@ -0,0 +1,62 @@
try:
from odoo import models, fields, api, SUPERUSER_ID
from odoo.exceptions import UserError, AccessDenied
except ModuleNotFoundError:
from flectra import models, fields, api, SUPERUSER_ID
from flectra.exceptions import UserError, AccessDenied
import logging
import passlib
from ..lib import get_config
from ..lib.ldap import get_ldap_connection
_logger = logging.getLogger(__name__)
_posix_shell_selection = list(map(lambda x: (x, x), ['/bin/false', '/usr/bin/nologin', '/bin/sh', '/bin/bash', '/bin/zsh']))
def _posix_uid(self):
return self.login.split('@')[0].lower()
def _posix_home_dir(self):
return f"/tmp/{self.posix_uid}"
class ResUsers(models.Model):
_inherit = 'res.users'
ssh_public_key = fields.Text(string='SSH Public Key', required=False)
posix_uid = fields.Char(required=False, string='POSIX UID', compute='_compute_posix_uid')
posix_home_directory = fields.Char(string='Posix Home', required=False, compute='_compute_posix_home_dir', store=True)
posix_login_shell = fields.Selection(_posix_shell_selection, string='SSH Login Shell', required=False, default=_posix_shell_selection[0][0])
@api.model
def _compute_posix_uid(self):
for record in self:
if True or not record.posix_uid:
record.posix_uid = _posix_uid(record)
@api.depends('posix_uid')
def _compute_posix_home_dir(self):
for record in self:
if True or not record.posix_home_directory:
record.posix_home_directory = _posix_home_dir(record)
def write(self, vals):
result = super().write(vals)
for record in self:
if record.partner_id and not self.partner_id.is_company:
with get_ldap_connection(self.env) as conn:
record.partner_id._sync_contact(conn)
return result
@api.model
def _crypt_context(self):
algo = get_config(self.env, 'ldap_password_algo', "ldap_salted_sha512")
return passlib.context.CryptContext(
["pbkdf2_sha512", algo, "plaintext"],
deprecated=["pbkdf2_sha512", "plaintext"]
)