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

feat: Disable Sharing globally #20318

Merged
merged 11 commits into from
Mar 28, 2023
Merged

feat: Disable Sharing globally #20318

merged 11 commits into from
Mar 28, 2023

Conversation

marination
Copy link
Collaborator

@marination marination commented Mar 13, 2023

Docs: https://docs.erpnext.com/docs/v14/user/manual/en/setting-up/settings/system-settings/edit-wiki?wiki_page_patch=57c20f0965

Issue:

  • The Document Share feature is a way to essentially go around the set permissions and give access to a user
  • In many cases this is not desirable as the permissions are thought through well and a confidential document must not be viewed by anyone other than the permitted users.
  • A case was encountered where a user shared a document with another user who was not supposed to see the document. This could happen accidentally or with sinister motives.
  • Users can "accidentally" assign a document to a non-permitted user and share access again in the process.

Enable or Disable document sharing system wide

  1. Checkbox in System Settings which is unchecked by default to maintain old behaviour
    Screenshot 2023-03-14 at 8 11 34 PM

  2. If enabled, system wide, no user will have share access to any document

  3. The share button will be read only, no action (no share access). Although users can see who the doc is shared with (consistent with old behaviour)
    2023-03-14 20 26 04

  4. On invoking the share API without ignore_share_permissions (form the browser), a perm error is thrown
    2023-03-14 20 33 34

  5. If any share API is invoked with ignore_share_permissions it will go through (consistent with old behaviour). [Creating a user, doc must be shared with the user themselves]

    2023-03-15 12 04 25

  6. assign_to is handled as a special case, where assigning a doc to a user will block the assignment if the user does not have access already. The assignee is expected to have access to the document otherwise assignments can be misused
    Screenshot 2023-03-28 at 5 57 31 PM

- Checkbox in System Settings
- If disabled, avoid share UI render
- Share APIs return None (non-obstructing) if share APIs are invoked
@github-actions github-actions bot added the add-test-cases Add test case to validate fix or enhancement label Mar 13, 2023
@codecov
Copy link

codecov bot commented Mar 13, 2023

Codecov Report

Merging #20318 (6e2c146) into develop (6bda014) will increase coverage by 0.06%.
The diff coverage is 66.66%.

❗ Current head 6e2c146 differs from pull request most recent head 1ea9d60. Consider uploading reports for the commit 1ea9d60 to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #20318      +/-   ##
===========================================
+ Coverage    63.80%   63.86%   +0.06%     
===========================================
  Files          758      758              
  Lines        68672    68654      -18     
  Branches      6194     6194              
===========================================
+ Hits         43814    43849      +35     
+ Misses       21320    21263      -57     
- Partials      3538     3542       +4     
Flag Coverage Δ
server 68.75% <100.00%> (-0.04%) ⬇️
server-ui 31.75% <16.66%> (+0.06%) ⬆️
ui-tests 51.81% <0.00%> (+0.21%) ⬆️

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

- Treat feature like a perm toggler. Essentially noone is allowed to explicity share anything
- Implicit sharing via `ignore_share_permissions` is allowed. Devs can decide where sharing should happen under the hood
- UI is made read only and not hidden. Users must see who doc is already shared with
- Make sure perm APIs used by share feature return false if sharing is disabled
- Rename checkbox to `Disable Document Sharing`
@marination marination changed the title feat: [WIP] Disable Sharing globally feat: Disable Sharing globally Mar 15, 2023
@marination marination removed the add-test-cases Add test case to validate fix or enhancement label Mar 15, 2023
@marination marination marked this pull request as ready for review March 15, 2023 10:59
@marination marination requested review from a team and shariquerik and removed request for a team March 15, 2023 10:59
Copy link
Member

@ankush ankush left a comment

Choose a reason for hiding this comment

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

just one minor UX fix. Rest looks fine.

frappe/desk/form/assign_to.py Outdated Show resolved Hide resolved
ankush
ankush previously approved these changes Mar 28, 2023
@ankush ankush merged commit 90f8f94 into develop Mar 28, 2023
@ankush ankush deleted the disable-sharing-globally branch March 28, 2023 12:43
mergify bot pushed a commit that referenced this pull request Mar 28, 2023
* feat: Disable Sharing globally

- Checkbox in System Settings
- If disabled, avoid share UI render
- Share APIs return None (non-obstructing) if share APIs are invoked

* feat: Settings checkbox must toggle share permission globally

- Treat feature like a perm toggler. Essentially noone is allowed to explicity share anything
- Implicit sharing via `ignore_share_permissions` is allowed. Devs can decide where sharing should happen under the hood
- UI is made read only and not hidden. Users must see who doc is already shared with
- Make sure perm APIs used by share feature return false if sharing is disabled
- Rename checkbox to `Disable Document Sharing`

* test: (server side) Impact of disabling sharing on APIs

