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

Feature: consumption templates #4196

Merged
merged 37 commits into from
Sep 22, 2023
Merged

Feature: consumption templates #4196

merged 37 commits into from
Sep 22, 2023

Conversation

shamoon
Copy link
Member

@shamoon shamoon commented Sep 17, 2023

Proposed change

This PR adds "consumption templates" which allow users more control over consumed docs. Functionally, this allows things like automatically sharing new documents, different consume folders and other useful things.

In general, this could definitely be expanded upon in the future, I think.

TLDR:

  • Set document source (folder, API, mail) and filter docs by file name, path or mail rule
  • Allows assigning: title (with some placeholders), tags, correspondent, doc type, owner & permissions
Screenshot 2023-09-21 at 10 47 31 PM

Thoughts:

  • At the moment templates will be [potentially] processed sequentially but subsequent templates won't override the prior. e.g. if you have two templates that set the correspondent the first one applied 'wins'.
  • Title placeholders have to come from the template so currently {correspondent}, {document_type}, {owner_username} and some date variables for added.
  • I thought about migrating mail rules to this (you add a template to a mail rule) but in the end I left them as-is, it seemed nice to be able to have two places to control things. Mail rule settings (e.g. assign correspondent) will take precedence.
  • I allowed filtering by mail rule, that way you can apply a template to docs consumed via a rule (to do things like set permissions, etc).
  • I also modified mail rules to allow a) not setting title, b) not setting owner

TODO:

  • docs
  • backend testing

Fixes #2177
Fixes #4163
Fixes #3443
& others

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other (please explain):

Checklist:

  • I have read & agree with the contributing guidelines.
  • If applicable, I have included testing coverage for new code in this PR, for backend and / or front-end changes.
  • If applicable, I have tested my code for new features & regressions on both mobile & desktop devices, using the latest version of major browsers.
  • If applicable, I have checked that all tests pass, see documentation.
  • I have run all pre-commit hooks, see documentation.
  • I have made corresponding changes to the documentation as needed.
  • I have checked my modifications for any breaking changes.

@paperless-ngx-secretary paperless-ngx-secretary bot added backend frontend non-trivial Requires approval by several team members labels Sep 17, 2023
@shamoon shamoon added this to the v2.0.0 milestone Sep 17, 2023
@github-actions github-actions bot added the enhancement New feature label Sep 17, 2023
@shamoon shamoon added notable Flag PRs to highlight in releases and removed enhancement New feature labels Sep 17, 2023
@shamoon shamoon force-pushed the feature-consumption-templates branch from 152d3f7 to aaae9d6 Compare September 17, 2023 08:22
@codecov
Copy link

codecov bot commented Sep 17, 2023

Codecov Report

Merging #4196 (19188bb) into dev (86d223f) will increase coverage by 0.16%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##              dev    #4196      +/-   ##
==========================================
+ Coverage   95.45%   95.61%   +0.16%     
==========================================
  Files         344      352       +8     
  Lines       13244    13571     +327     
  Branches     1084     1088       +4     
==========================================
+ Hits        12642    12976     +334     
+ Misses        597      590       -7     
  Partials        5        5              
