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: new editor user permission profile #4435

Merged
merged 10 commits into from
Jun 14, 2024

Conversation

chazzhou
Copy link
Contributor

Description

This change introduces a new user permission profile called "editor" in the Dify workspace. The editor role can add and edit apps within the workspace, but does not have permission to manage certain workspace-level settings such as adding API keys, changing workspace models and tools, or enabling/disabling the API endpoint. However, editors can turn on/off and manage the published site for apps they have access to.

In addition, this change disallows normal users and editors to view logs, enhancing the security of the workspace.

The implementation also streamlines some places where permission checking was not using helper functions, and adds disabled states on the frontend for actions that editors do not have permission to perform.

Fixes # (issue)

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Improvement, including but not limited to code refactoring, performance optimization, and UI/UX improvement

How Has This Been Tested?

  • Verified editors can create and edit apps
  • Confirmed editors cannot access workspace settings they don't have permission for
  • Tested that editors can manage published app websites
  • Checked disabled states appear correctly on frontend for editor role

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
  • optional I have made corresponding changes to the documentation
  • optional I have added tests that prove my fix is effective or that my feature works
  • optional New and existing unit tests pass locally with my changes

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. 💪 enhancement New feature or request labels May 15, 2024
@takatost takatost requested a review from VincePotato May 16, 2024 03:43
@VincePotato
Copy link

Could you provide more detailed information, such as why this new role is needed? Also, please list all the permissions related to the editor and explain them. @chazzhou

@chazzhou
Copy link
Contributor Author

Hi @VincePotato, thanks for the question. I want to include the new "editor" role to provide more granular access control within Dify workspaces. It allows owners and admins to grant certain users the ability to create and manage apps, without giving them full control over workspace-level settings.

The main rationale is to enable sharing workspaces with users who need to design agents and workflows, but shouldn't be able to modify critical settings like the underlying language models, installed tools, API keys, etc. This is helpful for collaborating with less technical users who are trusted to build apps, but not necessarily to manage the entire workspace configuration.

Here's an overview of the permission hierarchy:

  • Owner: Full control over the workspace and all settings
  • Admin: Same app permissions as owner, plus ability to manage workspace settings
  • Editor: Can create, edit, and manage apps, but cannot modify workspace settings
  • Normal (Viewer): Can only use apps, cannot create or edit them

The key permission changes for the editor role are:

Endpoint Method Description Previous Permission New Permission
/apps/<uuid:app_id>/site-enable POST Enable/disable app website None Editor
/apps/<uuid:app_id>/api-enable POST Enable/disable app API None Admin
/apps/<uuid:app_id>/completion-conversations GET View completion conversations None Admin
/apps/<uuid:app_id>/completion-conversations/<uuid:conversation_id> GET/DELETE View/delete completion conversation None Admin
/apps/<uuid:app_id>/chat-conversations GET View chat conversations None Admin
/apps/<uuid:app_id>/chat-conversations/<uuid:conversation_id> GET/DELETE View/delete chat conversation None Admin
/workspaces/current/default-model POST Change default workspace models None Admin
/apps POST Create app Admin Editor
/apps/<uuid:app_id> DELETE Delete app Admin Editor
/apps/<uuid:app_id>/copy POST Copy app Admin Editor
/apps/import POST Import app Admin Editor
/datasets/<uuid:dataset_id>/documents POST Create dataset document Admin Editor
/datasets/init POST Initialize dataset Admin Editor
/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/processing/<string:action> PATCH Process dataset document Admin Editor
/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/metadata PUT Edit document metadata Admin Editor
/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/status/<string:action> PATCH Change document status Admin Editor
/datasets/<uuid:dataset_id>/segments/<uuid:segment_id>/<string:action> PATCH Modify dataset segment Admin Editor
/datasets/<uuid:dataset_id>/documents/<uuid:document_id>/segments/<uuid:segment_id> PATCH Update document segment Admin Editor
/datasets POST Create dataset Admin Editor
/datasets/<uuid:dataset_id> PATCH/DELETE Modify/delete dataset Admin Editor
/tags POST Create tag Admin Editor
/tags/<uuid:tag_id> PATCH/DELETE Update/delete tag Admin Editor
/tag-bindings/create POST Create tag binding Admin Editor
/tag-bindings/remove POST Delete tag binding Admin Editor

In summary, the editor role provides a balance between enabling app creation/management and restricting access to workspace configuration. It's a useful addition for more flexible and secure collaboration within Dify.

Let me know if you have any other questions or suggestions! I'm happy to provide more details.

