| 1 | package store |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "database/sql" |
| 6 | "errors" |
| 7 | ) |
| 8 | |
| 9 | // Oficina ID links are connect's rows (home_identity_links). connect checks |
| 10 | // them, and Base reads and removes them only as connect asks an app to: |
| 11 | // removing a member removes their links (RemoveMember), and a link connect |
| 12 | // no longer resolves is removed before the member links again |
| 13 | // (web.oficina.dropDeadLink). Nothing here writes one. |
| 14 | |
| 15 | // OficinaLinkSubject is the Oficina account (subject at issuer) linked to |
| 16 | // member number n; ok is false when there is none. |
| 17 | func OficinaLinkSubject(ctx context.Context, q QueryRower, issuer string, n int64) (subject string, ok bool, err error) { |
| 18 | err = q.QueryRowContext(ctx, `SELECT subject FROM home_identity_links WHERE issuer = ? AND person_id = ?`, issuer, n).Scan(&subject) |
| 19 | if errors.Is(err, sql.ErrNoRows) { |
| 20 | return "", false, nil |
| 21 | } |
| 22 | return subject, err == nil, err |
| 23 | } |
| 24 | |
| 25 | // DeleteOficinaLink removes the link between subject at issuer and member |
| 26 | // number n, if it is still that link. |
| 27 | func DeleteOficinaLink(ctx context.Context, tx *sql.Tx, issuer, subject string, n int64) error { |
| 28 | _, err := tx.ExecContext(ctx, `DELETE FROM home_identity_links WHERE issuer = ? AND subject = ? AND person_id = ?`, issuer, subject, n) |
| 29 | return err |
| 30 | } |
| 31 | |