summaryrefslogtreecommitdiffstats
path: root/modules
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
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')
-rw-r--r--modules/convert/user.go9
-rw-r--r--modules/structs/repo_collaborator.go7
2 files changed, 16 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(),
+ }
+}
diff --git a/modules/structs/repo_collaborator.go b/modules/structs/repo_collaborator.go
index 2b4fa390d2..2f9c8992a1 100644
--- a/modules/structs/repo_collaborator.go
+++ b/modules/structs/repo_collaborator.go
@@ -8,3 +8,10 @@ package structs
type AddCollaboratorOption struct {
Permission *string `json:"permission"`
}
+
+// RepoCollaboratorPermission to get repository permission for a collaborator
+type RepoCollaboratorPermission struct {
+ Permission string `json:"permission"`
+ RoleName string `json:"role_name"`
+ User *User `json:"user"`
+}