Home  >  Article  >  Development Tools  >  How to set access permissions and user roles in GitLab

How to set access permissions and user roles in GitLab

王林
王林Original
2023-10-20 11:57:352084browse

How to set access permissions and user roles in GitLab

How to set access permissions and user roles in GitLab

GitLab is a powerful open source code hosting platform that not only helps teams easily manage and collaborate on code development , and also provides flexible access permissions and user role settings. In this article, we'll explore how to set access permissions and user roles in GitLab, and provide specific code examples for reference.

1. Set user roles

In GitLab, user roles are mainly divided into four levels: Owner, Maintainer, Developer and Guest. Owner is a role with full administrative rights and can control project settings and user permissions; Maintainer can manage projects and members, and edit project code; Developer can view, edit, and submit project code; Guest can only view code and issues, etc.

To create a user role through the API, you can use the access token provided by GitLab to authorize:

curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/users/<user_id>/project_members"

{
  "id": "<id>",
  "user_id": <user_id>,
  "project_id": <project_id>,
  "access_level": <access_level>
}

Among them, <your_access_token></your_access_token> is the access token and needs to be replaced with Your own token; <user_id></user_id> is the user ID, representing the user whose role is to be set; <project_id></project_id> is the project ID, representing the project for which the role is to be set; <access_level></access_level> is the access level, which can be 40 (Owner), 30 (Maintainer), 20 (Developer) or One of 10(Guest).

2. Set access permissions

In GitLab, permissions are divided into system level and project level. System-level permissions control the functions and access scope of the entire GitLab, while project-level permissions control the access and operations of specific projects.

  1. System-level permissions

To set system-level permissions, you need to use an administrator account or a user with Admin permissions. To update system-level permissions through the API, you can use the following code example:

curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/application/settings" --data "signup_enabled=false&default_project_visibility=private"

Among them, signup_enabled indicates whether the user is allowed to register, and the default is true; default_project_visibility represents the default visibility of new projects, which can be one of private, internal or public.

  1. Project-level permissions

To set project-level permissions, you need to use the project's administrator account or a user with Maintainer permissions. To update project-level permissions through the API, you can use the following code example:

curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/projects/<project_id>/members/<user_id>" --data "access_level=30"

Where, <project_id></project_id> is the project ID, representing the project for which permissions are to be set; <user_id> </user_id> is the user ID, representing the user whose permissions are to be set; access_level is the access level, which can be 0 (Guest), 10 (Reporter), # One of ##20 (Developer), 30 (Maintainer) or 40 (Owner).

Summary

Through GitLab’s API, we can easily set access permissions and user roles, thereby improving the efficiency of project management and member collaboration. This article provides specific code examples, hoping to help readers better use GitLab to manage code projects.

The above is the detailed content of How to set access permissions and user roles in GitLab. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn