πŸ”“
Permissions
This resource represents permissions. Use it to obtain details of all permissions and determine whether the user has certain permissions.

Get my permissions

Returns a list of permissions indicating which permissions the user has. Details of the user's permissions can be obtained in a global, project, or issue context.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
6
"log"
7
"os"
8
)
9
​
10
func main() {
11
​
12
var (
13
host = os.Getenv("HOST")
14
mail = os.Getenv("MAIL")
15
token = os.Getenv("TOKEN")
16
)
17
​
18
atlassian, err := v2.New(nil, host)
19
if err != nil {
20
log.Fatal(err)
21
}
22
​
23
atlassian.Auth.SetBasicAuth(mail, token)
24
​
25
permissions, response, err := atlassian.Permission.Gets(context.Background())
26
if err != nil {
27
log.Fatal(err)
28
}
29
​
30
log.Println("HTTP Endpoint Used", response.Endpoint)
31
​
32
for _, permission := range permissions {
33
log.Println(permission)
34
}
35
}
Copied!

Check permissions

  • for a list of global permissions, the global permissions are granted to a user.
  • for a list of project permissions and lists of projects and issues, for each project permission a list of the projects and issues a user can access or manipulate.
If no account ID is provided, the operation returns details for the logged-in user.
1
package main
2
​
3
import (
4
"context"
5
"github.com/ctreminiom/go-atlassian/jira/v2"
6
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
7
"log"
8
"os"
9
)
10
​
11
func main() {
12
​
13
/*
14
----------- Set an environment variable in git bash -----------
15
export HOST="https://ctreminiom.atlassian.net/"
16
export MAIL="MAIL_ADDRESS"
17
export TOKEN="TOKEN_API"
18
​
19
Docs: https://stackoverflow.com/questions/34169721/set-an-environment-variable-in-git-bash
20
*/
21
​
22
var (
23
host = os.Getenv("HOST")
24
mail = os.Getenv("MAIL")
25
token = os.Getenv("TOKEN")
26
)
27
​
28
atlassian, err := v2.New(nil, host)
29
if err != nil {
30
log.Fatal(err)
31
}
32
​
33
atlassian.Auth.SetBasicAuth(mail, token)
34
​
35
payload := &models.PermissionCheckPayload{
36
GlobalPermissions: []string{"ADMINISTER"},
37
AccountID: "", //
38
ProjectPermissions: []*models.BulkProjectPermissionsScheme{
39
{
40
Issues: nil,
41
Projects: []int{10000},
42
Permissions: []string{"EDIT_ISSUES"},
43
},
44
},
45
}
46
​
47
grants, response, err := atlassian.Permission.Check(context.Background(), payload)
48
if err != nil {
49
log.Fatal(err)
50
}
51
​
52
log.Println("HTTP Endpoint Used", response.Endpoint)
53
​
54
for _, permission := range grants.ProjectPermissions {
55
log.Println(permission.Permission, permission.Issues)
56
}
57
​
58
}
Copied!
Export as PDF
Copy link