Skip to content
This repository was archived by the owner on Jun 8, 2019. It is now read-only.

Change Collaborators List to include permissions #116

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gitea/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,25 @@ type Repository struct {
Permissions *Permission `json:"permissions,omitempty"`
}

// Collaborator represents a collaborator
// swagger:model
type Collaborator struct {
Copy link
Member

Choose a reason for hiding this comment

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

Why not use

// Collaborator represents a user with collaboration details.
type Collaborator struct {
	*User
	Collaboration *Collaboration
}

Copy link
Member

Choose a reason for hiding this comment

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

ping @zeripath

Copy link
Author

Choose a reason for hiding this comment

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

oh I'd sorta given up on this PR. I don't actually need it with the Sudo approach.

If you think the PR is still worth doing I'll do this.

Copy link
Member

Choose a reason for hiding this comment

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

I think it might be useful to see which permissions collaborators have, but I have no strong opinion, and I was going through PRs marked as stale so I'm ok with this (and linked PR) being closed.

Copy link
Author

Choose a reason for hiding this comment

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

I'll revise, rebase and update

// the user's id
ID int64 `json:"id"`
// the user's username
UserName string `json:"login"`
// the user's full name
FullName string `json:"full_name"`
// swagger:strfmt email
Email string `json:"email"`
// URL to the user's avatar
AvatarURL string `json:"avatar_url"`
// User locale
Language string `json:"language"`
// Permissions
Permissions *Permission `json:"permissions,omitempty"`
}

// ListMyRepos lists all repositories for the authenticated user that has access to.
func (c *Client) ListMyRepos() ([]*Repository, error) {
repos := make([]*Repository, 0, 10)
Expand Down
20 changes: 11 additions & 9 deletions gitea/repo_collaborator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

// ListCollaborators list a repository's collaborators
func (c *Client) ListCollaborators(user, repo string) ([]*User, error) {
collaborators := make([]*User, 0, 10)
func (c *Client) ListCollaborators(user, repo string) ([]*Collaborator, error) {
collaborators := make([]*Collaborator, 0, 10)
err := c.getParsedResponse("GET",
fmt.Sprintf("/repos/%s/%s/collaborators", user, repo),
nil, nil, &collaborators)
Expand All @@ -21,16 +21,18 @@ func (c *Client) ListCollaborators(user, repo string) ([]*User, error) {

// IsCollaborator check if a user is a collaborator of a repository
func (c *Client) IsCollaborator(user, repo, collaborator string) (bool, error) {
status, err := c.getStatusCode("GET",
var permission *Permission
err := c.getParsedResponse("GET",
fmt.Sprintf("/repos/%s/%s/collaborators/%s", user, repo, collaborator),
nil, nil)
nil, nil, &permission)
if err != nil {
return false, err
}
if status == 204 {
return true, nil
if err.Error() == "404 Not Found" {
return false, nil
} else {
return false, err
}
}
return false, nil
return (permission.Pull || permission.Push || permission.Admin), nil
}

// AddCollaboratorOption options when adding a user as a collaborator of a repository
Expand Down