Skip to content

Commit

Permalink
revoke pending org invite
Browse files Browse the repository at this point in the history
  • Loading branch information
pfvatterott committed Aug 15, 2024
1 parent ff63c31 commit 24377a6
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 14 deletions.
27 changes: 24 additions & 3 deletions pkg/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type ClientInterface interface {
UpdateOrgMetadata(orgID uuid.UUID, params models.UpdateOrg) (bool, error)
SubscribeOrgToRoleMapping(orgID uuid.UUID, params models.OrgRoleMappingSubscription) (bool, error)
ChangeUserRoleInOrg(params models.ChangeUserRoleInOrg) (bool, error)
RevokePendingOrgInvite(params models.RevokePendingOrgInvite) (bool, error)

// user in org endpoints
AddUserToOrg(params models.AddUserToOrg) (bool, error)
Expand Down Expand Up @@ -579,7 +580,7 @@ func (o *Client) MigrateUserFromExternalSource(params models.MigrateUserParams)
func (o *Client) DeleteUser(userID uuid.UUID) (bool, error) {
urlPostfix := fmt.Sprintf("user/%s", userID)

queryResponse, err := o.queryHelper.Delete(o.integrationAPIKey, urlPostfix, nil)
queryResponse, err := o.queryHelper.Delete(o.integrationAPIKey, urlPostfix, nil, nil)
if err != nil {
return false, fmt.Errorf("Error on deleting user: %w", err)
}
Expand Down Expand Up @@ -942,6 +943,26 @@ func (o *Client) FetchPendingInvites(params models.FetchPendingInvitesParams) (*
return pendingInvites, nil
}

func (o *Client) RevokePendingOrgInvite(params models.RevokePendingOrgInvite) (bool, error) {
urlPostfix := "pending_org_invites"

bodyJSON, err := json.Marshal(params)
if err != nil {
return false, fmt.Errorf("Error on marshalling body params: %w", err)
}

queryResponse, err := o.queryHelper.Delete(o.integrationAPIKey, urlPostfix, nil, bodyJSON)
if err != nil {
return false, fmt.Errorf("Error deleting pending org invite: %w", err)
}

if err := o.returnErrorMessageIfNotOk(queryResponse); err != nil {
return false, fmt.Errorf("Error deleting pending org invite: %w", err)
}

return true, nil
}

// NOTE: THIS IS DEPRECATED.
// CreateOrg will an organization and return its data, which is mostly just the org's ID.
func (o *Client) CreateOrg(name string) (*models.OrgMetadata, error) {
Expand Down Expand Up @@ -1011,7 +1032,7 @@ func (o *Client) CreateOrgV2(params models.CreateOrgV2Params) (*models.CreateOrg
func (o *Client) DeleteOrg(orgID uuid.UUID) (bool, error) {
urlPostfix := fmt.Sprintf("org/%s", orgID)

queryResponse, err := o.queryHelper.Delete(o.integrationAPIKey, urlPostfix, nil)
queryResponse, err := o.queryHelper.Delete(o.integrationAPIKey, urlPostfix, nil, nil)
if err != nil {
return false, fmt.Errorf("Error on deleting an org: %w", err)
}
Expand Down Expand Up @@ -1168,7 +1189,7 @@ func (o *Client) UpdateAPIKey(apiKeyID string, params models.APIKeyUpdateParams)
func (o *Client) DeleteAPIKey(apiKeyID string) (bool, error) {
urlPostfix := fmt.Sprintf("end_user_api_keys/%s", apiKeyID)

queryResponse, err := o.queryHelper.Delete(o.integrationAPIKey, urlPostfix, nil)
queryResponse, err := o.queryHelper.Delete(o.integrationAPIKey, urlPostfix, nil, nil)
if err != nil {
return false, fmt.Errorf("Error on deleting an API key: %w", err)
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/helpers/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type QueryHelperInterface interface {
Patch(token string, urlPostfix string, queryParams url.Values, bodyParams []byte) (*QueryResponse, error)
Post(token string, urlPostfix string, queryParams url.Values, bodyParams []byte) (*QueryResponse, error)
Put(token string, urlPostfix string, queryParams url.Values, bodyParams []byte) (*QueryResponse, error)
Delete(token string, urlPostfix string, queryParams url.Values) (*QueryResponse, error)
Delete(token string, urlPostfix string, queryParams url.Values, bodyParams []byte) (*QueryResponse, error)
}

type QueryHelper struct {
Expand Down Expand Up @@ -64,10 +64,10 @@ func (o *QueryHelper) Put(token string, urlPostfix string, queryParams url.Value
return o.RequestHelper("PUT", token, url, bodyParams)
}

func (o *QueryHelper) Delete(token string, urlPostfix string, queryParams url.Values) (*QueryResponse, error) {
func (o *QueryHelper) Delete(token string, urlPostfix string, queryParams url.Values, bodyParams []byte) (*QueryResponse, error) {
url := o.assembleURL(urlPostfix, queryParams)

return o.RequestHelper("DELETE", token, url, nil)
return o.RequestHelper("DELETE", token, url, bodyParams)
}

// public helper method
Expand All @@ -84,7 +84,7 @@ func (o *QueryHelper) RequestHelper(method string, token string, url string, bod
// add headers
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "Bearer "+token)
req.Header.Set("User-Agent", "propelauth-go/0.8 go/" + runtime.Version() + " " + runtime.GOOS + "/" + runtime.GOARCH)
req.Header.Set("User-Agent", "propelauth-go/0.8 go/"+runtime.Version()+" "+runtime.GOOS+"/"+runtime.GOARCH)

// send request
client := &http.Client{}
Expand Down
19 changes: 12 additions & 7 deletions pkg/models/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ type OrgQueryParams struct {

// CreateOrgV2Params is the information needed to create an organization, as well as some optional fields.
type CreateOrgV2Params struct {
Name string `json:"name"`
Domain string `json:"domain,omitempty"`
EnableAutoJoiningByDomain bool `json:"enable_auto_joining_by_domain,omitempty"`
MembersMustHaveMatchingDomain bool `json:"members_must_have_matching_domain,omitempty"`
MaxUsers int `json:"max_users,omitempty"`
CustomRoleMappingName *string `json:"custom_role_mapping_name,omitempty"`
LegacyOrgId *string `json:"legacy_org_id,omitempty"`
Name string `json:"name"`
Domain string `json:"domain,omitempty"`
EnableAutoJoiningByDomain bool `json:"enable_auto_joining_by_domain,omitempty"`
MembersMustHaveMatchingDomain bool `json:"members_must_have_matching_domain,omitempty"`
MaxUsers int `json:"max_users,omitempty"`
CustomRoleMappingName *string `json:"custom_role_mapping_name,omitempty"`
LegacyOrgId *string `json:"legacy_org_id,omitempty"`
}

// CreateOrgV2Response is the information returned when creating an organization.
Expand Down Expand Up @@ -156,3 +156,8 @@ type FetchPendingInvitesParams struct {
PageNumber *int `json:"page_number,omitempty"`
OrgID *uuid.UUID `json:"org_id,omitempty"`
}

type RevokePendingOrgInvite struct {
OrgID *uuid.UUID `json:"org_id,omitempty"`
InviteeEmail string `json:"invitee_email"`
}

0 comments on commit 24377a6

Please sign in to comment.