mirror of
https://github.com/SigNoz/signoz.git
synced 2026-03-11 07:52:04 +00:00
Some checks failed
build-staging / prepare (push) Has been cancelled
build-staging / js-build (push) Has been cancelled
build-staging / go-build (push) Has been cancelled
build-staging / staging (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
* feat: deprecate user invite table * fix: handle soft deleted users flow * fix: handle edge cases for authentication and reset password flow * feat: integration tests with fixes for new flow * fix: array for grants * fix: edge cases for reset token and context api * chore: remove all code related to old invite flow * fix: openapi specs * fix: integration tests and minor naming change * fix: integration tests fmtlint * feat: improve invitation email template * fix: role tests * fix: context api * fix: openapi frontend * chore: rename countbyorgid to activecountbyorgid * fix: a deleted user cannot recycled, creating a new one * feat: migrate existing invites to user as pending invite status * fix: error from GetUsersByEmailAndOrgID * feat: add backward compatibility to existing apis using new invite flow * chore: change ordering of apis in server * chore: change ordering of apis in server * fix: filter active users in role and org id check * fix: check deleted user in reset password flow * chore: address some review comments, add back countbyorgid method * chore: move to bulk inserts for migrating existing invites * fix: wrap funcs to transactions, and fix openapi specs * fix: move reset link method to types, also move authz grants outside transation * fix: transaction issues * feat: helper method ErrIfDeleted for user * fix: error code for errifdeleted in user * fix: soft delete store method * fix: password authn tests also add old invite flow test * fix: callbackauthn tests * fix: remove extra oidc tests * fix: callback authn tests oidc * chore: address review comments and optimise bulk invite api * fix: use db ctx in various places * fix: fix duplicate email invite issue and add partial invite * fix: openapi specs * fix: errifpending * fix: user status persistence * fix: edge cases * chore: add tests for partial index too * feat: use composite unique index on users table instead of partial one * chore: move duplicate email check to unmarshaljson and query user again in accept invite * fix: make 068 migratin idempotent * chore: remove unused emails var * chore: add a temp filter to show only active users in frontend until next frontend fix * chore: remove one check from register flow testing until temp code is removed * chore: remove commented code from tests * chore: address frontend review comments * chore: address frontend review comments
116 lines
5.1 KiB
Go
116 lines
5.1 KiB
Go
package user
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"github.com/SigNoz/signoz/pkg/statsreporter"
|
|
"github.com/SigNoz/signoz/pkg/types"
|
|
"github.com/SigNoz/signoz/pkg/valuer"
|
|
)
|
|
|
|
type Module interface {
|
|
// Creates the organization and the first user of that organization.
|
|
CreateFirstUser(ctx context.Context, organization *types.Organization, name string, email valuer.Email, password string) (*types.User, error)
|
|
|
|
// Creates a user and sends an analytics event.
|
|
CreateUser(ctx context.Context, user *types.User, opts ...CreateUserOption) error
|
|
|
|
// Get or create a user. If a user with the same email and orgID already exists, it returns the existing user.
|
|
GetOrCreateUser(ctx context.Context, user *types.User, opts ...CreateUserOption) (*types.User, error)
|
|
|
|
// Get or Create a reset password token for a user. If the password does not exist, a new one is randomly generated and inserted. The function
|
|
// is idempotent and can be called multiple times.
|
|
GetOrCreateResetPasswordToken(ctx context.Context, userID valuer.UUID) (*types.ResetPasswordToken, error)
|
|
|
|
// Updates password of a user using a reset password token. It also deletes all reset password tokens for the user.
|
|
// This is used to reset the password of a user when they forget their password.
|
|
UpdatePasswordByResetPasswordToken(ctx context.Context, token string, password string) error
|
|
|
|
// Updates password of user to the new password. It also deletes all reset password tokens for the user.
|
|
UpdatePassword(ctx context.Context, userID valuer.UUID, oldPassword string, password string) error
|
|
|
|
// Initiate forgot password flow for a user
|
|
ForgotPassword(ctx context.Context, orgID valuer.UUID, email valuer.Email, frontendBaseURL string) error
|
|
|
|
UpdateUser(ctx context.Context, orgID valuer.UUID, id string, user *types.User, updatedBy string) (*types.User, error)
|
|
|
|
// UpdateAnyUser updates a user and persists the changes to the database along with the analytics and identity deletion.
|
|
UpdateAnyUser(ctx context.Context, orgID valuer.UUID, user *types.User) error
|
|
DeleteUser(ctx context.Context, orgID valuer.UUID, id string, deletedBy string) error
|
|
|
|
// invite
|
|
CreateBulkInvite(ctx context.Context, orgID valuer.UUID, userID valuer.UUID, bulkInvites *types.PostableBulkInviteRequest) ([]*types.Invite, error)
|
|
ListInvite(ctx context.Context, orgID string) ([]*types.Invite, error)
|
|
AcceptInvite(ctx context.Context, token string, password string) (*types.User, error)
|
|
GetInviteByToken(ctx context.Context, token string) (*types.Invite, error)
|
|
|
|
// API KEY
|
|
CreateAPIKey(ctx context.Context, apiKey *types.StorableAPIKey) error
|
|
UpdateAPIKey(ctx context.Context, id valuer.UUID, apiKey *types.StorableAPIKey, updaterID valuer.UUID) error
|
|
ListAPIKeys(ctx context.Context, orgID valuer.UUID) ([]*types.StorableAPIKeyUser, error)
|
|
RevokeAPIKey(ctx context.Context, id, removedByUserID valuer.UUID) error
|
|
GetAPIKey(ctx context.Context, orgID valuer.UUID, id valuer.UUID) (*types.StorableAPIKeyUser, error)
|
|
|
|
GetNonDeletedUserByEmailAndOrgID(ctx context.Context, email valuer.Email, orgID valuer.UUID) (*types.User, error)
|
|
|
|
statsreporter.StatsCollector
|
|
}
|
|
|
|
type Getter interface {
|
|
// Get root user by org id.
|
|
GetRootUserByOrgID(context.Context, valuer.UUID) (*types.User, error)
|
|
|
|
// Get gets the users based on the given id
|
|
ListByOrgID(context.Context, valuer.UUID) ([]*types.User, error)
|
|
|
|
// Get users by email.
|
|
GetUsersByEmail(context.Context, valuer.Email) ([]*types.User, error)
|
|
|
|
// Get user by orgID and id.
|
|
GetByOrgIDAndID(context.Context, valuer.UUID, valuer.UUID) (*types.User, error)
|
|
|
|
// Get user by id.
|
|
Get(context.Context, valuer.UUID) (*types.User, error)
|
|
|
|
// List users by email and org ids.
|
|
ListUsersByEmailAndOrgIDs(context.Context, valuer.Email, []valuer.UUID) ([]*types.User, error)
|
|
|
|
// Count users by org id.
|
|
CountByOrgID(context.Context, valuer.UUID) (int64, error)
|
|
|
|
// Count of users by org id and grouped by status.
|
|
CountByOrgIDAndStatuses(context.Context, valuer.UUID, []string) (map[valuer.String]int64, error)
|
|
|
|
// Get factor password by user id.
|
|
GetFactorPasswordByUserID(context.Context, valuer.UUID) (*types.FactorPassword, error)
|
|
}
|
|
|
|
type Handler interface {
|
|
// invite
|
|
CreateInvite(http.ResponseWriter, *http.Request)
|
|
AcceptInvite(http.ResponseWriter, *http.Request)
|
|
GetInvite(http.ResponseWriter, *http.Request) // public function
|
|
ListInvite(http.ResponseWriter, *http.Request)
|
|
DeleteInvite(http.ResponseWriter, *http.Request)
|
|
CreateBulkInvite(http.ResponseWriter, *http.Request)
|
|
|
|
ListUsers(http.ResponseWriter, *http.Request)
|
|
UpdateUser(http.ResponseWriter, *http.Request)
|
|
DeleteUser(http.ResponseWriter, *http.Request)
|
|
GetUser(http.ResponseWriter, *http.Request)
|
|
GetMyUser(http.ResponseWriter, *http.Request)
|
|
|
|
// Reset Password
|
|
GetResetPasswordToken(http.ResponseWriter, *http.Request)
|
|
ResetPassword(http.ResponseWriter, *http.Request)
|
|
ChangePassword(http.ResponseWriter, *http.Request)
|
|
ForgotPassword(http.ResponseWriter, *http.Request)
|
|
|
|
// API KEY
|
|
CreateAPIKey(http.ResponseWriter, *http.Request)
|
|
ListAPIKeys(http.ResponseWriter, *http.Request)
|
|
UpdateAPIKey(http.ResponseWriter, *http.Request)
|
|
RevokeAPIKey(http.ResponseWriter, *http.Request)
|
|
}
|