- Also, fix missed system setting rename in `assign_to`

* fix: Inform assigner if assignee lacks perms and sharing is disabled

- misc: readable conditions

* fix: throw instead of msgprint

* fix: Typo and appropriate message for `throw`

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
(cherry picked from commit 90f8f94)

# Conflicts:
#	frappe/core/doctype/docshare/test_docshare.py
#	frappe/core/doctype/system_settings/system_settings.json
#	frappe/permissions.py
#	frappe/public/js/frappe/model/model.js
mergify bot pushed a commit that referenced this pull request Mar 28, 2023
* feat: Disable Sharing globally

- Checkbox in System Settings
- If disabled, avoid share UI render
- Share APIs return None (non-obstructing) if share APIs are invoked

* feat: Settings checkbox must toggle share permission globally

- Treat feature like a perm toggler. Essentially noone is allowed to explicity share anything
- Implicit sharing via `ignore_share_permissions` is allowed. Devs can decide where sharing should happen under the hood
- UI is made read only and not hidden. Users must see who doc is already shared with
- Make sure perm APIs used by share feature return false if sharing is disabled
- Rename checkbox to `Disable Document Sharing`

* test: (server side) Impact of disabling sharing on APIs

- Also, fix missed system setting rename in `assign_to`

* fix: Inform assigner if assignee lacks perms and sharing is disabled

- misc: readable conditions

* fix: throw instead of msgprint

* fix: Typo and appropriate message for `throw`

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
(cherry picked from commit 90f8f94)
@barredterra
Copy link
Collaborator

@ankush don't you want this in v13 at all or can we do a manual backport?

@ankush
Copy link
Member

ankush commented Mar 29, 2023

Way too many conflicts, better to port manually and confirm if it works.

