Skip to content

Commit

Permalink
ref: org role list and team role list
Browse files Browse the repository at this point in the history
  • Loading branch information
jianyuan committed Jan 12, 2024
1 parent 01d0536 commit 0f22970
Show file tree
Hide file tree
Showing 6 changed files with 354 additions and 51 deletions.
41 changes: 17 additions & 24 deletions sentry/organization_members.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,31 +6,24 @@ import (
"time"
)

// https://github.com/getsentry/sentry/blob/8b683002ec84f9edd338348500937a480e49e61c/src/sentry/api/serializers/models/role.py#L32
type RoleListItem struct {
ID string `json:"id"`
Name string `json:"name"`
IsAllowed bool `json:"isAllowed"`
}

// OrganizationMember represents a User's membership to the organization.
// https://github.com/getsentry/sentry/blob/22.5.0/src/sentry/api/serializers/models/organization_member/response.py#L57-L69
type OrganizationMember struct {
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
User User `json:"user"`
OrganizationRole string `json:"orgRole"`
OrganizationRoleList []RoleListItem `json:"orgRoleList"`
Pending bool `json:"pending"`
Expired bool `json:"expired"`
Flags map[string]bool `json:"flags"`
DateCreated time.Time `json:"dateCreated"`
InviteStatus string `json:"inviteStatus"`
InviterName *string `json:"inviterName"`
TeamRoleList []RoleListItem `json:"teamRoleList"`
TeamRoles []TeamRole `json:"teamRoles"`
Teams []string `json:"teams"`
ID string `json:"id"`
Email string `json:"email"`
Name string `json:"name"`
User User `json:"user"`
OrgRole string `json:"orgRole"`
OrgRoleList []OrganizationRoleListItem `json:"orgRoleList"`
Pending bool `json:"pending"`
Expired bool `json:"expired"`
Flags map[string]bool `json:"flags"`
DateCreated time.Time `json:"dateCreated"`
InviteStatus string `json:"inviteStatus"`
InviterName *string `json:"inviterName"`
TeamRoleList []TeamRoleListItem `json:"teamRoleList"`
TeamRoles []TeamRole `json:"teamRoles"`
Teams []string `json:"teams"`
}

