feat: assign users to teams via OIDC claims #1393

Merged
konrad merged 93 commits from viehlieb/api:950_reworked_assign_teams_via_oidc into main 2024-03-02 08:47:12 +00:00
2 changed files with 8 additions and 7 deletions
Showing only changes of commit 6bd5efa00b - Show all commits

View File

@ -115,13 +115,13 @@ func (tm *TeamMember) CheckMembership(s *xorm.Session) (exists bool, err error)
return exists, err
}
func (tm *TeamMember) GetMemberCount(s *xorm.Session) (memberCount int, err error) {
members := []TeamMember{}
err = s.
func (tm *TeamMember) GetMemberCount(s *xorm.Session) (memberCount int64, err error) {
member := TeamMember{}
memberCount, err = s.
viehlieb marked this conversation as resolved Outdated

Couldn't you just return the result here directly?

Couldn't you just return the result here directly?

In fact this function is not needed anymore for this feature, so I'll just remove it.
It was used for finding out whether a user should be signed out from team or deleted.

In fact this function is not needed anymore for this feature, so I'll just remove it. It was used for finding out whether a user should be signed out from team or deleted.
Where("team_id = ?", tm.TeamID).
Cols("user_id").
Find(&members)
return len(members), err
Count(&member)
viehlieb marked this conversation as resolved Outdated

If it's only counting, please use Count().

If it's only counting, please use `Count()`.

done

done
return memberCount, err
}
// Update toggles a team member's admin status

View File

@ -216,7 +216,8 @@ func HandleCallback(c echo.Context) error {
if err != nil {
viehlieb marked this conversation as resolved Outdated

Please don't ignore the error.

Please don't ignore the error.
log.Errorf("Could not proceed with group routine %v", err)
}
viehlieb marked this conversation as resolved Outdated

Please don't call this "Sign out". That's a different thing.

Please don't call this "Sign out". That's a different thing.
errs = SignOutFromOrDeleteTeamsByID(s, u, utils.NotIn(oldOidcTeams, oidcTeams))
errs = SignOutFromTeamsByID(s, u, utils.NotIn(oldOidcTeams, oidcTeams))
log.Errorf("%v", errs)
for _, err := range errs {
log.Errorf("Found Error while signing out from teams %v", err)
}
@ -293,7 +294,7 @@ func RemoveUserFromTeamsByIds(s *xorm.Session, u *user.User, teamIDs []int64) (e
if !exists {
continue
}
err := tm.Delete(s, u)
err = tm.Delete(s, u)
// if you cannot delete the team_member
if err != nil {
errs = append(errs, err)
viehlieb marked this conversation as resolved Outdated

The return here will mean if one team claim is invalid, it will not try to validate any others. Is that what you intended?

The return here will mean if one team claim is invalid, it will not try to validate any others. Is that what you intended?

changed behaviour to skipping the invalid team

changed behaviour to skipping the invalid team