InsertOrganizationMemberUser inserts a user as a member of an organization. If ifNotExists is true, it acts as a no-op if the user is already a member of the org. The function transactionally also adds the user to the relevant managed usergroups in the org. It may be called with or without holding
(ctx context.Context, orgID, userID, roleID string, attributes map[string]interface{}, ifNotExists bool)
| 17 | // The function transactionally also adds the user to the relevant managed usergroups in the org. |
| 18 | // It may be called with or without holding an existing transaction. |
| 19 | func (s *Service) InsertOrganizationMemberUser(ctx context.Context, orgID, userID, roleID string, attributes map[string]interface{}, ifNotExists bool) error { |
| 20 | ctx, tx, err := s.DB.NewTx(ctx, true) |
| 21 | if err != nil { |
| 22 | return err |
| 23 | } |
| 24 | defer func() { _ = tx.Rollback() }() |
| 25 | |
| 26 | inserted, err := s.DB.InsertOrganizationMemberUser(ctx, orgID, userID, roleID, attributes, ifNotExists) |
| 27 | if err != nil { |
| 28 | return err |
| 29 | } |
| 30 | |
| 31 | if inserted { |
| 32 | err = s.DB.InsertManagedUsergroupsMemberUser(ctx, orgID, userID, roleID) |
| 33 | if err != nil { |
| 34 | return err |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return tx.Commit() |
| 39 | } |
| 40 | |
| 41 | // InsertProjectMemberUser inserts a user as a member of a project. |
| 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. |
no test coverage detected