Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[18.0][MIG] dms: Migration to 18.0 #385

Open
wants to merge 168 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
168 commits
Select commit Hold shift + click to select a range
bb8c0a5
Version 1.0.0
May 4, 2017
7636f28
9.0 > 10.0
May 13, 2017
822c966
added markdown preview using showdown js library
sherpya Jul 24, 2017
6cc57c9
update
Oct 4, 2017
e1aa6ce
Add Ukrainian translation to mik_dms and muk_dms_access
Jun 25, 2018
c68ab06
Documents 2.0
keshrath Jul 10, 2018
9a0163b
publish muk_dms - 11.0
keshrath Jul 30, 2018
cdfdda2
v12
keshrath Sep 12, 2018
a684fe2
[IMP] : black, isort, prettier
etobella May 18, 2020
d88300f
[MIG] dms: from muk_dms to dms
etobella May 18, 2020
b2da326
[MIG] Dms tag
May 18, 2020
102de18
[MIG] dms: File
May 18, 2020
5f23f8b
[MIG][13.0] dms: Finish migration
etobella May 18, 2020
c75dede
[IMP] Minor mig fixes
May 19, 2020
87a5b4b
[MIG] dms: fix tests
etobella May 19, 2020
060c964
[IMP] Add security groups
May 19, 2020
39245e6
[ADD] dms: add funcionality of muk_dms_file
May 19, 2020
84813ee
[MIG] dms: File functionality
etobella May 19, 2020
810dfa3
[IMP] dms: Allow to drag and drop
etobella May 19, 2020
ae2af0d
[FIX] Various fixes
May 19, 2020
b034c19
[IMP] dms: Add mail
etobella May 19, 2020
2143a41
[FIX] dms: remove unused code and fixing: webpanel, migration, thumbn…
etobella May 19, 2020
38e2e4e
[IMP] dms: add migration script for muk_dms
etobella Jul 6, 2020
931920c
[13.0][MIG] dms: make migrations scripts compatible with older
LoisRForgeFlow Jul 9, 2020
f60081c
[FIX] dms: Download file with its proper name
etobella Aug 12, 2020
ec78f52
[FIX] dms: missing banner images & Load fields on the usual way
etobella Aug 14, 2020
9fa8985
[FIX] dms: Fix preview widget
etobella Aug 27, 2020
2c38c25
[FIX] dms: fix wrong test
Sep 28, 2020
e7003ea
[IMP] dms: Portal
victoralmau Oct 5, 2020
de9c656
[FIX] dms: /my/dms change to user and separate some urls in some func…
victoralmau Oct 19, 2020
c81f59e
[FIX] : Fix mimetype error in some files (.xlsx for example)
victoralmau Nov 3, 2020
ca6b1f5
[ADD] DMS integration with attachment
luismalta Aug 14, 2020
734e2e4
[IMP] dms: Attachment integration
victoralmau Nov 6, 2020
32ce603
Added translation using Weblate (Hebrew)
ygol Nov 10, 2020
e7e5f2b
Added translation using Weblate (Dutch)
bosd Dec 13, 2020
f54da7d
[FIX] dms: Remove request website user try
victoralmau Jan 18, 2021
3be07d7
[FIX] dms: Fix error when web_drop_target addon used to create new fi…
victoralmau Feb 1, 2021
ff84193
[FIX] dms: Adapt to 13.0
victoralmau Feb 2, 2021
94ef7b5
[IMP] dms: Integrate with mail_preview_base
etobella Sep 28, 2020
513f994
[FIX] dms: Kanban view
victoralmau Feb 8, 2021
9d9c7a3
[FIX] dms: Remove category creation in kanban tag view to prevent error
victoralmau Feb 11, 2021
93cf9ee
[FIX] dms: Use sudo() in attachment operacion (search dms directories…
victoralmau Feb 17, 2021
e4ed0f4
[REF+FIX] dms: Refactor code to create abstract.dms.mixin to contain …
victoralmau Feb 17, 2021
f8e5f7a
[FIX] dms: Prevent error when archive records and later process try t…
victoralmau Feb 18, 2021
853330d
[FIX] dms: Add domain operator
Shide Apr 22, 2021
a6c6cca
[12.0] [FIX] dms: Check `default_directory_id` context key
Shide Apr 26, 2021
a7db836
[FIX] dms: Prevent parent_id error in directories in some UI cases [F…
victoralmau Mar 30, 2021
e3135b0
[IMP] dms: Inherit permissions from related records
victoralmau Apr 5, 2021
f408a15
[IMP] dms: black, isort, prettier
victoralmau Apr 8, 2021
52193d8
[MIG] dms: Migration to 14.0
victoralmau Apr 27, 2021
6c415a0
[FIX] dms: Remove action column in portal (only used in files) and co…
victoralmau May 25, 2021
c8cb967
[FIX] dms: Fix error in portal with access_token
victoralmau May 26, 2021
6a14d89
[FIX] dms: Improve tests to prevent error if installed other addons a…
victoralmau May 31, 2021
071f592
[FIX] dms: Apply _apply_access_groups correctly (specially according …
victoralmau May 27, 2021
4b3b319
[FIX] improve some queries
Jun 10, 2021
1bc4399
[FIX] dms: cascade removal of related files/directories
Jun 8, 2021
cdf8c5d
[FIX] dms: do not fail for missing models on upgrade
Jun 1, 2021
5bf85f8
[FIX] dms: image thumbnails performance
May 28, 2021
e594efd
[FIX] dms: Fix multi-company rules + migration scripts
victoralmau Jul 8, 2021
723673c
[REF] dms: modify permissions computation
Jul 8, 2021
7d5d99b
[FIX] dms: respect computed security rules in all contexts
Jul 8, 2021
da1f75f
[FIX] dms: Prevent error (apply sudo()) when recursive directories re…
victoralmau Jul 8, 2021
ee92aa3
[FIX] dms: Fix tests for environments that add other groups to base u…
joao-p-marques Jul 9, 2021
d80d60e
[REF] dms: Adapt to 14.0
victoralmau Jul 9, 2021
bdf896a
[IMP] dms: automatic image thumbnails
Jul 28, 2021
a47b989
Explicit Access Group instructions
majenkotech Sep 13, 2021
b0f0749
[FIX] dms: Add python-magic library to readme
victoralmau Sep 3, 2021
9e5587d
[FIX] dms: Drag & Drop
Tardo Oct 20, 2021
ddebb7a
[IMP] dms: Set the drop target to the kanban view, excluding the sear…
etobella Oct 29, 2021
7cc6906
[FIX] dms: Pending attribute mimetype
etobella Oct 29, 2021
60684c9
[FIX] dms: Show the total of files (of all subdirectories) in the for…
victoralmau Nov 5, 2021
4a75382
[FIX] dms: Define the file extension correctly (even if there is no e…
victoralmau Nov 5, 2021
db4b734
[FIX] dms: Prevent CacheMis error from count_total_files in some NewI…
victoralmau Jan 24, 2022
a7e886e
[FIX] dms: Change size field type from integer to float to prevent 21…
victoralmau Jan 24, 2022
b8aadfe
[FIX] dms: Replace the content field with size in the form view of th…
victoralmau Feb 7, 2022
95749a6
[FIX] dms: The internal user group is added as an inheritance to the …
victoralmau Mar 1, 2022
f5b780e
[MIG] dms: Migration to 15.0
JasminSForgeFlow Feb 11, 2022
d24da93
[MIG] dms: Finish migration
etobella May 17, 2022
9bbd4fa
[FIX] dms: Add Archived ribbon in form views and remove active field …
victoralmau May 17, 2022
21b9299
[FIX] dms: do_warn method no longer available in v15
gdrius Jul 15, 2022
3e00342
Translated using Weblate (German)
marylla Jul 18, 2022
e73623e
[IMP+FIX] dms: Searchpanel changes:
victoralmau Sep 1, 2022
2c22999
[IMP] dms: Use _prepare_home_portal_values() function.
victoralmau Sep 6, 2022
8e60457
[IMP] dms: Refactor tests.
victoralmau Sep 5, 2022
85459fd
[IMP] dms: Changes in file tree view: - Set multi_edit - Add tag_ids …
victoralmau Jul 13, 2021
6908574
[FIX] dms: Compute mimetype in dms_file correctly to allow preview
victoralmau Jul 13, 2021
c9f49d9
[IMP] dms: automatic image thumbnails
victoralmau Nov 8, 2021
cd40310
[IMP] dms: Show in directory kaban view only root directories (Change…
victoralmau Jul 14, 2021
da08535
[FIX] dms: Show directory short name in searchpanel.
victoralmau Sep 7, 2022
06b41b8
[FIX] dms: Searchpanel from directories
victoralmau Sep 8, 2022
bd2b604
[FIX] dms: Add operator parameter required (forgotten at https://gith…
victoralmau Sep 12, 2022
1c75fde
[FIX] dms: skip attachment creation when storage type is different fr…
marcelsavegnago Sep 16, 2022
cef6c85
[FIX] dms: Remove migrations folder from 14.0
victoralmau Nov 22, 2022
d8e23ba
[FIX] dms: Remove parent_id defined if you do not have access to it (…
victoralmau Feb 10, 2023
4e8448b
[FIX] dms: Limit breadcrumb from portal to directories you have acces…
victoralmau Feb 9, 2023
1dac798
[FIX] dms: Get the "parent" directories (those of the top level to wh…
victoralmau Feb 7, 2023
275bdb2
[FIX] dms: Use the correct domain with inherit_access_from_parent_rec…
victoralmau Jan 25, 2023
aca1c09
[IMP] dms: Add action_dms_file_wizard_selector action.
victoralmau Feb 10, 2023
37bb914
[FIX] dms: dms.file thumbnail generation checks for supported mimetypes
aleuffre Apr 3, 2023
05444b3
[IMP] dms: more restrictive access rights for access groups
aleuffre Aug 31, 2022
07566b9
[IMP] dms: Increase the speed of tests
victoralmau Jul 18, 2023
c38c755
[FIX] dms: Explicitly exclude the pdf type in the image_1920 field of…
victoralmau Jun 15, 2023
1ae12ba
Translated using Weblate (Spanish)
Ivorra78 Jul 20, 2023
53ceda2
[MIG] dms: Migration from 15.0 to 16.0
Sep 18, 2023
a8396e7
Added translation using Weblate (Portuguese (Brazil))
adrianojprado Nov 3, 2023
fd93d09
Translated using Weblate (Portuguese (Brazil))
adrianojprado Nov 4, 2023
0273a3a
Translated using Weblate (Portuguese (Brazil))
adrianojprado Nov 5, 2023
4dca247
[16.0][IMP]dms: adjust contributors and sponsor
Nov 6, 2023
a25e78b
Translated using Weblate (Portuguese (Brazil))
adrianojprado Nov 7, 2023
fb4d227
Translated using Weblate (Portuguese (Brazil))
adrianojprado Nov 8, 2023
66206c8
Translated using Weblate (Italian)
mymage Nov 12, 2023
2a3ffbc
Translated using Weblate (Spanish)
Ivorra78 Nov 15, 2023
d8b969d
[FIX] dms: remove padding only for directory kanban records
lijoantony Nov 16, 2023
179a2ea
Translated using Weblate (Italian)
mymage Nov 17, 2023
016b3c5
Translated using Weblate (Italian)
mymage Dec 1, 2023
9e7a3ec
[IMP] dms: Show all directories in searchpanel from files
victoralmau Dec 13, 2023
0951918
[FIX] dms: Correctly filter records when selecting a searchpanel item…
victoralmau Jan 5, 2024
44f91fe
Translated using Weblate (Portuguese (Brazil))
adrianojprado Jan 5, 2024
5319f00
[IMP]dms: check for same storage
PicchiSeba Sep 1, 2023
66bcc50
Translated using Weblate (Spanish)
Ivorra78 Jan 9, 2024
edb42ac
Translated using Weblate (Italian)
mymage Jan 11, 2024
555c005
[FIX] dms: Improve search by model
etobella Oct 25, 2023
3201e04
[FIX] dms: Avoid error when set files from directory form view
adasatorres Feb 7, 2024
f65f210
[FIX] dms: Set the correct directory_id value according to the domain…
victoralmau Feb 9, 2024
e40592f
[FIX] dms: Fix smartbuttons from files and directories
victoralmau Feb 7, 2024
8336e70
[IMP] dms: Improve tests
victoralmau Feb 16, 2024
69234c4
Translated using Weblate (Italian)
mymage Feb 16, 2024
3dc0f4d
[IMP] dms: Add ACLs to dms.storage for users with the basic permission
victoralmau Jan 18, 2024
3b46e53
[IMP] dms: Add human_size field to directories and files
victoralmau Jan 29, 2024
5c8abeb
[FIX] dms: Improve the unlink method in base to avoid errors
victoralmau Jan 25, 2024
c5541e6
Added translation using Weblate (Portuguese)
peterromao Feb 29, 2024
3d409ed
[FIX] dms: Change display_name from directory kanban buttons (Directo…
victoralmau Mar 26, 2024
86c1802
[IMP] dms: Add default_order to file and directory tree to prevent co…
victoralmau Mar 27, 2024
eb00bbb
[IMP] dms: Add number items (directories and files) to directory kanb…
victoralmau Apr 15, 2024
fb654cf
[IMP] dms: Add move (change directory) action from files
victoralmau Mar 5, 2024
c8740d9
[16.0][FIX]dms: error when clicked the file smart button on directory…
adasatorres May 14, 2024
2257e14
[IMP] dms: Remove string=Size from the human_size field to avoid the …
tva-subteno-it May 22, 2024
73d7d6a
[FIX] dms: Remove incorrect character in maximum upload size error me…
tva-subteno-it May 30, 2024
77c0336
[IMP] dms: Capture correct error to be shown at notification
tva-subteno-it Jun 6, 2024
731987a
[FIX] dms: Allow share (directories and files) without 'Contact creat…
victoralmau Jun 18, 2024
b057735
[MIG] DMS: Migration to 17.0
tva-subteno-it May 30, 2024
2ea4390
[UPD] Update dms.pot
Jul 26, 2024
6012554
[BOT] post-merge updates
OCA-git-bot Jul 26, 2024
52a1425
Update translation files
weblate Jul 26, 2024
549e68c
Translated using Weblate (Italian)
mymage Jul 29, 2024
46e310d
Translated using Weblate (French)
tva-subteno-it Aug 9, 2024
5ada47c
Translated using Weblate (French)
tva-subteno-it Aug 14, 2024
33e258c
Translated using Weblate (French)
tva-subteno-it Aug 14, 2024
650916a
[IMP+FIX] dms: Improve performance + Avoid non-existing record access…
victoralmau Jul 22, 2024
d5426ca
[FIX] dms: Remove log warning in dms.file
victoralmau Aug 20, 2024
91ae61b
[BOT] post-merge updates
OCA-git-bot Aug 20, 2024
2a20b4c
Added translation using Weblate (Persian)
mostafabarmshory Aug 28, 2024
213e7c0
Translated using Weblate (Persian)
mostafabarmshory Aug 28, 2024
f907c09
Translated using Weblate (Persian)
mostafabarmshory Aug 28, 2024
b435304
[I18N] dms: Fix fa.po
pedrobaeza Sep 6, 2024
946b89a
Translated using Weblate (Italian)
mymage Sep 18, 2024
00310f6
[IMP] dms: Change portal_my_home_dms to use its own div
victoralmau Oct 10, 2024
e33804a
[IMP] dms: Add the mk_file_kanban_view class to the custom kanban view
victoralmau Oct 9, 2024
d1329ac
[IMP] dms: Show Upload button in the file kanban view only if it is a…
victoralmau Oct 11, 2024
3488507
[BOT] post-merge updates
OCA-git-bot Oct 11, 2024
255aad4
[BOT] post-merge updates
OCA-git-bot Oct 29, 2024
0bfefce
[IMP] dms: Add clipboard limitation to roadmap
victoralmau Dec 11, 2024
e8e75ff
[BOT] post-merge updates
OCA-git-bot Dec 11, 2024
d53f2a7
[MIG] dms: pre-commit auto fixes
kobros-tech Jan 14, 2025
6edad3f
[18.0][MIG] dms: Migration to 18.0
kobros-tech Jan 27, 2025
23deaee
[18.0][FIX] dms: bradcrump fix
kobros-tech Jan 27, 2025
7810264
[18.0][FIX] dms: access rules fix
kobros-tech Jan 28, 2025
2e9c024
[FIX] dms: error when creating a new document
JordiBForgeFlow Feb 3, 2025
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
14 changes: 9 additions & 5 deletions dms/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Document Management System
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fdms-lightgray.png?logo=github
:target: https://github.com/OCA/dms/tree/17.0/dms
:target: https://github.com/OCA/dms/tree/18.0/dms
:alt: OCA/dms
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/dms-17-0/dms-17-0-dms
:target: https://translation.odoo-community.org/projects/dms-18-0/dms-18-0-dms
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/dms&target_branch=17.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/dms&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -180,7 +180,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/dms/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/dms/issues/new?body=module:%20dms%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/dms/issues/new?body=module:%20dms%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -216,6 +216,10 @@ Contributors

- Timothée Vannier <[email protected]>

- `Kencove <https://www.kencove.com>`__:

- Mohamed Alkobrosli <[email protected]>

Other credits
-------------

Expand All @@ -240,6 +244,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/dms <https://github.com/OCA/dms/tree/17.0/dms>`_ project on GitHub.
This module is part of the `OCA/dms <https://github.com/OCA/dms/tree/18.0/dms>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion dms/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"name": "Document Management System",
"summary": """Document Management System for Odoo""",
"version": "17.0.1.2.1",
"version": "18.0.1.0.0",
"category": "Document Management",
"license": "LGPL-3",
"website": "https://github.com/OCA/dms",
Expand Down
2 changes: 1 addition & 1 deletion dms/controllers/portal.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
if access_token:
item = item.sudo()
if not item.check_access_token(access_token):
return False

Check warning on line 30 in dms/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

dms/controllers/portal.py#L30

Added line #L30 was not covered by tests
else:
if not item.permission_read:
return False

Check warning on line 33 in dms/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

dms/controllers/portal.py#L33

Added line #L33 was not covered by tests
return item

def _prepare_home_portal_values(self, counters):
Expand Down Expand Up @@ -69,9 +69,9 @@
]
# search
if search and search_in == "name":
domain += OR([[], [("name", "ilike", search)]])

Check warning on line 72 in dms/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

dms/controllers/portal.py#L72

Added line #L72 was not covered by tests
# content according to pager and archive selected
items = request.env["dms.directory"].search(domain, order=sort_order)
items = request.env["dms.directory"].sudo().search(domain, order=sort_order)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why sudo?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@etobella
there is no defined rule for portal users to access dms.directory

If you can add rules for portal users, I welcome

request.session["my_dms_folder_history"] = items.ids
# values
values.update(
Expand Down Expand Up @@ -131,7 +131,7 @@
access_token, dms_directory_id, search, search_in, sort_order
)
if not res:
return request.redirect("/" if access_token else "/my")

Check warning on line 134 in dms/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

dms/controllers/portal.py#L134

Added line #L134 was not covered by tests

dms_directory_sudo = res
# dms_files_count
Expand Down Expand Up @@ -173,14 +173,14 @@
:rtype: odoo.model.dms_file
"""
if not dms_directory_id:
return request.env["dms.file"]

Check warning on line 176 in dms/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

dms/controllers/portal.py#L176

Added line #L176 was not covered by tests
file_domain = [
("is_hidden", "=", False),
("directory_id", "=", dms_directory_id),
]
# search
if search and search_in == "name":
file_domain.append(("name", "ilike", search))

Check warning on line 183 in dms/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

dms/controllers/portal.py#L183

Added line #L183 was not covered by tests

# items
file_model = request.env["dms.file"]
Expand Down Expand Up @@ -209,7 +209,7 @@
domain = [("is_hidden", "=", False), ("parent_id", "=", dms_directory_id)]
# search
if search and search_in:
domain.append(("name", "ilike", search))

Check warning on line 212 in dms/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

dms/controllers/portal.py#L212

Added line #L212 was not covered by tests

# content according to pager and archive selected
directory_model = request.env["dms.directory"]
Expand Down Expand Up @@ -274,8 +274,8 @@
res = self._dms_check_access("dms.file", dms_file_id, access_token)
if not res:
if access_token:
return request.redirect("/")
return request.redirect("/my")

Check warning on line 278 in dms/controllers/portal.py

View check run for this annotation

Codecov / codecov/patch

dms/controllers/portal.py#L277-L278

Added lines #L277 - L278 were not covered by tests

if res.attachment_id and request.env.user.has_group("base.group_portal"):
res = res.sudo()
Expand Down
8 changes: 4 additions & 4 deletions dms/models/access_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class DmsAccessGroups(models.Model):
_parent_name = "parent_group_id"

name = fields.Char(string="Group Name", required=True, translate=True)
parent_path = fields.Char(index="btree", unaccent=False)
parent_path = fields.Char(index="btree")

# Permissions written directly on this group
perm_create = fields.Boolean(string="Create Access")
Expand Down Expand Up @@ -122,9 +122,9 @@ def _compute_inclusive_permissions(self):
for one in self:
one.update(
{
"perm_inclusive_%s" % perm: (
one["perm_%s" % perm]
or one.parent_group_id["perm_inclusive_%s" % perm]
f"perm_inclusive_{perm}": (
one[f"perm_{perm}"]
or one.parent_group_id[f"perm_inclusive_{perm}"]
)
for perm in ("create", "unlink", "write")
}
Expand Down
15 changes: 7 additions & 8 deletions dms/models/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
from odoo.osv.expression import AND, OR
from odoo.tools import consteq, human_size

from odoo.addons.http_routing.models.ir_http import slugify

from ..tools.file import check_name, unique_name

_logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -46,7 +44,7 @@ class DmsDirectory(models.Model):
_parent_name = "parent_id"
_directory_field = _parent_name

parent_path = fields.Char(index="btree", unaccent=False)
parent_path = fields.Char(index="btree")
is_root_directory = fields.Boolean(
default=False,
help="""Indicates if the directory is a root directory.
Expand Down Expand Up @@ -216,7 +214,7 @@ def _get_domain_by_access_groups(self, operation):
"""Special rules for directories."""
self_filter = [
("storage_id_inherit_access_from_parent_record", "=", False),
("id", "inselect", self._get_access_groups_query(operation)),
("id", "in", self._get_access_groups_query(operation)),
]
# Upstream only filters by parent directory
result = super()._get_domain_by_access_groups(operation)
Expand All @@ -237,7 +235,7 @@ def _get_domain_by_access_groups(self, operation):
def _compute_access_url(self):
res = super()._compute_access_url()
for item in self:
item.access_url = "/my/dms/directory/%s" % (item.id)
item.access_url = f"/my/dms/directory/{item.id}"
return res

def check_access_token(self, access_token=False):
Expand Down Expand Up @@ -278,7 +276,7 @@ def _get_parent_categories(self, access_token):
and consteq(current_directory.access_token, access_token)
)
or not access_token
and current_directory.check_access_rights("read")
and current_directory.check_access("read")
):
return directories
current_directory = current_directory.parent_id
Expand Down Expand Up @@ -529,7 +527,7 @@ def _onchange_model_id(self):
# Constrains
@api.constrains("parent_id")
def _check_directory_recursion(self):
if not self._check_recursion():
if self._has_cycle():
raise ValidationError(_("Error! You cannot create recursive directories."))
return True

Expand Down Expand Up @@ -627,7 +625,8 @@ def message_new(self, msg_dict, custom_values=None):
parent_directory._process_message(msg_dict)
return parent_directory
names = parent_directory.child_directory_ids.mapped("name")
subject = slugify(msg_dict.get("subject", _("Alias-Mail-Extraction")))
slug = self.env["ir.http"]._slug
subject = slug(msg_dict.get("subject", _("Alias-Mail-Extraction")))
defaults = dict(
{"name": unique_name(subject, names, escape_suffix=True)}, **custom_values
)
Expand Down
4 changes: 2 additions & 2 deletions dms/models/dms_category.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class DMSCategory(models.Model):
comodel_name="dms.category",
inverse_name="parent_id",
)
parent_path = fields.Char(index="btree", unaccent=False)
parent_path = fields.Char(index="btree")
tag_ids = fields.One2many(
string="Tags", comodel_name="dms.tag", inverse_name="category_id"
)
Expand Down Expand Up @@ -99,6 +99,6 @@ def _compute_count_files(self):

@api.constrains("parent_id")
def _check_category_recursion(self):
if not self._check_recursion():
if self._has_cycle():
raise ValidationError(_("Error! You cannot create recursive categories."))
return True
10 changes: 5 additions & 5 deletions dms/models/dms_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,14 +150,14 @@ def _compute_image_1920(self):
):
one.image_1920 = one.content

def check_access_rule(self, operation):
self.mapped("directory_id").check_access_rule(operation)
return super().check_access_rule(operation)
def check_access(self, operation):
self.mapped("directory_id").check_access(operation)
return super().check_access(operation)

def _compute_access_url(self):
res = super()._compute_access_url()
for item in self:
item.access_url = "/my/dms/file/%s/download" % (item.id)
item.access_url = f"/my/dms/file/{item.id}/download"
return res

def check_access_token(self, access_token=False):
Expand Down Expand Up @@ -240,7 +240,7 @@ def _get_forbidden_extensions(self):
return [extension.strip() for extension in extensions.split(",")]

def _get_icon_placeholder_name(self):
return self.extension and "file_%s.svg" % self.extension or ""
return self.extension and f"file_{self.extension}.svg" or ""

# Actions
def action_migrate(self, should_logging=True):
Expand Down
86 changes: 58 additions & 28 deletions dms/models/dms_security_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
OR,
TRUE_DOMAIN,
)
from odoo.tools import SQL

_logger = getLogger(__name__)

Expand Down Expand Up @@ -86,10 +87,10 @@ def _compute_permissions(self):
)
return

creatable = self._filter_access_rules("create")
readable = self._filter_access_rules("read")
unlinkable = self._filter_access_rules("unlink")
writeable = self._filter_access_rules("write")
creatable = self._filtered_access("create")
readable = self._filtered_access("read")
unlinkable = self._filtered_access("unlink")
writeable = self._filtered_access("write")
for one in self:
one.update(
{
Expand Down Expand Up @@ -135,15 +136,15 @@ def _get_domain_by_inheritance(self, operation):
)
continue
# Check model access only once per batch
if not model.check_access_rights(operation, raise_exception=False):
if not model.check_access(operation):
continue
domains.append([("res_model", "=", model._name), ("res_id", "=", False)])
# Check record access in batch too
res_ids = [i for i in group["res_id"] if i] # Hack to remove None res_id
# Apply exists to skip records that do not exist. (e.g. a res.partner
# deleted by database).
model_records = model.browse(res_ids).exists()
related_ok = model_records._filter_access_rules_python(operation)
related_ok = model_records._filtered_access(operation)
if not related_ok:
continue
domains.append(
Expand All @@ -161,33 +162,53 @@ def _get_access_groups_query(self, operation):
"unlink": "AND dag.perm_inclusive_unlink",
"write": "AND dag.perm_inclusive_write",
}[operation]
select = f"""
SELECT
dir_group_rel.aid
FROM
dms_directory_complete_groups_rel AS dir_group_rel
INNER JOIN dms_access_group AS dag
ON dir_group_rel.gid = dag.id
INNER JOIN dms_access_group_users_rel AS users
ON users.gid = dag.id
WHERE
users.uid = %s {operation_check}
"""
return select, (self.env.uid,)
if operation == "read":
sql = SQL(
"""(
SELECT
dir_group_rel.aid
FROM
dms_directory_complete_groups_rel AS dir_group_rel
INNER JOIN dms_access_group AS dag
ON dir_group_rel.gid = dag.id
INNER JOIN dms_access_group_users_rel AS users
ON users.gid = dag.id
WHERE
users.uid = %s
)""",
self.env.uid,
)
else:
sql = SQL(
"""(
SELECT
dir_group_rel.aid
FROM
dms_directory_complete_groups_rel AS dir_group_rel
INNER JOIN dms_access_group AS dag
ON dir_group_rel.gid = dag.id
INNER JOIN dms_access_group_users_rel AS users
ON users.gid = dag.id
WHERE
users.uid = %s %s
)""",
self.env.uid,
operation_check,
)
return sql

@api.model
def _get_domain_by_access_groups(self, operation):
"""Get domain for records accessible applying DMS access groups."""
result = [
(
"%s.storage_id_inherit_access_from_parent_record"
% self._directory_field,
f"{self._directory_field}.storage_id_inherit_access_from_parent_record",
"=",
False,
),
(
self._directory_field,
"inselect",
"in",
self._get_access_groups_query(operation),
),
]
Expand Down Expand Up @@ -236,16 +257,26 @@ def _search_permission_unlink(self, operator, value):
def _search_permission_write(self, operator, value):
return self._get_permission_domain(operator, value, "write")

def _filter_access_rules_python(self, operation):
def _filtered_access_no_recursion(self, operation: str):
"""This method is just the same as _filtered_access
but it can not be called withoud super due to
recursion error.

"""
if self and not self.env.su and (result := self._check_access(operation)):
return self - result[0]
return self

def _filtered_access(self, operation):
# Only kept to not break inheritance; see next comment
result = super()._filter_access_rules_python(operation)
result = super()._filtered_access(operation)
# HACK Always fall back to applying rules by SQL.
# Upstream `_filter_access_rules_python()` doesn't use computed fields
# Upstream `_filtered_access()` doesn't use computed fields
# search methods. Thus, it will take the `[('permission_{operation}',
# '=', user.id)]` rule literally. Obviously that will always fail
# because `self[f"permission_{operation}"]` will always be a `bool`,
# while `user.id` will always be an `int`.
result |= self._filter_access_rules(operation)
result |= self._filtered_access_no_recursion(operation)
return result

@api.model_create_multi
Expand All @@ -258,6 +289,5 @@ def create(self, vals_list):
res.flush_recordset()
# Go back to the original sudo state and check we really had creation permission
res = res.sudo(self.env.su)
res.check_access_rights("create")
res.check_access_rule("create")
res.check_access("create")
return res
4 changes: 2 additions & 2 deletions dms/models/ir_binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
class IrBinary(models.AbstractModel):
_inherit = "ir.binary"

def _find_record_check_access(self, record, access_token):
def _find_record_check_access(self, record, access_token, field):
if record._name in ("dms.file", "dms.directory"):
if record.sudo().check_access_token(access_token):
# sudo because the user might not usually have access to the record but
# now the token is valid.
# Used to display the icon in the portal.
return record.sudo()

return super()._find_record_check_access(record, access_token)
return super()._find_record_check_access(record, access_token, field)
2 changes: 1 addition & 1 deletion dms/models/mixins_thumbnail.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def _get_icon_url(self):
"""Obtain URL to record icon."""
local_path = self._get_icon_disk_path()
icon_name = os.path.basename(local_path)
return "/dms/static/icons/%s" % icon_name
return f"/dms/static/icons/{icon_name}"

@api.depends("image_128")
def _compute_icon_url(self):
Expand Down
6 changes: 3 additions & 3 deletions dms/models/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class Storage(models.Model):
name = fields.Char(required=True)
save_type = fields.Selection(
selection=[
("database", _("Database")),
("file", _("Filestore")),
("attachment", _("Attachment")),
("database", "Database"),
("file", "Filestore"),
("attachment", "Attachment"),
],
default="database",
required=True,
Expand Down
2 changes: 2 additions & 0 deletions dms/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@
- Khanh Bui \<<[email protected]>\>
- [Subteno](https://www.subteno.com):
- Timothée Vannier <<[email protected]>>
- [Kencove](https://www.kencove.com):
- Mohamed Alkobrosli <<[email protected]>>
Loading
Loading