Compare commits
2 Commits
refactor/g
...
famfix
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
daa09136ef | ||
|
|
82ebcf66a5 |
@@ -1,2 +1,2 @@
|
||||
ALTER TABLE families
|
||||
ADD COLUMN storage_limit BIGINT;
|
||||
ADD COLUMN storage_limit BIGINT NULL;
|
||||
@@ -42,7 +42,7 @@ func (h *FamilyHandler) InviteMember(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err := h.Controller.InviteMember(c, auth.GetUserID(c.Request.Header), request.Email, request.StorageLimit)
|
||||
err := h.Controller.InviteMember(c, auth.GetUserID(c.Request.Header), request.Email)
|
||||
if err != nil {
|
||||
handler.Error(c, stacktrace.Propagate(err, ""))
|
||||
return
|
||||
|
||||
@@ -57,7 +57,7 @@ func (c *Controller) CreateFamily(ctx context.Context, adminUserID int64) error
|
||||
}
|
||||
|
||||
// InviteMember invites a user to join the family plan of admin User
|
||||
func (c *Controller) InviteMember(ctx *gin.Context, adminUserID int64, email string, storageLimit *int64) error {
|
||||
func (c *Controller) InviteMember(ctx *gin.Context, adminUserID int64, email string) error {
|
||||
err := c.BillingCtrl.IsActivePayingSubscriber(adminUserID)
|
||||
if err != nil {
|
||||
return stacktrace.Propagate(ente.ErrNoActiveSubscription, "you must be on a paid plan")
|
||||
@@ -114,7 +114,7 @@ func (c *Controller) InviteMember(ctx *gin.Context, adminUserID int64, email str
|
||||
return stacktrace.Propagate(err, "")
|
||||
}
|
||||
|
||||
activeInviteToken, err := c.FamilyRepo.AddMemberInvite(ctx, adminUserID, potentialMemberUser.ID, inviteToken, storageLimit)
|
||||
activeInviteToken, err := c.FamilyRepo.AddMemberInvite(ctx, adminUserID, potentialMemberUser.ID, inviteToken)
|
||||
if err != nil {
|
||||
return stacktrace.Propagate(err, "")
|
||||
}
|
||||
@@ -232,7 +232,7 @@ func (c *Controller) ModifyMemberStorage(ctx context.Context, actorUserID int64,
|
||||
}
|
||||
}
|
||||
|
||||
modifyStorageErr := c.FamilyRepo.ModifyMemberStorage(ctx, actorUserID, member.ID, storageLimit)
|
||||
modifyStorageErr := c.FamilyRepo.ModifyMemberStorage(ctx, member.ID, storageLimit)
|
||||
if modifyStorageErr != nil {
|
||||
return stacktrace.Propagate(modifyStorageErr, "Failed to modify members storage")
|
||||
}
|
||||
|
||||
@@ -90,16 +90,16 @@ func (repo *FamilyRepository) CloseFamily(ctx context.Context, adminID int64) er
|
||||
|
||||
// AddMemberInvite inserts a family invitation entry for this given pair of admin & member and return the active inviteToken
|
||||
// which can be used to accept the invite
|
||||
func (repo *FamilyRepository) AddMemberInvite(ctx context.Context, adminID int64, memberID int64, inviteToken string, storageLimit *int64) (string, error) {
|
||||
func (repo *FamilyRepository) AddMemberInvite(ctx context.Context, adminID int64, memberID int64, inviteToken string) (string, error) {
|
||||
if adminID == memberID {
|
||||
return "", stacktrace.Propagate(errors.New("memberID and adminID can not be same"), "")
|
||||
}
|
||||
// on conflict, we should not change the status from 'ACCEPTED' to `INVITED`.
|
||||
// Also, the token should not be updated if the user is already in `INVITED` state.
|
||||
_, err := repo.DB.ExecContext(ctx, `INSERT INTO families(id, admin_id, member_id, status, token, storage_limit)
|
||||
VALUES($1, $2, $3, $4, $5, $6) ON CONFLICT (admin_id,member_id)
|
||||
DO UPDATE SET(status, token) = ($4, $5) WHERE NOT (families.status = ANY($7))`,
|
||||
uuid.New(), adminID, memberID, ente.INVITED, inviteToken, storageLimit, pq.Array([]ente.MemberStatus{ente.INVITED, ente.ACCEPTED}))
|
||||
_, err := repo.DB.ExecContext(ctx, `INSERT INTO families(id, admin_id, member_id, status, token)
|
||||
VALUES($1, $2, $3, $4, $5) ON CONFLICT (admin_id,member_id)
|
||||
DO UPDATE SET(status, token) = ($4, $5) WHERE NOT (families.status = ANY($6))`,
|
||||
uuid.New(), adminID, memberID, ente.INVITED, inviteToken, pq.Array([]ente.MemberStatus{ente.INVITED, ente.ACCEPTED}))
|
||||
if err != nil {
|
||||
return "", stacktrace.Propagate(err, "")
|
||||
}
|
||||
@@ -197,7 +197,7 @@ func (repo *FamilyRepository) RemoveMember(ctx context.Context, adminID int64, m
|
||||
}
|
||||
|
||||
// UpdateStorage is used to set Pre-existing Members Storage Limit.
|
||||
func (repo *FamilyRepository) ModifyMemberStorage(ctx context.Context, adminID int64, id uuid.UUID, storageLimit *int64) error {
|
||||
func (repo *FamilyRepository) ModifyMemberStorage(ctx context.Context, id uuid.UUID, storageLimit *int64) error {
|
||||
_, err := repo.DB.Exec(`UPDATE families SET storage_limit=$1 where id=$2`, storageLimit, id)
|
||||
if err != nil {
|
||||
return stacktrace.Propagate(err, "Could not update Members Storage Limit")
|
||||
|
||||
Reference in New Issue
Block a user