forked from ctreminiom/go-atlassian
/
contentRestrictionOperationUser.go
132 lines (100 loc) · 3.56 KB
/
contentRestrictionOperationUser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package confluence
import (
"context"
"fmt"
"github.com/ctreminiom/go-atlassian/pkg/infra/models"
"net/http"
"net/url"
"strings"
)
type ContentRestrictionOperationUserService struct{ client *Client }
// Get returns whether the specified content restriction applies to a user.
// Docs: https://docs.go-atlassian.io/confluence-cloud/content/restrictions/operations/user#get-content-restriction-status-for-user
func (c *ContentRestrictionOperationUserService) Get(ctx context.Context, contentID, operationKey, accountID string) (
response *ResponseScheme, err error) {
if len(contentID) == 0 {
return nil, models.ErrNoContentIDError
}
if len(operationKey) == 0 {
return nil, models.ErrNoContentRestrictionKeyError
}
if len(accountID) == 0 {
return nil, models.ErrNoAccountIDError
}
var endpoint strings.Builder
endpoint.WriteString(fmt.Sprintf("rest/api/content/%v/restriction/byOperation/%v/user", contentID, operationKey))
query := url.Values{}
query.Add("accountId", accountID)
if query.Encode() != "" {
endpoint.WriteString(fmt.Sprintf("?%v", query.Encode()))
}
request, err := c.client.newRequest(ctx, http.MethodGet, endpoint.String(), nil)
if err != nil {
return nil, err
}
response, err = c.client.Call(request, nil)
if err != nil {
return response, err
}
return
}
// Add adds a user to a content restriction. That is, grant read or update permission to the user for a piece of content.
// Docs: https://docs.go-atlassian.io/confluence-cloud/content/restrictions/operations/user#add-user-to-content-restriction
func (c *ContentRestrictionOperationUserService) Add(ctx context.Context, contentID, operationKey, accountID string) (
response *ResponseScheme, err error) {
if len(contentID) == 0 {
return nil, models.ErrNoContentIDError
}
if len(operationKey) == 0 {
return nil, models.ErrNoContentRestrictionKeyError
}
if len(accountID) == 0 {
return nil, models.ErrNoAccountIDError
}
var endpoint strings.Builder
endpoint.WriteString(fmt.Sprintf("rest/api/content/%v/restriction/byOperation/%v/user", contentID, operationKey))
query := url.Values{}
query.Add("accountId", accountID)
if query.Encode() != "" {
endpoint.WriteString(fmt.Sprintf("?%v", query.Encode()))
}
request, err := c.client.newRequest(ctx, http.MethodPut, endpoint.String(), nil)
if err != nil {
return nil, err
}
response, err = c.client.Call(request, nil)
if err != nil {
return response, err
}
return
}
// Remove removes a group from a content restriction. That is, remove read or update permission for the group for a piece of content.
// Docs: https://docs.go-atlassian.io/confluence-cloud/content/restrictions/operations/user#remove-user-from-content-restriction
func (c *ContentRestrictionOperationUserService) Remove(ctx context.Context, contentID, operationKey, accountID string) (
response *ResponseScheme, err error) {
if len(contentID) == 0 {
return nil, models.ErrNoContentIDError
}
if len(operationKey) == 0 {
return nil, models.ErrNoContentRestrictionKeyError
}
if len(accountID) == 0 {
return nil, models.ErrNoAccountIDError
}
var endpoint strings.Builder
endpoint.WriteString(fmt.Sprintf("rest/api/content/%v/restriction/byOperation/%v/user", contentID, operationKey))
query := url.Values{}
query.Add("accountId", accountID)
if query.Encode() != "" {
endpoint.WriteString(fmt.Sprintf("?%v", query.Encode()))
}
request, err := c.client.newRequest(ctx, http.MethodDelete, endpoint.String(), nil)
if err != nil {
return nil, err
}
response, err = c.client.Call(request, nil)
if err != nil {
return response, err
}
return
}