ankush added a commit that referenced this pull request Mar 29, 2023
* feat: Disable Sharing globally (#20318)

* feat: Disable Sharing globally

- Checkbox in System Settings
- If disabled, avoid share UI render
- Share APIs return None (non-obstructing) if share APIs are invoked

* feat: Settings checkbox must toggle share permission globally

- Treat feature like a perm toggler. Essentially noone is allowed to explicity share anything
- Implicit sharing via `ignore_share_permissions` is allowed. Devs can decide where sharing should happen under the hood
- UI is made read only and not hidden. Users must see who doc is already shared with
- Make sure perm APIs used by share feature return false if sharing is disabled
- Rename checkbox to `Disable Document Sharing`

* test: (server side) Impact of disabling sharing on APIs

- Also, fix missed system setting rename in `assign_to`

* fix: Inform assigner if assignee lacks perms and sharing is disabled

- misc: readable conditions

* fix: throw instead of msgprint

* fix: Typo and appropriate message for `throw`

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
(cherry picked from commit 90f8f94)

* test: fix test case to modified behaviour

We throw instead of showing warning now

---------

Co-authored-by: Marica <maricadsouza221197@gmail.com>
Co-authored-by: Ankush Menat <ankush@frappe.io>
ankush added a commit that referenced this pull request Mar 29, 2023
* feat: Disable Sharing globally (#20318)

* feat: Disable Sharing globally

- Checkbox in System Settings
- If disabled, avoid share UI render
- Share APIs return None (non-obstructing) if share APIs are invoked

* feat: Settings checkbox must toggle share permission globally

- Treat feature like a perm toggler. Essentially noone is allowed to explicity share anything
- Implicit sharing via `ignore_share_permissions` is allowed. Devs can decide where sharing should happen under the hood
- UI is made read only and not hidden. Users must see who doc is already shared with
- Make sure perm APIs used by share feature return false if sharing is disabled
- Rename checkbox to `Disable Document Sharing`

* test: (server side) Impact of disabling sharing on APIs

- Also, fix missed system setting rename in `assign_to`

* fix: Inform assigner if assignee lacks perms and sharing is disabled

- misc: readable conditions

* fix: throw instead of msgprint

* fix: Typo and appropriate message for `throw`

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>

* test: fix test case to modified behaviour

We throw instead of showing warning now

* style: format

[skip ci]

---------

Co-authored-by: Ankush Menat <ankush@frappe.io>
frappe-pr-bot pushed a commit that referenced this pull request Apr 4, 2023
# [14.31.0](v14.30.0...v14.31.0) (2023-04-04)

### Bug Fixes

* allow `reset_otp_secret` only if Two Factor Auth is enabled ([#20506](#20506)) ([#20561](#20561)) ([ca486c4](ca486c4))
* allowed only POST and PUT methods in `rename_doc` ([#20504](#20504)) ([#20565](#20565)) ([fd1f6fe](fd1f6fe))
* bulk update using doc method, check perms ([#20522](#20522)) ([2237968](2237968))
* cannot restore cancelled document if workflow is active ([547efe3](547efe3))
* Check if reference_name is set ([2e9068b](2e9068b))
* content_type can be `None` during file upload ([#20572](#20572)) ([#20574](#20574)) ([ebc6059](ebc6059))
* date field shouldn't be formatted for TZ ([#20486](#20486)) ([#20490](#20490)) ([07b7b46](07b7b46))
* don't hide tab with dashboard if there is a visible section/control ([084e8af](084e8af))
* Drop message_id index before migrating email queue ([#20376](#20376)) ([#20578](#20578)) ([394c232](394c232))
* email linking and message_id indexing ([#20356](#20356)) ([#20579](#20579)) ([5ae94ef](5ae94ef))
* escape HTML instead of sanitizing ([2269d6e](2269d6e))
* fix address query for postgres ([f01566a](f01566a)), closes [/github.com//pull/20537#ref-pullrequest-1645575433](https://github.com//github.com/frappe/frappe/pull/20537/issues/ref-pullrequest-1645575433)
* get workflow_state_fieldname instead of setting workflow_state to none ([bac4e9b](bac4e9b))
* Handle JsBarcode exceptions ([#20532](#20532)) ([b1c3d8b](b1c3d8b))
* heatmap not reset on dashboard refresh ([3c0659b](3c0659b))
* hide chart and heatmap on dashboard reset ([cec7a73](cec7a73))
* Incorrect use of the Walrus operator ([a70a5ca](a70a5ca))
* nestedset rename ([#20498](#20498)) ([#20499](#20499)) ([b831392](b831392))
* removed unnecessary usage of `[@frappe](https://github.com/frappe).whitelist` ([#20503](#20503)) ([#20563](#20563)) ([0af8315](0af8315))
* rewrite query for postgres ([#20557](#20557)) ([#20559](#20559)) ([d754be5](d754be5))
* sending mails to unintended recipients as cc ([1c47643](1c47643))
* **UI:** align link cards & charts on workspace ([82cfd33](82cfd33))
* unsubscribe from list_update before resubbing ([#20450](#20450)) ([#20581](#20581)) ([7866605](7866605))
* use chart type passed to `render_graph` on form dashboards ([015f7db](015f7db))

### Features

* Disable Sharing globally (backport [#20318](#20318)) ([#20492](#20492)) ([67a537c](67a537c))
* list-view click and drag on check box to select multiple rows (backport [#20457](#20457)) ([#20568](#20568)) ([f757a37](f757a37))
* make workflow state translatable ([#20412](#20412)) ([8675789](8675789))
* **util:** `get_table_name`: wrap in backticks ([#20553](#20553)) ([#20556](#20556)) ([5c56dff](5c56dff))

### Performance Improvements

* Faster address query with explicit joins (backport [#20537](#20537)) ([#20540](#20540)) ([2ef7ef5](2ef7ef5))
* unsubscribe from list_update events ([#20423](#20423)) ([#20580](#20580)) ([8a63144](8a63144))
frappe-pr-bot pushed a commit that referenced this pull request Apr 4, 2023
# [13.52.0](v13.51.3...v13.52.0) (2023-04-04)

### Bug Fixes

* better error logging while sending email ([#20570](#20570)) ([8ae4d55](8ae4d55))
* cannot restore cancelled document if workflow is active ([6206dc0](6206dc0))
* escape HTML instead of sanitizing ([68ad9cf](68ad9cf))
* fix address query for postgres ([616dd8b](616dd8b)), closes [/github.com//pull/20537#ref-pullrequest-1645575433](https://github.com//github.com/frappe/frappe/pull/20537/issues/ref-pullrequest-1645575433)
* get workflow_state_fieldname instead of setting workflow_state to none ([3249aa2](3249aa2))
* removed unnecessary usage of `[@frappe](https://github.com/frappe).whitelist` ([#20503](#20503)) ([#20562](#20562)) ([08398cb](08398cb))
* rewrite query for postgres ([#20557](#20557)) ([#20558](#20558)) ([e400c5f](e400c5f))

### Features

* Disable Sharing globally ([#20318](#20318)) [backport] ([#20500](#20500)) ([758873c](758873c))
* make workflow state translatable ([#20412](#20412)) ([#20501](#20501)) ([1545fbd](1545fbd))

### Performance Improvements

* Faster address query with explicit joins (backport [#20537](#20537)) ([#20539](#20539)) ([955a723](955a723))
@iMoshi
Copy link
Contributor

iMoshi commented Apr 4, 2023

Awesome!

Would it not make more sense to actually hide the Share div from the sidebar when this feature is enabled though? :)

@marination
Copy link
Collaborator Author

@iMoshi in the case where sharing is disabled after a document is already shared with some users, we would probably still want to see who all can view this document. Seemed consistent with the behaviour when a user has no share access.
That's what we were kinda going for - switch off everyones share permission.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants