Skip to content

Commit

Permalink
Fixed issue with update user state (#4164)
Browse files Browse the repository at this point in the history
* Fixed issue with mongo watch events to add image registry on project creation

Signed-off-by: Saranya-jena <[email protected]>

* Fixed imports

Signed-off-by: Saranya-jena <[email protected]>

* resolved comments

Signed-off-by: Saranya-jena <[email protected]>

* fixed imports

Signed-off-by: Saranya-jena <[email protected]>

* Updated  project schema fields to fix deactivate user api

Signed-off-by: Saranya-jena <[email protected]>

---------

Signed-off-by: Saranya-jena <[email protected]>
  • Loading branch information
Saranya-jena committed Sep 13, 2023
1 parent a64d321 commit 7bcbd7c
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 21 deletions.
15 changes: 8 additions & 7 deletions chaoscenter/authentication/pkg/entities/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ type ProjectStats struct {

// Member contains the required fields to be stored in the database for a member
type Member struct {
UserID string `bson:"user_id" json:"userID"`
Username string `bson:"username" json:"username"`
Email string `bson:"email" json:"email"`
Name string `bson:"name" json:"name"`
Role MemberRole `bson:"role" json:"role"`
Invitation Invitation `bson:"invitation" json:"invitation"`
JoinedAt int64 `bson:"joined_at" json:"joinedAt"`
UserID string `bson:"user_id" json:"userID"`
Username string `bson:"username" json:"username"`
Email string `bson:"email" json:"email"`
Name string `bson:"name" json:"name"`
Role MemberRole `bson:"role" json:"role"`
Invitation Invitation `bson:"invitation" json:"invitation"`
JoinedAt int64 `bson:"joined_at" json:"joinedAt"`
DeactivatedAt *int64 `bson:"deactivated_at,omitempty" json:"deactivatedAt,omitempty"`
}

type Members struct {
Expand Down
6 changes: 3 additions & 3 deletions chaoscenter/authentication/pkg/project/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Repository interface {
UpdateInvite(projectID string, userID string, invitation entities.Invitation, role *entities.MemberRole) error
UpdateProjectName(projectID string, projectName string) error
GetAggregateProjects(pipeline mongo.Pipeline, opts *options.AggregateOptions) (*mongo.Cursor, error)
UpdateProjectState(userID string, deactivateTime string) error
UpdateProjectState(userID string, deactivateTime int64, isDeactivate bool) error
GetOwnerProjects(ctx context.Context, userID string) ([]*entities.Project, error)
GetProjectRole(projectID string, userID string) (*entities.MemberRole, error)
GetProjectMembers(projectID string, state string) ([]*entities.Member, error)
Expand Down Expand Up @@ -288,7 +288,7 @@ func (r repository) GetAggregateProjects(pipeline mongo.Pipeline, opts *options.
}

// UpdateProjectState updates the deactivated_at state of the member and removed_at field of the project
func (r repository) UpdateProjectState(userID string, deactivateTime string) error {
func (r repository) UpdateProjectState(userID string, deactivateTime int64, isDeactivate bool) error {
opts := options.Update().SetArrayFilters(options.ArrayFilters{
Filters: []interface{}{
bson.D{{"elem.user_id", userID}},
Expand Down Expand Up @@ -320,7 +320,7 @@ func (r repository) UpdateProjectState(userID string, deactivateTime string) err

update = bson.D{
{"$set", bson.D{
{"removed_at", deactivateTime},
{"is_removed", isDeactivate},
}},
}

Expand Down
6 changes: 3 additions & 3 deletions chaoscenter/authentication/pkg/services/project_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type projectService interface {
UpdateInvite(projectID string, userID string, invitation entities.Invitation, role *entities.MemberRole) error
UpdateProjectName(projectID string, projectName string) error
GetAggregateProjects(pipeline mongo.Pipeline, opts *options.AggregateOptions) (*mongo.Cursor, error)
UpdateProjectState(userID string, deactivateTime string) error
UpdateProjectState(userID string, deactivateTime int64, isDeactivate bool) error
GetOwnerProjectIDs(ctx context.Context, userID string) ([]*entities.Project, error)
GetProjectRole(projectID string, userID string) (*entities.MemberRole, error)
GetProjectMembers(projectID string, state string) ([]*entities.Member, error)
Expand Down Expand Up @@ -68,8 +68,8 @@ func (a applicationService) GetAggregateProjects(pipeline mongo.Pipeline, opts *
return a.projectRepository.GetAggregateProjects(pipeline, opts)
}

func (a applicationService) UpdateProjectState(userID string, deactivateTime string) error {
return a.projectRepository.UpdateProjectState(userID, deactivateTime)
func (a applicationService) UpdateProjectState(userID string, deactivateTime int64, isDeactivate bool) error {
return a.projectRepository.UpdateProjectState(userID, deactivateTime, isDeactivate)
}
func (a applicationService) GetOwnerProjectIDs(ctx context.Context, userID string) ([]*entities.Project, error) {
return a.projectRepository.GetOwnerProjects(ctx, userID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package services

import (
"context"
"strconv"
"time"

"github.com/litmuschaos/litmus/chaoscenter/authentication/pkg/entities"
Expand Down Expand Up @@ -37,10 +36,10 @@ func (a applicationService) UpdateStateTransaction(userRequest entities.UpdateUs
return utils.ErrUpdatingAdmin
}

var deactivateTime string
var deactivateTime int64

if *userRequest.IsDeactivate {
deactivateTime = strconv.FormatInt(time.Now().Unix(), 10)
deactivateTime = time.Now().UnixMilli()

// Checking if user is already deactivated
if user.DeactivatedAt != nil {
Expand All @@ -55,7 +54,7 @@ func (a applicationService) UpdateStateTransaction(userRequest entities.UpdateUs
return utils.ErrServerError
}
// Updating details in project collection
err = a.UpdateProjectState(user.ID, deactivateTime)
err = a.UpdateProjectState(user.ID, deactivateTime, *userRequest.IsDeactivate)
if err != nil {
log.Info(err)
return utils.ErrServerError
Expand Down
4 changes: 2 additions & 2 deletions chaoscenter/authentication/pkg/services/user_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type userService interface {
CreateUser(user *entities.User) (*entities.User, error)
UpdateUser(user *entities.UserDetails) error
IsAdministrator(user *entities.User) error
UpdateUserState(username string, isDeactivate bool, deactivateTime string) error
UpdateUserState(username string, isDeactivate bool, deactivateTime int64) error
InviteUsers(invitedUsers []string) (*[]entities.User, error)
}

Expand Down Expand Up @@ -71,7 +71,7 @@ func (a applicationService) IsAdministrator(user *entities.User) error {
}

// UpdateUserState updates deactivated_at state of the user
func (a applicationService) UpdateUserState(username string, isDeactivate bool, deactivateTime string) error {
func (a applicationService) UpdateUserState(username string, isDeactivate bool, deactivateTime int64) error {
return a.userRepository.UpdateUserState(username, isDeactivate, deactivateTime)
}

Expand Down
4 changes: 2 additions & 2 deletions chaoscenter/authentication/pkg/user/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Repository interface {
CreateUser(user *entities.User) (*entities.User, error)
UpdateUser(user *entities.UserDetails) error
IsAdministrator(user *entities.User) error
UpdateUserState(username string, isDeactivate bool, deactivateTime string) error
UpdateUserState(username string, isDeactivate bool, deactivateTime int64) error
InviteUsers(invitedUsers []string) (*[]entities.User, error)
}

Expand Down Expand Up @@ -231,7 +231,7 @@ func (r repository) IsAdministrator(user *entities.User) error {
}

// UpdateUserState updates the deactivated_at state of the user
func (r repository) UpdateUserState(username string, isDeactivate bool, deactivateTime string) error {
func (r repository) UpdateUserState(username string, isDeactivate bool, deactivateTime int64) error {
var err error
if isDeactivate {
_, err = r.Collection.UpdateOne(context.Background(), bson.M{"username": username}, bson.M{"$set": bson.M{
Expand Down

0 comments on commit 7bcbd7c

Please sign in to comment.