VincePotato
VincePotato previously approved these changes May 20, 2024
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label May 20, 2024
@crazywoola
Copy link
Member

@takatost Have we tested this pr?

@chazzhou
Copy link
Contributor Author

Hi everyone,

I've updated the PR to maintain compatibility with the recent front-end changes. The main change is that buttons for editing tools will now be disabled for editors and viewers.

Additionally, I've made an adjustment to the permissions for the following endpoint:

Endpoint Method Description Previous Permission New Permission
/apps/uuid:app_id/site POST Edit app site settings Admin Editor

This change grants editors the ability to modify app site settings, which was previously restricted to admin users only.

Please review the changes and let me know if you have any questions or concerns.

Thanks!

@chazzhou chazzhou requested a review from VincePotato May 28, 2024 02:12
@nsvrana
Copy link

nsvrana commented May 30, 2024

Just a note - this fixes a huge challenge we've had with Dify internally. Would love to see this released in a near future version. Ideally, in the future, Dify could go as far as to get to user/editor permissions on a per agent/bot/workflow basis.

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels May 30, 2024
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:XL This PR changes 500-999 lines, ignoring generated files. labels May 30, 2024
@chazzhou
Copy link
Contributor Author

@nsvrana I'm glad it helped!

Recent changes resolved the merge conflict with main.

@crazywoola
Copy link
Member

Hello there can you resolve the conflicting files.

Copy link
Member

@crazywoola crazywoola left a comment

Choose a reason for hiding this comment

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

Cool :0

@crazywoola
Copy link
Member

Hello, can you add my wechat crazyphage?

@crazywoola crazywoola merged commit 8bcc5a3 into langgenius:main Jun 14, 2024
7 checks passed
@chazzhou chazzhou deleted the new-editor-role branch June 14, 2024 14:20
@takatost takatost mentioned this pull request Jun 14, 2024
dengpeng pushed a commit to dengpeng/dify that referenced this pull request Jun 16, 2024
@dq7532183
Copy link

I am also doing this because a team can modify assistants created by others, so I want to create a role and can only view and edit the assistants I have created. The tags table already has the createduby field, which needs to be added to the apps

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Must be admin or iwner

Scorpion1221 added a commit to yybht155/dify that referenced this pull request Jun 26, 2024
* commit '12c815c597b121357151c798aae6580304416937': (97 commits)
  fix: ExtractSetting optional value missing None as default val (langgenius#5238)
  version to 0.6.11 (langgenius#5224)
  Feat/firecrawl data source (langgenius#5232)
  update tooltip (langgenius#5235)
  fix: note editor italic (langgenius#5230)
  fix: z-index (langgenius#5229)
  Update README.md (langgenius#5228)
  fix: allow the name and icon of the web app to be set independently of that of the bot itself (langgenius#5225)
  fix: initialize site with customized icon and icon_background (langgenius#5227)
  feat: support firecrawl frontend code (langgenius#5226)
  feat(Tools): Add Feishu multi-dimensional table operation function (langgenius#5213)
  chore: development script for syncing Poetry lockfile (langgenius#5170)
  fix: workspace member's last_active should be last_active_time, but not last_login_time (langgenius#4906)
  fix: number variable cause type error in openai moderation (langgenius#5222)
  feat: new editor user permission profile (langgenius#4435)
  Fix: http_request delete method not working (langgenius#4975)
  Update README, deploy dify with YAML file on Kubernetes (langgenius#5131)
  feat: support tencent vector db (langgenius#3568)
  fix: add repo check for build-push.yml (langgenius#5141)
  feat: Add Optional API Key, Proxy Server, and Bypass Cache Parameters to Jina Tools (langgenius#5197)
  ...

# Conflicts:
#	api/core/helper/code_executor/code_executor.py
#	api/requirements.txt
HuberyHuV1 pushed a commit to HuberyHuV1/dify that referenced this pull request Jul 22, 2024
@liuzhenghua
Copy link
Contributor

@takatost @crazywoola Can you help confirm with PM about my PR? #6950

In my opinion, creating new applications requires an architecture review, and deleting applications is a dangerous operation. These actions should not be performed by the editor role.

I'm also looking forward to Dify adding the ability for admins to configure specific apps that the editor role can definitely edit.

@nsvrana
Copy link

nsvrana commented Aug 5, 2024

Please don’t change this role in the way you just described - for my use case either we need separate app by app permissions or editor needs to be able to create and delete.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💪 enhancement New feature or request lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants