Notification Setup Error

We have detected an error in your notification set-up (Event-ID dab39dc24f564ec7bd4628d1305fd03c). Currently, we cannot inform you about inspection progress. Please check that the user 557058:bca11929-8c2d-43f2-8a82-c5416880d395 still has access to your repository or update the API account.

GroupPrivileges   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 115
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A groups() 0 6 1
A repository() 0 6 1
A group() 0 6 1
A repositories() 0 6 1
A grant() 0 11 2
A delete() 0 6 1
1
<?php
2
3
/**
4
 * This file is part of the bitbucket-api package.
5
 *
6
 * (c) Alexandru G. <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Bitbucket\API;
13
14
use Psr\Http\Message\ResponseInterface;
15
16
/**
17
 * Manages a group's repository permissions.
18
 *
19
 * @author  Alexandru G.    <[email protected]>
20
 * @see https://confluence.atlassian.com/bitbucket/group-privileges-endpoint-296093137.html
21
 */
22
class GroupPrivileges extends Api
23
{
24
    /**
25
     * Get a list of privileged groups
26
     *
27
     * Gets all the groups granted access to an account's repositories.
28
     *
29
     * @access public
30
     * @param  string           $workspaceId The team or individual account owning the repository.
31
     * @return ResponseInterface
32 1
     */
33
    public function groups($workspaceId)
34 1
    {
35 1
        return $this->getClient()->setApiVersion('1.0')->get(
36
            sprintf('/group-privileges/%s/', $workspaceId)
37
        );
38
    }
39
40
    /**
41
     * Get a list of privileged groups for a repository
42
     *
43
     * Get a list of the privilege groups for a specific repository.
44
     *
45
     * @access public
46
     * @param  string           $workspaceId The team or individual account owning the repository.
47
     * @param  string           $repo        A repository belonging to the account.
48
     * @return ResponseInterface
49 1
     */
50
    public function repository($workspaceId, $repo)
51 1
    {
52 1
        return $this->getClient()->setApiVersion('1.0')->get(
53
            sprintf('/group-privileges/%s/%s', $workspaceId, $repo)
54
        );
55
    }
56
57
    /**
58
     * Get a group on a repository
59
     *
60
     * Gets the privileges of a group on a repository.
61
     *
62
     * @access public
63
     * @param  string           $workspaceId The team or individual account owning the repository.
64
     * @param  string           $repo        A repository belonging to the account.
65
     * @param  string           $groupOwner  The account that owns the group.
66
     * @param  string           $groupSlug   The group slug.
67
     * @return ResponseInterface
68 1
     */
69
    public function group($workspaceId, $repo, $groupOwner, $groupSlug)
70 1
    {
71 1
        return $this->getClient()->setApiVersion('1.0')->get(
72
            sprintf('/group-privileges/%s/%s/%s/%s', $workspaceId, $repo, $groupOwner, $groupSlug)
73
        );
74
    }
75
76
    /**
77
     * Get a list of repositories with a specific privilege group
78
     *
79
     * Get a list of the repositories on which a particular privilege group appears.
80
     *
81
     * @access public
82
     * @param  string           $workspaceId The team or individual account owning the repository.
83
     * @param  string           $groupOwner  The account that owns the group.
84
     * @param  string           $groupSlug   The group slug.
85
     * @return ResponseInterface
86 1
     */
87
    public function repositories($workspaceId, $groupOwner, $groupSlug)
88 1
    {
89 1
        return $this->getClient()->setApiVersion('1.0')->get(
90
            sprintf('/group-privileges/%s/%s/%s', $workspaceId, $groupOwner, $groupSlug)
91
        );
92
    }
93
94
    /**
95
     *
96
     * Grant group privileges on a repository.
97
     *
98
     * @access public
99
     * @param  string           $workspaceId The team or individual account owning the repository.
100
     * @param  string           $repo        The repository to grant privileges on.
101
     * @param  string           $groupOwner  The account that owns the group.
102
     * @param  string           $groupSlug   The group slug.
103
     * @param  string           $privilege   A privilege value
104
     * @return ResponseInterface
105
     *
106
     * @throws \InvalidArgumentException
107 2
     */
108
    public function grant($workspaceId, $repo, $groupOwner, $groupSlug, $privilege)
109 2
    {
110 1
        if (!in_array($privilege, array('read', 'write', 'admin'))) {
111
            throw new \InvalidArgumentException("Invalid privilege provided.");
112
        }
113 1
114 1
        return $this->getClient()->setApiVersion('1.0')->put(
115 1
            sprintf('/group-privileges/%s/%s/%s/%s', $workspaceId, $repo, $groupOwner, $groupSlug),
116
            $privilege
117
        );
118
    }
119
120
    /**
121
     * Delete group privileges from a repository
122
     *
123
     * @access public
124
     * @param  string           $workspaceId The team or individual account.
125
     * @param  string           $repo        The repository to remove privileges from.
126
     * @param  string           $groupOwner  The account that owns the group.
127
     * @param  string           $groupSlug   The group slug.
128
     * @return ResponseInterface
129 1
     */
130
    public function delete($workspaceId, $repo, $groupOwner, $groupSlug)
131 1
    {
132 1
        return $this->getClient()->setApiVersion('1.0')->delete(
133
            sprintf('/group-privileges/%s/%s/%s/%s', $workspaceId, $repo, $groupOwner, $groupSlug)
134
        );
135
    }
136
}
137