Flag Coverage Δ
backend 94.47% <100.00%> (+0.25%) ⬆️
frontend 96.97% <100.00%> (+0.06%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
.../app/components/app-frame/app-frame.component.html 100.00% <ø> (ø)
...e-edit-dialog/mail-rule-edit-dialog.component.html 100.00% <ø> (ø)
...ule-edit-dialog/mail-rule-edit-dialog.component.ts 100.00% <ø> (ø)
...g/user-edit-dialog/user-edit-dialog.component.html 100.00% <ø> (ø)
...p/components/common/input/tags/tags.component.html 100.00% <ø> (ø)
src/paperless_mail/serialisers.py 97.95% <ø> (ø)
src-ui/src/app/app-routing.module.ts 100.00% <100.00%> (ø)
src-ui/src/app/app.module.ts 100.00% <100.00%> (ø)
...og/consumption-template-edit-dialog.component.html 100.00% <100.00%> (ø)
...alog/consumption-template-edit-dialog.component.ts 100.00% <100.00%> (ø)
... and 19 more

... and 1 file with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Pipfile Show resolved Hide resolved
@stumpylog
Copy link
Member

This looks very powerful for the permissions and just other stuff. I'll have to look at it more when I can. It seems like a good answer to many requests overall. Nice work so far.

@shamoon
Copy link
Member Author

shamoon commented Sep 17, 2023

This looks very powerful for the permissions and just other stuff. I'll have to look at it more when I can. It seems like a good answer to many requests overall. Nice work so far.

Thanks mate, yea whatever (/whenever) you can contribute would be awesome, you know I tend to fumble through backend stuff

@shamoon shamoon force-pushed the feature-consumption-templates branch 2 times, most recently from 997e89e to 1b4cd92 Compare September 18, 2023 04:25
@shamoon shamoon marked this pull request as ready for review September 18, 2023 04:37
@shamoon shamoon requested review from a team as code owners September 18, 2023 04:37
@shamoon shamoon enabled auto-merge (squash) September 18, 2023 04:37
@shamoon shamoon added the enhancement New feature label Sep 18, 2023
@shamoon shamoon force-pushed the feature-consumption-templates branch 6 times, most recently from 9e197e1 to b04e86e Compare September 20, 2023 07:38
@ignoreigor
Copy link

Hi again,

This looks very powerful for the permissions and just other stuff. I'll have to look at it more when I can. It seems like a good answer to many requests overall. Nice work so far.

i agree this looks powerful and fairly useful for multiple purposes. Maybe this can end up in far future to a complete rewrite of matching document-types, correspondents and tags, then working with a list of rules consisting of conditions and actions, as I earlier suggested.

But so far, good work!

@shamoon shamoon force-pushed the feature-consumption-templates branch from b04e86e to a15a142 Compare September 20, 2023 21:04
@stumpylog
Copy link
Member

The header of the templates page is hard to see on a dark theme:
image

Tags dropdown doesn't have a "No items found" thing.

After selecting consume and API upload sources, the resulting template always has mail fetch instead. The PUT values look good, the GET returns Mail Source.

I can help track some of this down again as I have time.

@shamoon
Copy link
Member Author

shamoon commented Sep 21, 2023

Thanks for the fixes / cleanup (yea all that int() stuff felt messy). Let me know what else you notice.

The column heading thing was from that last package bump (bootstrap release notes are horrible) but fixed, as for the tags dropdown, you mean like this (screenshot below) or something else?

Screenshot 2023-09-20 at 6 58 32 PM

@shamoon shamoon force-pushed the feature-consumption-templates branch from 1ddf96d to aef4d46 Compare September 21, 2023 22:31
@shamoon shamoon force-pushed the feature-consumption-templates branch from aef4d46 to c896660 Compare September 21, 2023 22:51
@shamoon
Copy link
Member Author

shamoon commented Sep 22, 2023

Turns out you were right stumpy, the default perms on the frontend would apply to these, which got me thinking about this some more. Actually a lot more...

I debated this a bit, but I think the best thing is to remove perms from templates (not assigning perms to docs, just no owner / perms on templates themselves). Happy to come up with another solution if you think wise.

The biggest issue, I think, is that since templates are potentially applied to sources that have no user in context, so listing the templates would always return all of them (as opposed to only ones they have access to) and so you'd end up with users potentially having their docs affected by templates they cant see. Then theres the fact that sharing is kind of nonsensical (so I considered removing perms but leaving owner, but still previous issue), etc. etc.

Overall, seemed too messy and counter-intuitive and I didn't see an obvious simple solution. Again, welcome to thoughts but this way theres one master list and people can either access it, or not.

@stumpylog
Copy link
Member

Yes, i see the problem. A user would be surprised if they had a document with unexpected tags or even the owner changed from themselves. This seems like a good compromise

@shamoon shamoon merged commit 9712ac1 into dev Sep 22, 2023
29 checks passed
Copy link
Member

@stumpylog stumpylog left a comment

Choose a reason for hiding this comment

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

I think I'm good with this as it. Lets squash and merge it

@shamoon shamoon deleted the feature-consumption-templates branch September 22, 2023 23:53
@juergen852
Copy link

I think, this feature is more something for the "Admins" and not for normal users.
I would also feel good with your approach if templates are limited to admins.

@shamoon
Copy link
Member Author

shamoon commented Oct 3, 2023

You can set permissions for this just like anything else in the app

shamoon added a commit that referenced this pull request Oct 13, 2023
* Initial implementation of consumption templates

* Frontend implementation of consumption templates

Testing

* Support consumption template source

* order templates, automatically add permissions

* Support title assignment in consumption templates

* Refactoring, filters to and, show sources on list

Show sources on template list, update some translation strings

Make filters and

minor testing

* Update strings

* Only update django-multiselectfield

* Basic docs, document some methods

* Improve testing coverage, template multi-assignment merges
Copy link
Contributor

github-actions bot commented Nov 3, 2023

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new discussion or issue for related concerns.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backend enhancement New feature frontend non-trivial Requires approval by several team members notable Flag PRs to highlight in releases
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants