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
Showing only changes of commit a7c1fb919c - Show all commits

View File

@ -82,7 +82,7 @@ type TeamMember struct {
}
// TableName makes beautiful table names
func (TeamMember) TableName() string {
func (*TeamMember) TableName() string {
viehlieb marked this conversation as resolved Outdated

Why did you change this?

Why did you change this?

oha.
this was unintended.

oha. this was unintended.
return "team_members"
}
@ -94,6 +94,7 @@ type TeamUser struct {
TeamID int64 `json:"-"`
}
// TeamData is the relevant data for a team and is delivered by oidc token
viehlieb marked this conversation as resolved Outdated

What is this used for? Please add a comment.

What is this used for? Please add a comment.

What's the difference to the Team struct?

What's the difference to the `Team` struct?

Intermediate struct which only holds TeamName and OidcId Description.
It does not exist as a Team yet or better: it is the data accessible via oidc, which the Team struct is compared against.

Intermediate struct which only holds TeamName and OidcId Description. It does not exist as a Team yet or better: it is the data accessible via oidc, which the Team struct is compared against.

Okay, but isn't it missing the json tags then? I'm not sure if I understood you correctly herre.

If it's only used for oidc data the name should reflect that. TeamData is too generic.

Okay, but isn't it missing the json tags then? I'm not sure if I understood you correctly herre. If it's only used for oidc data the name should reflect that. `TeamData` is too generic.

No, the teamData has to be pulled out of token via

getTeamDataFromToken

Called it OIDCTeamData now.

No, the teamData has to be pulled out of token via `getTeamDataFromToken` Called it OIDCTeamData now.
type TeamData struct {
TeamName string
OidcID string
@ -166,7 +167,7 @@ func FindAllOidcTeamIDsForUser(s *xorm.Session, userID int64) (ts []int64, err e
Table("team_members").
Where("user_id = ? ", userID).
Join("RIGHT", "teams", "teams.id = team_members.team_id").
viehlieb marked this conversation as resolved Outdated

Can teams.oidc_id be null? Then you should check that as well.

Can `teams.oidc_id` be null? Then you should check that as well.
Where("teams.oidc_id != ?", "").
Where("teams.oidc_id != ? AND teams.oidc_id IS NOT NULL", "").
Cols("teams.id").
Find(&ts)
if ts == nil || err != nil {
@ -325,8 +326,7 @@ func (t *Team) Create(s *xorm.Session, a web.Auth) (err error) {
return
}
var admin = true
tm := TeamMember{TeamID: t.ID, Username: doer.Username, Admin: admin}
tm := TeamMember{TeamID: t.ID, Username: doer.Username, Admin: true}
viehlieb marked this conversation as resolved Outdated

Why the extra variable?

Why the extra variable?

manageAdmin func and this var are deleted from code, since not needed

manageAdmin func and this var are deleted from code, since not needed

manageAdmin func and this var are deleted from code, since not needed

manageAdmin func and this var are deleted from code, since not needed
if err = tm.Create(s, doer); err != nil {
return err
}
@ -337,11 +337,6 @@ func (t *Team) Create(s *xorm.Session, a web.Auth) (err error) {
})
}
func (t *Team) ManageAdminRight(teamMember TeamMember, admin bool) {
// Insert the current user as member and admin
teamMember.Admin = admin
}
// Delete deletes a team
// @Summary Deletes a team
viehlieb marked this conversation as resolved Outdated

That's not what the function seems to be doing. Please change the name or comment.

That's not what the function seems to be doing. Please change the name or comment.
// @Description Delets a team. This will also remove the access for all users in that team.