Skip to content

Commit

Permalink
fix: the user is not correctly considered as active (#280)
Browse files Browse the repository at this point in the history
**Relative Issues:** Resolve #279 

**Describe the pull request**
One column on the model user called `is_a_user` must be set as true when
an User takes the action to join the app. But actually, the number of
active users seems to lower. This PR fix this issue

**Checklist**

- [x] I have linked the relative issue to this pull request
- [x] I have made the modifications or added tests related to my PR
- [x] I have added/updated the documentation for my RP
- [x] I put my PR in Ready for Review only when all the checklist is
checked

**Breaking changes ?**
no

**Additional context**
A manual migration in the database will be perfromed to set all user
with duo account linked as active.
  • Loading branch information
42atomys authored Nov 28, 2022
1 parent c5a858a commit d5c41d1
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions internal/api/account_callbacks.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,31 @@ func accountLinkCallback(ctx context.Context, db *modelgen.Client, account *mode
case string(typesgen.ProviderGithub):
githubLinkCallback(bgCtx, db, account)
case string(typesgen.ProviderDuo):
break
duoLinkCallback(bgCtx, db, account)
default:
log.Warn().Str("accountType", account.Type).Msg("no callback is defined")
}
}

// duoLinkCallback is the callback for 42 (DUO) accounts when the account is
// linked to an user. Only happened when an User will connect itself for the
// first time
func duoLinkCallback(ctx context.Context, db *modelgen.Client, account *modelgen.Account) {
user, err := account.User(ctx)
if err != nil {
log.Error().Err(err).Msg("failed to retrieve user")
sentry.CaptureException(err)
return
}

if err := db.User.UpdateOne(user).SetIsAUser(true).Exec(ctx); err != nil {
log.Error().Err(err).Msg("failed to update user")
sentry.CaptureException(err)
}
}

// discordLinkCallback is the callback for Discord accounts when the account is
// linked to a user. It will add the user to the Discord server.
// linked to an user. It will add the user to the Discord server.
func discordLinkCallback(ctx context.Context, db *modelgen.Client, account *modelgen.Account) {
// Invite the user to the S42 server using the Discord API
err := discord.
Expand All @@ -54,7 +71,7 @@ func discordLinkCallback(ctx context.Context, db *modelgen.Client, account *mode
}

// githubLinkCallback is the callback for Github accounts when the account is
// linked to a user. It will follow the creator of the repository and star
// linked to an user. It will follow the creator of the repository and star
// the repository.
func githubLinkCallback(ctx context.Context, db *modelgen.Client, account *modelgen.Account) {
client := github.NewClient(oauth2.NewClient(ctx, oauth2.StaticTokenSource(
Expand Down

0 comments on commit d5c41d1

Please sign in to comment.