-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from ctreminiom/feature/confluence-restrictio…
…n-operation-user ✨ Added the Confluence Restriction Operation User service
- Loading branch information
Showing
4 changed files
with
621 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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("wiki/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("wiki/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("wiki/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 | ||
} |
Oops, something went wrong.