const (
Expand Down Expand Up @@ -104,8 +97,8 @@ func (s *OrganizationMembersService) Create(ctx context.Context, organizationSlu
}

type TeamRole struct {
TeamSlug string `json:"teamSlug"`
Role string `json:"role"`
TeamSlug string `json:"teamSlug"`
Role *string `json:"role"`
}

type UpdateOrganizationMemberParams struct {
Expand Down
85 changes: 59 additions & 26 deletions sentry/organization_members_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,32 +590,57 @@ func TestOrganizationMembersService_Update(t *testing.T) {
},
},
},
OrganizationRole: OrganizationRoleMember,
OrganizationRoleList: []RoleListItem{
OrgRole: OrganizationRoleMember,
OrgRoleList: []OrganizationRoleListItem{
{
ID: "billing",
Name: "Billing",
IsAllowed: true,
ID: "billing",
Name: "Billing",
Desc: "Can manage subscription and billing details.",
Scopes: []string{"org:billing"},
IsAllowed: true,
IsRetired: false,
IsGlobal: false,
MinimumTeamRole: "contributor",
},
{
ID: "member",
Name: "Member",
IsAllowed: true,
ID: "member",
Name: "Member",
Desc: "Members can view and act on events, as well as view most other data within the organization.",
Scopes: []string{"team:read", "project:releases", "org:read", "event:read", "alerts:write", "member:read", "alerts:read", "event:admin", "project:read", "event:write"},
IsAllowed: true,
IsRetired: false,
IsGlobal: false,
MinimumTeamRole: "contributor",
},
{
ID: "admin",
Name: "Admin",
IsAllowed: true,
ID: "admin",
Name: "Admin",
Desc: "Admin privileges on any teams of which they're a member. They can create new teams and projects, as well as remove teams and projects on which they already hold membership (or all teams, if open membership is enabled). Additionally, they can manage memberships of teams that they are members of. They cannot invite members to the organization.",
Scopes: []string{"team:admin", "org:integrations", "project:admin", "team:read", "project:releases", "org:read", "team:write", "event:read", "alerts:write", "member:read", "alerts:read", "event:admin", "project:read", "event:write", "project:write"},
IsAllowed: true,
IsRetired: true,
IsGlobal: false,
MinimumTeamRole: "admin",
},
{
ID: "manager",
Name: "Manager",
IsAllowed: true,
ID: "manager",
Name: "Manager",
Desc: "Gains admin access on all teams as well as the ability to add and remove members.",
Scopes: []string{"team:admin", "org:integrations", "project:releases", "team:write", "member:read", "org:write", "project:write", "project:admin", "team:read", "org:read", "event:read", "member:write", "alerts:write", "alerts:read", "event:admin", "project:read", "event:write", "member:admin"},
IsAllowed: true,
IsRetired: false,
IsGlobal: true,
MinimumTeamRole: "admin",
},
{
ID: "owner",
Name: "Owner",
IsAllowed: true,
ID: "owner",
Name: "Owner",
Desc: "Unrestricted access to the organization, its data, and its settings. Can add, modify, and delete projects and members, as well as make billing and plan changes.",
Scopes: []string{"team:admin", "org:integrations", "project:releases", "org:admin", "team:write", "member:read", "org:write", "project:write", "project:admin", "team:read", "org:read", "event:read", "member:write", "alerts:write", "org:billing", "alerts:read", "event:admin", "project:read", "event:write", "member:admin"},
IsAllowed: true,
IsRetired: false,
IsGlobal: true,
MinimumTeamRole: "admin",
},
},
Pending: false,
Expand All @@ -631,26 +656,34 @@ func TestOrganizationMembersService_Update(t *testing.T) {
DateCreated: mustParseTime("2021-07-06T21:13:01.120263Z"),
InviteStatus: "approved",
InviterName: &inviterName,
TeamRoleList: []RoleListItem{
TeamRoleList: []TeamRoleListItem{
{
ID: "contributor",
Name: "Contributor",
IsAllowed: false,
ID: "contributor",
Name: "Contributor",
Desc: "Contributors can view and act on events, as well as view most other data within the team's projects.",
Scopes: []string{"team:read", "project:releases", "org:read", "event:read", "member:read", "alerts:read", "project:read", "event:write"},
IsAllowed: false,
IsRetired: false,
IsMinimumRoleFor: nil,
},
{
ID: "admin",
Name: "Team Admin",
IsAllowed: false,
ID: "admin",
Name: "Team Admin",
Desc: "Admin privileges on the team. They can create and remove projects, and can manage the team's memberships. They cannot invite members to the organization.",
Scopes: []string{"team:admin", "org:integrations", "project:admin", "team:read", "project:releases", "org:read", "team:write", "event:read", "alerts:write", "member:read", "alerts:read", "event:admin", "project:read", "event:write", "project:write"},
IsAllowed: false,
IsRetired: false,
IsMinimumRoleFor: String("admin"),
},
},
TeamRoles: []TeamRole{
{
TeamSlug: "ancient-gabelers",
Role: TeamRoleAdmin,
Role: String(TeamRoleAdmin),
},
{
TeamSlug: "powerful-abolitionist",
Role: TeamRoleContributor,
Role: String(TeamRoleContributor),
},
},
Teams: []string{
Expand Down
2 changes: 2 additions & 0 deletions sentry/organizations.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type Organization struct {
IsDefault *bool `json:"isDefault,omitempty"`
DefaultRole *string `json:"defaultRole,omitempty"`
AvailableRoles []OrganizationAvailableRole `json:"availableRoles,omitempty"`
OrgRoleList []OrganizationRoleListItem `json:"orgRoleList,omitempty"`
TeamRoleList []TeamRoleListItem `json:"teamRoleList,omitempty"`
OpenMembership *bool `json:"openMembership,omitempty"`
AllowSharedIssues *bool `json:"allowSharedIssues,omitempty"`
EnhancedPrivacy *bool `json:"enhancedPrivacy,omitempty"`
Expand Down
Loading

0 comments on commit 0f22970

Please sign in to comment.