Remove duplicate membership method
Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
@@ -52,7 +52,13 @@ func (m Membership) CursorKey(orderBy MembershipOrderField) page.CursorKey {
|
|||||||
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
panic(fmt.Sprintf("unsupported order by: %s", orderBy))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Membership) LoadByIdentityInOrganization(ctx context.Context, conn pg.Conn, identityID gid.GID, organizationID gid.GID) error {
|
func (m *Membership) LoadByIdentityIDAndOrganizationID(
|
||||||
|
ctx context.Context,
|
||||||
|
conn pg.Conn,
|
||||||
|
scope Scoper,
|
||||||
|
identityID gid.GID,
|
||||||
|
organizationID gid.GID,
|
||||||
|
) error {
|
||||||
q := `
|
q := `
|
||||||
SELECT
|
SELECT
|
||||||
id,
|
id,
|
||||||
@@ -66,14 +72,19 @@ FROM
|
|||||||
WHERE
|
WHERE
|
||||||
identity_id = @identity_id
|
identity_id = @identity_id
|
||||||
AND organization_id = @organization_id
|
AND organization_id = @organization_id
|
||||||
|
AND %s
|
||||||
`
|
`
|
||||||
|
|
||||||
|
q = fmt.Sprintf(q, scope.SQLFragment())
|
||||||
|
|
||||||
args := pgx.StrictNamedArgs{
|
args := pgx.StrictNamedArgs{
|
||||||
"identity_id": identityID,
|
"identity_id": identityID,
|
||||||
"organization_id": organizationID,
|
"organization_id": organizationID,
|
||||||
}
|
}
|
||||||
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
rows,
|
||||||
|
err := conn.Query(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot query membership: %w", err)
|
return fmt.Errorf("cannot query membership: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -268,7 +268,7 @@ func (s *AccountService) AcceptInvitation(
|
|||||||
}
|
}
|
||||||
|
|
||||||
existingMembership := &coredata.Membership{}
|
existingMembership := &coredata.Membership{}
|
||||||
if err := existingMembership.LoadByIdentityAndOrg(
|
if err := existingMembership.LoadByIdentityIDAndOrganizationID(
|
||||||
ctx,
|
ctx,
|
||||||
tx,
|
tx,
|
||||||
scope,
|
scope,
|
||||||
@@ -775,7 +775,13 @@ func (s AccountService) GetMembershipForOrganization(
|
|||||||
return fmt.Errorf("cannot load identity %q: %w", identityID, err)
|
return fmt.Errorf("cannot load identity %q: %w", identityID, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := membership.LoadByIdentityInOrganization(ctx, tx, identityID, organizationID); err != nil {
|
if err := membership.LoadByIdentityIDAndOrganizationID(
|
||||||
|
ctx,
|
||||||
|
tx,
|
||||||
|
coredata.NewScopeFromObjectID(organizationID),
|
||||||
|
identityID,
|
||||||
|
organizationID,
|
||||||
|
); err != nil {
|
||||||
return fmt.Errorf("cannot load membership: %w", err)
|
return fmt.Errorf("cannot load membership: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -281,7 +281,7 @@ func (s *OrganizationService) RemoveMember(
|
|||||||
}
|
}
|
||||||
|
|
||||||
membership := &coredata.Membership{}
|
membership := &coredata.Membership{}
|
||||||
if err := membership.LoadByIdentityAndOrg(ctx, tx, scope, profile.IdentityID, profile.OrganizationID); err != nil {
|
if err := membership.LoadByIdentityIDAndOrganizationID(ctx, tx, scope, profile.IdentityID, profile.OrganizationID); err != nil {
|
||||||
return fmt.Errorf("cannot load membership: %w", err)
|
return fmt.Errorf("cannot load membership: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -328,7 +328,7 @@ func (s *Service) HandleAssertion(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := membership.LoadByIdentityAndOrg(
|
if err := membership.LoadByIdentityIDAndOrganizationID(
|
||||||
ctx,
|
ctx,
|
||||||
tx,
|
tx,
|
||||||
scope,
|
scope,
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ func (s *Service) CreateUser(
|
|||||||
|
|
||||||
// Check if membership exists
|
// Check if membership exists
|
||||||
membership = &coredata.Membership{}
|
membership = &coredata.Membership{}
|
||||||
if err := membership.LoadByIdentityAndOrg(
|
if err := membership.LoadByIdentityIDAndOrganizationID(
|
||||||
ctx,
|
ctx,
|
||||||
tx,
|
tx,
|
||||||
scope,
|
scope,
|
||||||
@@ -294,7 +294,7 @@ func (s *Service) GetUser(
|
|||||||
}
|
}
|
||||||
|
|
||||||
membership = &coredata.Membership{}
|
membership = &coredata.Membership{}
|
||||||
if err := membership.LoadByIdentityAndOrg(
|
if err := membership.LoadByIdentityIDAndOrganizationID(
|
||||||
ctx,
|
ctx,
|
||||||
conn,
|
conn,
|
||||||
scope,
|
scope,
|
||||||
@@ -437,7 +437,7 @@ func (s *Service) updateUser(
|
|||||||
}
|
}
|
||||||
|
|
||||||
membership = &coredata.Membership{}
|
membership = &coredata.Membership{}
|
||||||
if err := membership.LoadByIdentityAndOrg(ctx, tx, scope, profile.IdentityID, profile.OrganizationID); err != nil {
|
if err := membership.LoadByIdentityIDAndOrganizationID(ctx, tx, scope, profile.IdentityID, profile.OrganizationID); err != nil {
|
||||||
return fmt.Errorf("cannot load membership: %w", err)
|
return fmt.Errorf("cannot load membership: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -366,7 +366,7 @@ func (s SessionService) OpenPasswordChildSessionForOrganization(
|
|||||||
return NewUserInactiveError(profile.ID)
|
return NewUserInactiveError(profile.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = membership.LoadByIdentityInOrganization(ctx, tx, rootSession.IdentityID, organizationID)
|
err = membership.LoadByIdentityIDAndOrganizationID(ctx, tx, scope, rootSession.IdentityID, organizationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == coredata.ErrResourceNotFound {
|
if err == coredata.ErrResourceNotFound {
|
||||||
return NewMembershipNotFoundError(organizationID)
|
return NewMembershipNotFoundError(organizationID)
|
||||||
@@ -468,7 +468,7 @@ func (s SessionService) OpenSAMLChildSessionForOrganization(
|
|||||||
return NewUserInactiveError(profile.ID)
|
return NewUserInactiveError(profile.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = membership.LoadByIdentityInOrganization(ctx, tx, rootSession.IdentityID, organizationID)
|
err = membership.LoadByIdentityIDAndOrganizationID(ctx, tx, scope, rootSession.IdentityID, organizationID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == coredata.ErrResourceNotFound {
|
if err == coredata.ErrResourceNotFound {
|
||||||
return NewMembershipNotFoundError(organizationID)
|
return NewMembershipNotFoundError(organizationID)
|
||||||
@@ -554,7 +554,7 @@ func (s SessionService) AssumeOrganizationSession(
|
|||||||
return NewUserInactiveError(profile.ID)
|
return NewUserInactiveError(profile.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := membership.LoadByIdentityInOrganization(ctx, tx, rootSession.IdentityID, organizationID); err != nil {
|
if err := membership.LoadByIdentityIDAndOrganizationID(ctx, tx, scope, rootSession.IdentityID, organizationID); err != nil {
|
||||||
if err == coredata.ErrResourceNotFound {
|
if err == coredata.ErrResourceNotFound {
|
||||||
return NewMembershipNotFoundError(organizationID)
|
return NewMembershipNotFoundError(organizationID)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user