MCPcopy Index your code
hub / github.com/rilldata/rill / InsertProjectMemberUser

Method InsertProjectMemberUser

admin/user.go:44–70  ·  view source on GitHub ↗

InsertProjectMemberUser inserts a user as a member of a project. If the user is not already a member of the project's organization, it transactionally adds them as a guest of the org as well. It may be called with or without holding an existing transaction.

(ctx context.Context, orgID, projectID, userID, roleID string, attributes map[string]interface{}, restrictResources bool, resources []database.ResourceName)

Source from the content-addressed store, hash-verified

42// If the user is not already a member of the project's organization, it transactionally adds them as a guest of the org as well.
43// It may be called with or without holding an existing transaction.
44func (s *Service) InsertProjectMemberUser(ctx context.Context, orgID, projectID, userID, roleID string, attributes map[string]interface{}, restrictResources bool, resources []database.ResourceName) error {
45 guestRole, err := s.DB.FindOrganizationRole(ctx, database.OrganizationRoleNameGuest)
46 if err != nil {
47 return err
48 }
49
50 ctx, tx, err := s.DB.NewTx(ctx, true)
51 if err != nil {
52 return err
53 }
54 defer func() { _ = tx.Rollback() }()
55
56 // Insert the user as a member of the project.
57 err = s.DB.InsertProjectMemberUser(ctx, projectID, userID, roleID, restrictResources, resources)
58 if err != nil {
59 return err
60 }
61
62 // All project-level members must also be org members.
63 // So if the user is not already a member of the organization, add them as a guest.
64 err = s.InsertOrganizationMemberUser(ctx, orgID, userID, guestRole.ID, attributes, true)
65 if err != nil {
66 return err
67 }
68
69 return tx.Commit()
70}
71
72// DeleteOrganizationMemberUser deletes a user as a member of an organization.
73// It transactionally also removes the user from all user groups in the org and all projects in the org.

Callers 2

CreateProjectMethod · 0.95
CreateOrUpdateUserMethod · 0.95

Calls 6

FindOrganizationRoleMethod · 0.65
NewTxMethod · 0.65
RollbackMethod · 0.65
CommitMethod · 0.65

Tested by

no test coverage detected