this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix(users): send LoginStuck or PendingSignup events to the relevant admins [ci release]

+55
+55
users.go
··· 48 48 return receiversForShotgunOpens(message) 49 49 case EventShotgunClosesSoon: 50 50 return receiversForShotgunCloses(message) 51 + case EventLoginStuck, EventPendingSignup: 52 + return receiversForUserCandidate(message) 51 53 case EventTest: 52 54 return []string{}, fmt.Errorf("test event is for subscriptions, not users") 53 55 } ··· 287 289 288 290 return 289 291 } 292 + 293 + func receiversForUserCandidate(message Message) (userIds []string, err error) { 294 + // Find school of the user candidate or user 295 + school, err := prisma.School.FindFirst( 296 + db.School.Majors.Some( 297 + db.Major.Or( 298 + db.Major.Students.Some(db.User.ID.Equals(message.ChurrosObjectId)), 299 + db.Major.UserCandidates.Some(db.UserCandidate.ID.Equals(message.ChurrosObjectId)), 300 + ), 301 + ), 302 + ).Exec(context.Background()) 303 + 304 + if err != nil { 305 + return []string{}, fmt.Errorf("while getting school of user or usercandidate %s: %w", message.ChurrosObjectId, err) 306 + } 307 + 308 + systemAdmins, err := prisma.User.FindMany( 309 + db.User.Admin.Equals(true), 310 + ).Select( 311 + db.User.ID.Field(), 312 + ).Exec(context.Background()) 313 + 314 + if err != nil { 315 + return []string{}, fmt.Errorf("while getting system admins: %w", err) 316 + } 317 + 318 + // If external account, send to system admins 319 + if school == nil { 320 + for _, admin := range systemAdmins { 321 + userIds = append(userIds, admin.ID) 322 + } 323 + return 324 + } 325 + 326 + // If user or candidate has a school, get student association admins for that school 327 + studentAssociationAdmins, err := prisma.User.FindMany( 328 + db.User.AdminOfStudentAssociations.Some( 329 + db.StudentAssociation.SchoolID.Equals(school.ID), 330 + ), 331 + ).Select( 332 + db.User.ID.Field(), 333 + ).Exec(context.Background()) 334 + 335 + if err != nil { 336 + return []string{}, fmt.Errorf("while getting student association admins for %+v: %w", school, err) 337 + } 338 + 339 + for _, admin := range studentAssociationAdmins { 340 + userIds = append(userIds, admin.ID) 341 + } 342 + 343 + return 344 + }