summaryrefslogtreecommitdiffstats
path: root/modules/convert
diff options
context:
space:
mode:
authorFlorin Hillebrand <flozzone@gmail.com>2022-04-29 14:24:38 +0200
committerGitHub <noreply@github.com>2022-04-29 14:24:38 +0200
commitad6d08d155c67d6d3833d2961ed0fd5a2ba1ff88 (patch)
tree4b951ae25ad9118d31a5077f7f3d24b19efcfc5c /modules/convert
parente5c6c001c5f5299a63b4ccbd7aaeea486d6b5c53 (diff)
downloadgitea-ad6d08d155c67d6d3833d2961ed0fd5a2ba1ff88.tar.gz
gitea-ad6d08d155c67d6d3833d2961ed0fd5a2ba1ff88.zip
Add API to query collaborators permission for a repository (#18761)
Targeting #14936, #15332 Adds a collaborator permissions API endpoint according to GitHub API: https://docs.github.com/en/rest/collaborators/collaborators#get-repository-permissions-for-a-user to retrieve a collaborators permissions for a specific repository. ### Checks the repository permissions of a collaborator. `GET` `/repos/{owner}/{repo}/collaborators/{collaborator}/permission` Possible `permission` values are `admin`, `write`, `read`, `owner`, `none`. ```json { "permission": "admin", "role_name": "admin", "user": {} } ``` Where `permission` and `role_name` hold the same `permission` value and `user` is filled with the user API object. Only admins are allowed to use this API endpoint.
Diffstat (limited to 'modules/convert')
-rw-r--r--modules/convert/user.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/modules/convert/user.go b/modules/convert/user.go
index dc4a8c49c7..2b07d21838 100644
--- a/modules/convert/user.go
+++ b/modules/convert/user.go
@@ -95,3 +95,12 @@ func User2UserSettings(user *user_model.User) api.UserSettings {
DiffViewStyle: user.DiffViewStyle,
}
}
+
+// ToUserAndPermission return User and its collaboration permission for a repository
+func ToUserAndPermission(user, doer *user_model.User, accessMode perm.AccessMode) api.RepoCollaboratorPermission {
+ return api.RepoCollaboratorPermission{
+ User: ToUser(user, doer),
+ Permission: accessMode.String(),
+ RoleName: accessMode.String(),
+ }
+}