Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dms/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class OnboardingController(http.Controller):
@http.route("/config/dms.forbidden_extensions", type="json", auth="user")
@http.route("/config/dms.forbidden_extensions", type="jsonrpc", auth="user")
def forbidden_extensions(self, **_kwargs):
params = request.env["ir.config_parameter"].sudo()
return {
Expand Down
2 changes: 1 addition & 1 deletion dms/demo/res_users.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
-->
<odoo noupdate="1">
<record id="base.user_demo" model="res.users">
<field eval="[(4, ref('dms.group_dms_user'))]" name="groups_id" />
<field eval="[(4, ref('dms.group_dms_user'))]" name="group_ids" />
</record>
</odoo>
33 changes: 17 additions & 16 deletions dms/models/access_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright 2024 Timothée Vannier - Subteno (https://www.subteno.com).
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import _, api, fields, models
from odoo import Command, api, fields, models
from odoo.exceptions import ValidationError


Expand Down Expand Up @@ -47,7 +47,7 @@ class DmsAccessGroups(models.Model):
string="Directories",
column1="gid",
column2="aid",
auto_join=True,
bypass_search_access=True,
readonly=True,
)
complete_directory_ids = fields.Many2many(
Expand All @@ -56,7 +56,7 @@ class DmsAccessGroups(models.Model):
column1="gid",
column2="aid",
string="Complete directories",
auto_join=True,
bypass_search_access=True,
readonly=True,
)
count_users = fields.Integer(compute="_compute_users", store=True)
Expand Down Expand Up @@ -94,7 +94,7 @@ class DmsAccessGroups(models.Model):
column2="uid",
string="Group Users",
compute="_compute_users",
auto_join=True,
bypass_search_access=True,
store=True,
recursive=True,
)
Expand All @@ -104,9 +104,10 @@ def _compute_count_directories(self):
for record in self:
record.count_directories = len(record.directory_ids)

_sql_constraints = [
("name_uniq", "unique (name)", "The name of the group must be unique!")
]
_name_uniq = models.Constraint(
"unique (name)",
"The name of the group must be unique!",
)

@api.depends(
"parent_group_id.perm_inclusive_create",
Expand Down Expand Up @@ -136,20 +137,20 @@ def default_get(self, fields_list):
if res.get("explicit_user_ids"):
res["explicit_user_ids"] = res["explicit_user_ids"] + [self.env.uid]
else:
res["explicit_user_ids"] = [(6, 0, [self.env.uid])]
res["explicit_user_ids"] = [Command.set([self.env.uid])]
return res

@api.depends(
"parent_group_id",
"parent_group_id.users",
"group_ids",
"group_ids.users",
"group_ids.user_ids",
"explicit_user_ids",
)
def _compute_users(self):
for record in self:
users = (
record.group_ids.users
record.group_ids.user_ids
| record.explicit_user_ids
| record.parent_group_id.users
)
Expand All @@ -158,7 +159,7 @@ def _compute_users(self):
def copy_data(self, default=None):
vals_list = super().copy_data(default)
for group, vals in zip(self, vals_list, strict=False):
vals["name"] = _("%s (copy)") % group.name
vals["name"] = self.env._("%s (copy)", group.name)
return vals_list

@api.constrains("parent_path")
Expand All @@ -169,9 +170,9 @@ def _check_parent_recursiveness(self):
for one in self.filtered("parent_group_id"):
if str(one.id) in one.parent_path.split("/"):
raise ValidationError(
_("Parent group '%(parent)s' is child of '%(current)s'.")
% {
"parent": one.parent_group_id.display_name,
"current": one.display_name,
}
self.env._(
"Parent group '%(parent)s' is child of '%(current)s'.",
parent=one.parent_group_id.display_name,
current=one.display_name,
)
)
60 changes: 38 additions & 22 deletions dms/models/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from collections import defaultdict
from typing import Literal # noqa # pylint: disable=unused-import

from odoo import _, api, fields, models, tools
from odoo import api, fields, models, tools
from odoo.exceptions import UserError, ValidationError
from odoo.osv.expression import AND, OR
from odoo.fields import Domain
from odoo.tools import consteq, human_size

from ..tools.file import check_name, unique_name
Expand Down Expand Up @@ -60,7 +60,7 @@ class DmsDirectory(models.Model):
comodel_name="dms.storage",
string="Storage",
ondelete="restrict",
auto_join=True,
bypass_search_access=True,
store=True,
)
parent_id = fields.Many2one(
Expand Down Expand Up @@ -116,7 +116,7 @@ def _default_parent_id(self):
comodel_name="dms.directory",
inverse_name="parent_id",
string="Subdirectories",
auto_join=False,
bypass_search_access=False,
copy=True,
)

Expand Down Expand Up @@ -153,7 +153,7 @@ def _default_parent_id(self):
comodel_name="dms.file",
inverse_name="directory_id",
string="Files",
auto_join=False,
bypass_search_access=False,
copy=True,
)

Expand Down Expand Up @@ -221,7 +221,7 @@ def _get_domain_by_access_groups(self, operation):
if operation == "create":
# When creating, I need create access in parent directory, or
# self-create permission if it's a root directory
result = OR(
result = Domain.OR(
[
[("is_root_directory", "=", False)] + result,
[("is_root_directory", "=", True)] + self_filter,
Expand Down Expand Up @@ -379,7 +379,11 @@ def _search_panel_directory(self, **kwargs):
# Search
@api.model
def _search_starred(self, operator, operand):
if operator == "=" and operand:
# The 19.0 Domain optimizer normalises ('starred', '=', True) to
# ('starred', 'in', {True}); accept both shapes.
if isinstance(operand, (set, list, tuple)):
operand = True in operand
if operator in ("=", "in") and operand:
return [("user_star_ids", "in", [self.env.uid])]
return [("user_star_ids", "not in", [self.env.uid])]

Expand Down Expand Up @@ -412,14 +416,16 @@ def _compute_count_directories(self):
for record in self:
directories = len(record.child_directory_ids)
record.count_directories = directories
record.count_directories_title = _("%s Subdirectories") % directories
record.count_directories_title = self.env._(
"%s Subdirectories", directories
)

@api.depends("file_ids")
def _compute_count_files(self):
for record in self:
files = len(record.file_ids)
record.count_files = files
record.count_files_title = _("%s Files") % files
record.count_files_title = self.env._("%s Files", files)

@api.depends("child_directory_ids", "file_ids")
def _compute_count_elements(self):
Expand Down Expand Up @@ -528,7 +534,9 @@ def _onchange_model_id(self):
@api.constrains("parent_id")
def _check_directory_recursion(self):
if self._has_cycle():
raise ValidationError(_("Error! You cannot create recursive directories."))
raise ValidationError(
self.env._("Error! You cannot create recursive directories.")
)
return True

@api.constrains("storage_id", "model_id")
Expand All @@ -538,34 +546,40 @@ def _check_storage_id_attachment_model_id(self):
):
if not record.model_id:
raise ValidationError(
_("A directory has to have model in attachment storage.")
self.env._("A directory has to have model in attachment storage.")
)
if not record.is_root_directory and not record.res_id:
raise ValidationError(
_("This directory needs to be associated to a record.")
self.env._("This directory needs to be associated to a record.")
)

@api.constrains("is_root_directory", "storage_id")
def _check_directory_storage(self):
for record in self:
if record.is_root_directory and not record.storage_id:
raise ValidationError(_("A root directory has to have a storage."))
raise ValidationError(
self.env._("A root directory has to have a storage.")
)

@api.constrains("is_root_directory", "parent_id")
def _check_directory_parent(self):
for record in self:
if record.is_root_directory and record.parent_id:
raise ValidationError(
_("A directory can't be a root and have a parent directory.")
self.env._(
"A directory can't be a root and have a parent directory."
)
)
if not record.is_root_directory and not record.parent_id:
raise ValidationError(_("A directory has to have a parent directory."))
raise ValidationError(
self.env._("A directory has to have a parent directory.")
)

@api.constrains("name")
def _check_name(self):
for record in self:
if self.env.context.get("check_name", True) and not check_name(record.name):
raise ValidationError(_("The directory name is invalid."))
raise ValidationError(self.env._("The directory name is invalid."))
if record.is_root_directory:
children = record.sudo().storage_id.root_directory_ids
else:
Expand All @@ -576,7 +590,7 @@ def _check_name(self):
and child != record
):
raise ValidationError(
_("A directory with the same name already exists.")
self.env._("A directory with the same name already exists.")
)

# Create, Update, Delete
Expand Down Expand Up @@ -626,7 +640,7 @@ def message_new(self, msg_dict, custom_values=None):
return parent_directory
names = parent_directory.child_directory_ids.mapped("name")
slug = self.env["ir.http"]._slug
subject = slug(msg_dict.get("subject", _("Alias-Mail-Extraction")))
subject = slug(msg_dict.get("subject", self.env._("Alias-Mail-Extraction")))
defaults = dict(
{"name": unique_name(subject, names, escape_suffix=True)}, **custom_values
)
Expand Down Expand Up @@ -678,13 +692,15 @@ def write(self, vals):
if new_parent_id:
if old_storage_id != self.browse(new_parent_id).storage_id.id:
raise UserError(
_(
self.env._(
"It is not possible to change to a parent "
"with other storage."
)
)
elif old_storage_id != new_storage_id:
raise UserError(_("It is not possible to change the storage."))
raise UserError(
self.env._("It is not possible to change the storage.")
)
# Groups part
if any(key in vals for key in ["group_ids", "inherit_group_ids"]):
res = super().write(vals)
Expand Down Expand Up @@ -743,7 +759,7 @@ def action_dms_directories_all_directory(self):
action = self.env["ir.actions.act_window"]._for_xml_id(
"dms.action_dms_directory"
)
domain = AND(
domain = Domain.AND(
[
literal_eval(action["domain"].strip()),
[("parent_id", "child_of", self.id)],
Expand All @@ -761,7 +777,7 @@ def action_dms_directories_all_directory(self):
def action_dms_files_all_directory(self):
self.ensure_one()
action = self.env["ir.actions.act_window"]._for_xml_id("dms.action_dms_file")
domain = AND(
domain = Domain.AND(
[
literal_eval(action["domain"].strip()),
[("directory_id", "child_of", self.id)],
Expand Down
13 changes: 8 additions & 5 deletions dms/models/dms_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import logging

from odoo import _, api, fields, models
from odoo import api, fields, models
from odoo.exceptions import ValidationError

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -63,9 +63,10 @@ class DMSCategory(models.Model):
count_directories = fields.Integer(compute="_compute_count_directories")
count_files = fields.Integer(compute="_compute_count_files")

_sql_constraints = [
("name_uniq", "unique (name)", "Category name already exists!"),
]
_name_uniq = models.Constraint(
"unique (name)",
"Category name already exists!",
)

@api.depends("name", "parent_id.complete_name")
def _compute_complete_name(self):
Expand Down Expand Up @@ -100,5 +101,7 @@ def _compute_count_files(self):
@api.constrains("parent_id")
def _check_category_recursion(self):
if self._has_cycle():
raise ValidationError(_("Error! You cannot create recursive categories."))
raise ValidationError(
self.env._("Error! You cannot create recursive categories.")
)
return True
Loading
Loading