From 18cb4a37ddc239a63f0bdbb2ca0ad26dc7a5c6c4 Mon Sep 17 00:00:00 2001 From: Seongmin Lee Date: Sun, 25 Jan 2026 23:30:30 +0900 Subject: [PATCH] appview: remove `oauth.User` type This is not required anymore. `MultiAccountUser` can just hold active user DID. Signed-off-by: Seongmin Lee --- appview/issues/issues.go | 38 +++++++------- appview/knots/knots.go | 48 +++++++++--------- appview/labels/labels.go | 2 +- appview/middleware/middleware.go | 8 +-- appview/notifications/notifications.go | 8 +-- appview/oauth/accounts.go | 10 +--- appview/oauth/oauth.go | 6 +-- appview/pulls/pulls.go | 44 ++++++++--------- appview/repo/artifact.go | 8 +-- appview/repo/repo.go | 42 ++++++++-------- appview/repo/settings.go | 2 +- appview/reporesolver/resolver.go | 4 +- appview/settings/settings.go | 4 +- appview/spindles/spindles.go | 68 +++++++++++++------------- appview/state/accounts.go | 2 +- appview/state/follow.go | 12 ++--- appview/state/login.go | 2 +- appview/state/profile.go | 58 +++++++++++----------- appview/state/reaction.go | 12 ++--- appview/state/star.go | 10 ++-- appview/state/state.go | 26 +++++----- appview/strings/strings.go | 24 ++++----- 22 files changed, 214 insertions(+), 224 deletions(-) diff --git a/appview/issues/issues.go b/appview/issues/issues.go index 9d35bb71..33687169 100644 --- a/appview/issues/issues.go +++ b/appview/issues/issues.go @@ -102,7 +102,7 @@ func (rp *Issues) RepoSingleIssue(w http.ResponseWriter, r *http.Request) { userReactions := map[models.ReactionKind]bool{} if user != nil { - userReactions = db.GetReactionStatusMap(rp.db, user.Active.Did, issue.AtUri()) + userReactions = db.GetReactionStatusMap(rp.db, user.Did, issue.AtUri()) } backlinks, err := db.GetBacklinks(rp.db, issue.AtUri()) @@ -181,7 +181,7 @@ func (rp *Issues) EditIssue(w http.ResponseWriter, r *http.Request) { return } - ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoIssueNSID, user.Active.Did, newIssue.Rkey) + ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoIssueNSID, user.Did, newIssue.Rkey) if err != nil { l.Error("failed to get record", "err", err) rp.pages.Notice(w, noticeId, "Failed to edit issue, no record found on PDS.") @@ -190,7 +190,7 @@ func (rp *Issues) EditIssue(w http.ResponseWriter, r *http.Request) { _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.RepoIssueNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: newIssue.Rkey, SwapRecord: ex.Cid, Record: &lexutil.LexiconTypeDecoder{ @@ -305,10 +305,10 @@ func (rp *Issues) CloseIssue(w http.ResponseWriter, r *http.Request) { return } - roles := repoinfo.RolesInRepo{Roles: rp.enforcer.GetPermissionsInRepo(user.Active.Did, f.Knot, f.DidSlashRepo())} + roles := repoinfo.RolesInRepo{Roles: rp.enforcer.GetPermissionsInRepo(user.Did, f.Knot, f.DidSlashRepo())} isRepoOwner := roles.IsOwner() isCollaborator := roles.IsCollaborator() - isIssueOwner := user.Active.Did == issue.Did + isIssueOwner := user.Did == issue.Did // TODO: make this more granular if isIssueOwner || isRepoOwner || isCollaborator { @@ -325,7 +325,7 @@ func (rp *Issues) CloseIssue(w http.ResponseWriter, r *http.Request) { issue.Open = false // notify about the issue closure - rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Active.Did), issue) + rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Did), issue) ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", ownerSlashRepo, issue.IssueId)) @@ -353,10 +353,10 @@ func (rp *Issues) ReopenIssue(w http.ResponseWriter, r *http.Request) { return } - roles := repoinfo.RolesInRepo{Roles: rp.enforcer.GetPermissionsInRepo(user.Active.Did, f.Knot, f.DidSlashRepo())} + roles := repoinfo.RolesInRepo{Roles: rp.enforcer.GetPermissionsInRepo(user.Did, f.Knot, f.DidSlashRepo())} isRepoOwner := roles.IsOwner() isCollaborator := roles.IsCollaborator() - isIssueOwner := user.Active.Did == issue.Did + isIssueOwner := user.Did == issue.Did if isCollaborator || isRepoOwner || isIssueOwner { err := db.ReopenIssues( @@ -372,7 +372,7 @@ func (rp *Issues) ReopenIssue(w http.ResponseWriter, r *http.Request) { issue.Open = true // notify about the issue reopen - rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Active.Did), issue) + rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Did), issue) ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", ownerSlashRepo, issue.IssueId)) @@ -415,7 +415,7 @@ func (rp *Issues) NewIssueComment(w http.ResponseWriter, r *http.Request) { mentions, references := rp.mentionsResolver.Resolve(r.Context(), body) comment := models.IssueComment{ - Did: user.Active.Did, + Did: user.Did, Rkey: tid.TID(), IssueAt: issue.AtUri().String(), ReplyTo: replyTo, @@ -556,8 +556,8 @@ func (rp *Issues) EditIssueComment(w http.ResponseWriter, r *http.Request) { } comment := comments[0] - if comment.Did != user.Active.Did { - l.Error("unauthorized comment edit", "expectedDid", comment.Did, "gotDid", user.Active.Did) + if comment.Did != user.Did { + l.Error("unauthorized comment edit", "expectedDid", comment.Did, "gotDid", user.Did) http.Error(w, "you are not the author of this comment", http.StatusUnauthorized) return } @@ -607,7 +607,7 @@ func (rp *Issues) EditIssueComment(w http.ResponseWriter, r *http.Request) { // rkey is optional, it was introduced later if newComment.Rkey != "" { // update the record on pds - ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoIssueCommentNSID, user.Active.Did, comment.Rkey) + ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoIssueCommentNSID, user.Did, comment.Rkey) if err != nil { l.Error("failed to get record", "err", err, "did", newComment.Did, "rkey", newComment.Rkey) rp.pages.Notice(w, fmt.Sprintf("comment-%s-status", commentId), "Failed to update description, no record found on PDS.") @@ -616,7 +616,7 @@ func (rp *Issues) EditIssueComment(w http.ResponseWriter, r *http.Request) { _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.RepoIssueCommentNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: newComment.Rkey, SwapRecord: ex.Cid, Record: &lexutil.LexiconTypeDecoder{ @@ -738,8 +738,8 @@ func (rp *Issues) DeleteIssueComment(w http.ResponseWriter, r *http.Request) { } comment := comments[0] - if comment.Did != user.Active.Did { - l.Error("unauthorized action", "expectedDid", comment.Did, "gotDid", user.Active.Did) + if comment.Did != user.Did { + l.Error("unauthorized action", "expectedDid", comment.Did, "gotDid", user.Did) http.Error(w, "you are not the author of this comment", http.StatusUnauthorized) return } @@ -768,7 +768,7 @@ func (rp *Issues) DeleteIssueComment(w http.ResponseWriter, r *http.Request) { } _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ Collection: tangled.RepoIssueCommentNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: comment.Rkey, }) if err != nil { @@ -920,7 +920,7 @@ func (rp *Issues) NewIssue(w http.ResponseWriter, r *http.Request) { Title: r.FormValue("title"), Body: body, Open: true, - Did: user.Active.Did, + Did: user.Did, Created: time.Now(), Mentions: mentions, References: references, @@ -944,7 +944,7 @@ func (rp *Issues) NewIssue(w http.ResponseWriter, r *http.Request) { } resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.RepoIssueNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: issue.Rkey, Record: &lexutil.LexiconTypeDecoder{ Val: &record, diff --git a/appview/knots/knots.go b/appview/knots/knots.go index 23a6ac50..de1b66c6 100644 --- a/appview/knots/knots.go +++ b/appview/knots/knots.go @@ -60,7 +60,7 @@ func (k *Knots) knots(w http.ResponseWriter, r *http.Request) { user := k.OAuth.GetMultiAccountUser(r) registrations, err := db.GetRegistrations( k.Db, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), ) if err != nil { k.Logger.Error("failed to fetch knot registrations", "err", err) @@ -78,7 +78,7 @@ func (k *Knots) dashboard(w http.ResponseWriter, r *http.Request) { l := k.Logger.With("handler", "dashboard") user := k.OAuth.GetMultiAccountUser(r) - l = l.With("user", user.Active.Did) + l = l.With("user", user.Did) domain := chi.URLParam(r, "domain") if domain == "" { @@ -88,7 +88,7 @@ func (k *Knots) dashboard(w http.ResponseWriter, r *http.Request) { registrations, err := db.GetRegistrations( k.Db, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("domain", domain), ) if err != nil { @@ -158,7 +158,7 @@ func (k *Knots) register(w http.ResponseWriter, r *http.Request) { return } l = l.With("domain", domain) - l = l.With("user", user.Active.Did) + l = l.With("user", user.Did) tx, err := k.Db.Begin() if err != nil { @@ -171,7 +171,7 @@ func (k *Knots) register(w http.ResponseWriter, r *http.Request) { k.Enforcer.E.LoadPolicy() }() - err = db.AddKnot(tx, domain, user.Active.Did) + err = db.AddKnot(tx, domain, user.Did) if err != nil { l.Error("failed to insert", "err", err) fail() @@ -193,7 +193,7 @@ func (k *Knots) register(w http.ResponseWriter, r *http.Request) { return } - ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.KnotNSID, user.Active.Did, domain) + ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.KnotNSID, user.Did, domain) var exCid *string if ex != nil { exCid = ex.Cid @@ -202,7 +202,7 @@ func (k *Knots) register(w http.ResponseWriter, r *http.Request) { // re-announce by registering under same rkey _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.KnotNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: domain, Record: &lexutil.LexiconTypeDecoder{ Val: &tangled.Knot{ @@ -233,14 +233,14 @@ func (k *Knots) register(w http.ResponseWriter, r *http.Request) { } // begin verification - err = serververify.RunVerification(r.Context(), domain, user.Active.Did, k.Config.Core.Dev) + err = serververify.RunVerification(r.Context(), domain, user.Did, k.Config.Core.Dev) if err != nil { l.Error("verification failed", "err", err) k.Pages.HxRefresh(w) return } - err = serververify.MarkKnotVerified(k.Db, k.Enforcer, domain, user.Active.Did) + err = serververify.MarkKnotVerified(k.Db, k.Enforcer, domain, user.Did) if err != nil { l.Error("failed to mark verified", "err", err) k.Pages.HxRefresh(w) @@ -277,7 +277,7 @@ func (k *Knots) delete(w http.ResponseWriter, r *http.Request) { // get record from db first registrations, err := db.GetRegistrations( k.Db, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("domain", domain), ) if err != nil { @@ -305,7 +305,7 @@ func (k *Knots) delete(w http.ResponseWriter, r *http.Request) { err = db.DeleteKnot( tx, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("domain", domain), ) if err != nil { @@ -333,7 +333,7 @@ func (k *Knots) delete(w http.ResponseWriter, r *http.Request) { _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ Collection: tangled.KnotNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: domain, }) if err != nil { @@ -381,12 +381,12 @@ func (k *Knots) retry(w http.ResponseWriter, r *http.Request) { return } l = l.With("domain", domain) - l = l.With("user", user.Active.Did) + l = l.With("user", user.Did) // get record from db first registrations, err := db.GetRegistrations( k.Db, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("domain", domain), ) if err != nil { @@ -402,7 +402,7 @@ func (k *Knots) retry(w http.ResponseWriter, r *http.Request) { registration := registrations[0] // begin verification - err = serververify.RunVerification(r.Context(), domain, user.Active.Did, k.Config.Core.Dev) + err = serververify.RunVerification(r.Context(), domain, user.Did, k.Config.Core.Dev) if err != nil { l.Error("verification failed", "err", err) @@ -420,7 +420,7 @@ func (k *Knots) retry(w http.ResponseWriter, r *http.Request) { return } - err = serververify.MarkKnotVerified(k.Db, k.Enforcer, domain, user.Active.Did) + err = serververify.MarkKnotVerified(k.Db, k.Enforcer, domain, user.Did) if err != nil { l.Error("failed to mark verified", "err", err) k.Pages.Notice(w, noticeId, err.Error()) @@ -439,7 +439,7 @@ func (k *Knots) retry(w http.ResponseWriter, r *http.Request) { return } - ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.KnotNSID, user.Active.Did, domain) + ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.KnotNSID, user.Did, domain) var exCid *string if ex != nil { exCid = ex.Cid @@ -448,7 +448,7 @@ func (k *Knots) retry(w http.ResponseWriter, r *http.Request) { // ignore the error here _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.KnotNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: domain, Record: &lexutil.LexiconTypeDecoder{ Val: &tangled.Knot{ @@ -477,7 +477,7 @@ func (k *Knots) retry(w http.ResponseWriter, r *http.Request) { // Get updated registration to show registrations, err = db.GetRegistrations( k.Db, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("domain", domain), ) if err != nil { @@ -509,11 +509,11 @@ func (k *Knots) addMember(w http.ResponseWriter, r *http.Request) { return } l = l.With("domain", domain) - l = l.With("user", user.Active.Did) + l = l.With("user", user.Did) registrations, err := db.GetRegistrations( k.Db, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("domain", domain), orm.FilterIsNot("registered", "null"), ) @@ -566,7 +566,7 @@ func (k *Knots) addMember(w http.ResponseWriter, r *http.Request) { _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.KnotMemberNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: rkey, Record: &lexutil.LexiconTypeDecoder{ Val: &tangled.KnotMember{ @@ -617,11 +617,11 @@ func (k *Knots) removeMember(w http.ResponseWriter, r *http.Request) { return } l = l.With("domain", domain) - l = l.With("user", user.Active.Did) + l = l.With("user", user.Did) registrations, err := db.GetRegistrations( k.Db, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("domain", domain), orm.FilterIsNot("registered", "null"), ) diff --git a/appview/labels/labels.go b/appview/labels/labels.go index 7aea6e6a..3f5f1bdc 100644 --- a/appview/labels/labels.go +++ b/appview/labels/labels.go @@ -82,7 +82,7 @@ func (l *Labels) PerformLabelOp(w http.ResponseWriter, r *http.Request) { return } - did := user.Active.Did + did := user.Did rkey := tid.TID() performedAt := time.Now() indexedAt := time.Now() diff --git a/appview/middleware/middleware.go b/appview/middleware/middleware.go index 46e0f307..de7d5adb 100644 --- a/appview/middleware/middleware.go +++ b/appview/middleware/middleware.go @@ -128,9 +128,9 @@ func (mw Middleware) knotRoleMiddleware(group string) middlewareFunc { return } - ok, err := mw.enforcer.E.HasGroupingPolicy(actor.Active.Did, group, domain) + ok, err := mw.enforcer.E.HasGroupingPolicy(actor.Did, group, domain) if err != nil || !ok { - log.Printf("%s does not have perms of a %s in domain %s", actor.Active.Did, group, domain) + log.Printf("%s does not have perms of a %s in domain %s", actor.Did, group, domain) http.Error(w, "Forbiden", http.StatusUnauthorized) return } @@ -161,9 +161,9 @@ func (mw Middleware) RepoPermissionMiddleware(requiredPerm string) middlewareFun return } - ok, err := mw.enforcer.E.Enforce(actor.Active.Did, f.Knot, f.DidSlashRepo(), requiredPerm) + ok, err := mw.enforcer.E.Enforce(actor.Did, f.Knot, f.DidSlashRepo(), requiredPerm) if err != nil || !ok { - log.Printf("%s does not have perms of a %s in repo %s", actor.Active.Did, requiredPerm, f.DidSlashRepo()) + log.Printf("%s does not have perms of a %s in repo %s", actor.Did, requiredPerm, f.DidSlashRepo()) http.Error(w, "Forbiden", http.StatusUnauthorized) return } diff --git a/appview/notifications/notifications.go b/appview/notifications/notifications.go index 2a63c87a..3cda6baa 100644 --- a/appview/notifications/notifications.go +++ b/appview/notifications/notifications.go @@ -54,7 +54,7 @@ func (n *Notifications) notificationsPage(w http.ResponseWriter, r *http.Request total, err := db.CountNotifications( n.db, - orm.FilterEq("recipient_did", user.Active.Did), + orm.FilterEq("recipient_did", user.Did), ) if err != nil { l.Error("failed to get total notifications", "err", err) @@ -65,7 +65,7 @@ func (n *Notifications) notificationsPage(w http.ResponseWriter, r *http.Request notifications, err := db.GetNotificationsWithEntities( n.db, page, - orm.FilterEq("recipient_did", user.Active.Did), + orm.FilterEq("recipient_did", user.Did), ) if err != nil { l.Error("failed to get notifications", "err", err) @@ -73,7 +73,7 @@ func (n *Notifications) notificationsPage(w http.ResponseWriter, r *http.Request return } - err = db.MarkAllNotificationsRead(n.db, user.Active.Did) + err = db.MarkAllNotificationsRead(n.db, user.Did) if err != nil { l.Error("failed to mark notifications as read", "err", err) } @@ -98,7 +98,7 @@ func (n *Notifications) getUnreadCount(w http.ResponseWriter, r *http.Request) { count, err := db.CountNotifications( n.db, - orm.FilterEq("recipient_did", user.Active.Did), + orm.FilterEq("recipient_did", user.Did), orm.FilterEq("read", 0), ) if err != nil { diff --git a/appview/oauth/accounts.go b/appview/oauth/accounts.go index fd1e1b80..dcc6269f 100644 --- a/appview/oauth/accounts.go +++ b/appview/oauth/accounts.go @@ -22,14 +22,10 @@ type AccountRegistry struct { } type MultiAccountUser struct { - Active User + Did string Accounts []AccountInfo } -func (m *MultiAccountUser) Did() string { - return m.Active.Did -} - func (o *OAuth) GetAccounts(r *http.Request) *AccountRegistry { session, err := o.SessStore.Get(r, AccountsName) if err != nil || session.IsNew { @@ -116,9 +112,7 @@ func (o *OAuth) GetMultiAccountUser(r *http.Request) *MultiAccountUser { registry := o.GetAccounts(r) return &MultiAccountUser{ - Active: User{ - Did: sess.Data.AccountDID.String(), - }, + Did: sess.Data.AccountDID.String(), Accounts: registry.Accounts, } } diff --git a/appview/oauth/oauth.go b/appview/oauth/oauth.go index ffbdc029..9f25ad36 100644 --- a/appview/oauth/oauth.go +++ b/appview/oauth/oauth.go @@ -231,13 +231,9 @@ func (o *OAuth) RemoveAccount(w http.ResponseWriter, r *http.Request, targetDid return o.saveAccounts(w, r, registry) } -type User struct { - Did string -} - func (o *OAuth) GetDid(r *http.Request) string { if u := o.GetMultiAccountUser(r); u != nil { - return u.Did() + return u.Did } return "" diff --git a/appview/pulls/pulls.go b/appview/pulls/pulls.go index c308da4f..c0f260af 100644 --- a/appview/pulls/pulls.go +++ b/appview/pulls/pulls.go @@ -128,7 +128,7 @@ func (s *Pulls) PullActions(w http.ResponseWriter, r *http.Request) { mergeCheckResponse := s.mergeCheck(r, f, pull, stack) branchDeleteStatus := s.branchDeleteStatus(r, f, pull) resubmitResult := pages.Unknown - if user.Active.Did == pull.OwnerDid { + if user.Did == pull.OwnerDid { resubmitResult = s.resubmitCheck(r, f, pull, stack) } @@ -191,7 +191,7 @@ func (s *Pulls) repoPullHelper(w http.ResponseWriter, r *http.Request, interdiff mergeCheckResponse := s.mergeCheck(r, f, pull, stack) branchDeleteStatus := s.branchDeleteStatus(r, f, pull) resubmitResult := pages.Unknown - if user != nil && user.Active.Did == pull.OwnerDid { + if user != nil && user.Did == pull.OwnerDid { resubmitResult = s.resubmitCheck(r, f, pull, stack) } @@ -232,7 +232,7 @@ func (s *Pulls) repoPullHelper(w http.ResponseWriter, r *http.Request, interdiff userReactions := map[models.ReactionKind]bool{} if user != nil { - userReactions = db.GetReactionStatusMap(s.db, user.Active.Did, pull.AtUri()) + userReactions = db.GetReactionStatusMap(s.db, user.Did, pull.AtUri()) } labelDefs, err := db.GetLabelDefinitions( @@ -402,7 +402,7 @@ func (s *Pulls) branchDeleteStatus(r *http.Request, repo *models.Repo, pull *mod } // user can only delete branch if they are a collaborator in the repo that the branch belongs to - perms := s.enforcer.GetPermissionsInRepo(user.Active.Did, repo.Knot, repo.DidSlashRepo()) + perms := s.enforcer.GetPermissionsInRepo(user.Did, repo.Knot, repo.DidSlashRepo()) if !slices.Contains(perms, "repo:push") { return nil } @@ -737,7 +737,7 @@ func (s *Pulls) PullComment(w http.ResponseWriter, r *http.Request) { } atResp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.RepoPullCommentNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: tid.TID(), Record: &lexutil.LexiconTypeDecoder{ Val: &tangled.RepoPullComment{ @@ -754,7 +754,7 @@ func (s *Pulls) PullComment(w http.ResponseWriter, r *http.Request) { } comment := &models.PullComment{ - OwnerDid: user.Active.Did, + OwnerDid: user.Did, RepoAt: f.RepoAt().String(), PullId: pull.PullId, Body: body, @@ -849,7 +849,7 @@ func (s *Pulls) NewPull(w http.ResponseWriter, r *http.Request) { fromFork := r.FormValue("fork") sourceBranch := r.FormValue("sourceBranch") patch := r.FormValue("patch") - userDid := syntax.DID(user.Active.Did) + userDid := syntax.DID(user.Did) if targetBranch == "" { s.pages.Notice(w, "pull", "Target branch is required.") @@ -1479,7 +1479,7 @@ func (s *Pulls) CompareBranchesFragment(w http.ResponseWriter, r *http.Request) func (s *Pulls) CompareForksFragment(w http.ResponseWriter, r *http.Request) { user := s.oauth.GetMultiAccountUser(r) - forks, err := db.GetForksByDid(s.db, user.Active.Did) + forks, err := db.GetForksByDid(s.db, user.Did) if err != nil { log.Println("failed to get forks", err) return @@ -1626,7 +1626,7 @@ func (s *Pulls) resubmitPatch(w http.ResponseWriter, r *http.Request) { return } - if user == nil || user.Active.Did != pull.OwnerDid { + if user == nil || user.Did != pull.OwnerDid { log.Println("unauthorized user") w.WriteHeader(http.StatusUnauthorized) return @@ -1640,7 +1640,7 @@ func (s *Pulls) resubmitPatch(w http.ResponseWriter, r *http.Request) { patch := r.FormValue("patch") - s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, "", "") + s.resubmitPullHelper(w, r, f, syntax.DID(user.Did), pull, patch, "", "") } func (s *Pulls) resubmitBranch(w http.ResponseWriter, r *http.Request) { @@ -1653,7 +1653,7 @@ func (s *Pulls) resubmitBranch(w http.ResponseWriter, r *http.Request) { return } - if user == nil || user.Active.Did != pull.OwnerDid { + if user == nil || user.Did != pull.OwnerDid { log.Println("unauthorized user") w.WriteHeader(http.StatusUnauthorized) return @@ -1665,7 +1665,7 @@ func (s *Pulls) resubmitBranch(w http.ResponseWriter, r *http.Request) { return } - roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Active.Did, f.Knot, f.DidSlashRepo())} + roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Did, f.Knot, f.DidSlashRepo())} if !roles.IsPushAllowed() { log.Println("unauthorized user") w.WriteHeader(http.StatusUnauthorized) @@ -1705,7 +1705,7 @@ func (s *Pulls) resubmitBranch(w http.ResponseWriter, r *http.Request) { patch := comparison.FormatPatchRaw combined := comparison.CombinedPatchRaw - s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, combined, sourceRev) + s.resubmitPullHelper(w, r, f, syntax.DID(user.Did), pull, patch, combined, sourceRev) } func (s *Pulls) resubmitFork(w http.ResponseWriter, r *http.Request) { @@ -1718,7 +1718,7 @@ func (s *Pulls) resubmitFork(w http.ResponseWriter, r *http.Request) { return } - if user == nil || user.Active.Did != pull.OwnerDid { + if user == nil || user.Did != pull.OwnerDid { log.Println("unauthorized user") w.WriteHeader(http.StatusUnauthorized) return @@ -1802,7 +1802,7 @@ func (s *Pulls) resubmitFork(w http.ResponseWriter, r *http.Request) { patch := comparison.FormatPatchRaw combined := comparison.CombinedPatchRaw - s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, combined, sourceRev) + s.resubmitPullHelper(w, r, f, syntax.DID(user.Did), pull, patch, combined, sourceRev) } func (s *Pulls) resubmitPullHelper( @@ -2227,7 +2227,7 @@ func (s *Pulls) MergePull(w http.ResponseWriter, r *http.Request) { // notify about the pull merge for _, p := range pullsToMerge { - s.notifier.NewPullState(r.Context(), syntax.DID(user.Active.Did), p) + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) } ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) @@ -2251,10 +2251,10 @@ func (s *Pulls) ClosePull(w http.ResponseWriter, r *http.Request) { } // auth filter: only owner or collaborators can close - roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Active.Did, f.Knot, f.DidSlashRepo())} + roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Did, f.Knot, f.DidSlashRepo())} isOwner := roles.IsOwner() isCollaborator := roles.IsCollaborator() - isPullAuthor := user.Active.Did == pull.OwnerDid + isPullAuthor := user.Did == pull.OwnerDid isCloseAllowed := isOwner || isCollaborator || isPullAuthor if !isCloseAllowed { log.Println("failed to close pull") @@ -2300,7 +2300,7 @@ func (s *Pulls) ClosePull(w http.ResponseWriter, r *http.Request) { } for _, p := range pullsToClose { - s.notifier.NewPullState(r.Context(), syntax.DID(user.Active.Did), p) + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) } ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) @@ -2325,10 +2325,10 @@ func (s *Pulls) ReopenPull(w http.ResponseWriter, r *http.Request) { } // auth filter: only owner or collaborators can close - roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Active.Did, f.Knot, f.DidSlashRepo())} + roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Did, f.Knot, f.DidSlashRepo())} isOwner := roles.IsOwner() isCollaborator := roles.IsCollaborator() - isPullAuthor := user.Active.Did == pull.OwnerDid + isPullAuthor := user.Did == pull.OwnerDid isCloseAllowed := isOwner || isCollaborator || isPullAuthor if !isCloseAllowed { log.Println("failed to close pull") @@ -2374,7 +2374,7 @@ func (s *Pulls) ReopenPull(w http.ResponseWriter, r *http.Request) { } for _, p := range pullsToReopen { - s.notifier.NewPullState(r.Context(), syntax.DID(user.Active.Did), p) + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) } ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) diff --git a/appview/repo/artifact.go b/appview/repo/artifact.go index 365f01f3..decc162e 100644 --- a/appview/repo/artifact.go +++ b/appview/repo/artifact.go @@ -75,7 +75,7 @@ func (rp *Repo) AttachArtifact(w http.ResponseWriter, r *http.Request) { putRecordResp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.RepoArtifactNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: rkey, Record: &lexutil.LexiconTypeDecoder{ Val: &tangled.RepoArtifact{ @@ -104,7 +104,7 @@ func (rp *Repo) AttachArtifact(w http.ResponseWriter, r *http.Request) { defer tx.Rollback() artifact := models.Artifact{ - Did: user.Active.Did, + Did: user.Did, Rkey: rkey, RepoAt: f.RepoAt(), Tag: tag.Tag.Hash, @@ -251,7 +251,7 @@ func (rp *Repo) DeleteArtifact(w http.ResponseWriter, r *http.Request) { artifact := artifacts[0] - if user.Active.Did != artifact.Did { + if user.Did != artifact.Did { log.Println("user not authorized to delete artifact", err) rp.pages.Notice(w, "remove", "Unauthorized deletion of artifact.") return @@ -259,7 +259,7 @@ func (rp *Repo) DeleteArtifact(w http.ResponseWriter, r *http.Request) { _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ Collection: tangled.RepoArtifactNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: artifact.Rkey, }) if err != nil { diff --git a/appview/repo/repo.go b/appview/repo/repo.go index f04f9061..1af90a1f 100644 --- a/appview/repo/repo.go +++ b/appview/repo/repo.go @@ -83,7 +83,7 @@ func New( func (rp *Repo) EditSpindle(w http.ResponseWriter, r *http.Request) { user := rp.oauth.GetMultiAccountUser(r) l := rp.logger.With("handler", "EditSpindle") - l = l.With("did", user.Active.Did) + l = l.With("did", user.Did) errorId := "operation-error" fail := func(msg string, err error) { @@ -107,7 +107,7 @@ func (rp *Repo) EditSpindle(w http.ResponseWriter, r *http.Request) { if !removingSpindle { // ensure that this is a valid spindle for this user - validSpindles, err := rp.enforcer.GetSpindlesForUser(user.Active.Did) + validSpindles, err := rp.enforcer.GetSpindlesForUser(user.Did) if err != nil { fail("Failed to find spindles. Try again later.", err) return @@ -170,7 +170,7 @@ func (rp *Repo) EditSpindle(w http.ResponseWriter, r *http.Request) { func (rp *Repo) AddLabelDef(w http.ResponseWriter, r *http.Request) { user := rp.oauth.GetMultiAccountUser(r) l := rp.logger.With("handler", "AddLabel") - l = l.With("did", user.Active.Did) + l = l.With("did", user.Did) f, err := rp.repoResolver.Resolve(r) if err != nil { @@ -216,7 +216,7 @@ func (rp *Repo) AddLabelDef(w http.ResponseWriter, r *http.Request) { } label := models.LabelDefinition{ - Did: user.Active.Did, + Did: user.Did, Rkey: tid.TID(), Name: name, ValueType: valueType, @@ -329,7 +329,7 @@ func (rp *Repo) AddLabelDef(w http.ResponseWriter, r *http.Request) { func (rp *Repo) DeleteLabelDef(w http.ResponseWriter, r *http.Request) { user := rp.oauth.GetMultiAccountUser(r) l := rp.logger.With("handler", "DeleteLabel") - l = l.With("did", user.Active.Did) + l = l.With("did", user.Did) f, err := rp.repoResolver.Resolve(r) if err != nil { @@ -437,7 +437,7 @@ func (rp *Repo) DeleteLabelDef(w http.ResponseWriter, r *http.Request) { func (rp *Repo) SubscribeLabel(w http.ResponseWriter, r *http.Request) { user := rp.oauth.GetMultiAccountUser(r) l := rp.logger.With("handler", "SubscribeLabel") - l = l.With("did", user.Active.Did) + l = l.With("did", user.Did) f, err := rp.repoResolver.Resolve(r) if err != nil { @@ -523,7 +523,7 @@ func (rp *Repo) SubscribeLabel(w http.ResponseWriter, r *http.Request) { func (rp *Repo) UnsubscribeLabel(w http.ResponseWriter, r *http.Request) { user := rp.oauth.GetMultiAccountUser(r) l := rp.logger.With("handler", "UnsubscribeLabel") - l = l.With("did", user.Active.Did) + l = l.With("did", user.Did) f, err := rp.repoResolver.Resolve(r) if err != nil { @@ -694,7 +694,7 @@ func (rp *Repo) EditLabelPanel(w http.ResponseWriter, r *http.Request) { func (rp *Repo) AddCollaborator(w http.ResponseWriter, r *http.Request) { user := rp.oauth.GetMultiAccountUser(r) l := rp.logger.With("handler", "AddCollaborator") - l = l.With("did", user.Active.Did) + l = l.With("did", user.Did) f, err := rp.repoResolver.Resolve(r) if err != nil { @@ -723,7 +723,7 @@ func (rp *Repo) AddCollaborator(w http.ResponseWriter, r *http.Request) { return } - if collaboratorIdent.DID.String() == user.Active.Did { + if collaboratorIdent.DID.String() == user.Did { fail("You seem to be adding yourself as a collaborator.", nil) return } @@ -743,7 +743,7 @@ func (rp *Repo) AddCollaborator(w http.ResponseWriter, r *http.Request) { createdAt := time.Now() resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.RepoCollaboratorNSID, - Repo: currentUser.Active.Did, + Repo: currentUser.Did, Rkey: rkey, Record: &lexutil.LexiconTypeDecoder{ Val: &tangled.RepoCollaborator{ @@ -792,7 +792,7 @@ func (rp *Repo) AddCollaborator(w http.ResponseWriter, r *http.Request) { } err = db.AddCollaborator(tx, models.Collaborator{ - Did: syntax.DID(currentUser.Active.Did), + Did: syntax.DID(currentUser.Did), Rkey: rkey, SubjectDid: collaboratorIdent.DID, RepoAt: f.RepoAt(), @@ -840,7 +840,7 @@ func (rp *Repo) DeleteRepo(w http.ResponseWriter, r *http.Request) { } _, err = comatproto.RepoDeleteRecord(r.Context(), atpClient, &comatproto.RepoDeleteRecord_Input{ Collection: tangled.RepoNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: f.Rkey, }) if err != nil { @@ -969,7 +969,7 @@ func (rp *Repo) SyncRepoFork(w http.ResponseWriter, r *http.Request) { r.Context(), client, &tangled.RepoForkSync_Input{ - Did: user.Active.Did, + Did: user.Did, Name: f.Name, Source: f.Source, Branch: ref, @@ -998,7 +998,7 @@ func (rp *Repo) ForkRepo(w http.ResponseWriter, r *http.Request) { switch r.Method { case http.MethodGet: user := rp.oauth.GetMultiAccountUser(r) - knots, err := rp.enforcer.GetKnotsForUser(user.Active.Did) + knots, err := rp.enforcer.GetKnotsForUser(user.Did) if err != nil { rp.pages.Notice(w, "repo", "Invalid user account.") return @@ -1020,7 +1020,7 @@ func (rp *Repo) ForkRepo(w http.ResponseWriter, r *http.Request) { } l = l.With("targetKnot", targetKnot) - ok, err := rp.enforcer.E.Enforce(user.Active.Did, targetKnot, targetKnot, "repo:create") + ok, err := rp.enforcer.E.Enforce(user.Did, targetKnot, targetKnot, "repo:create") if err != nil || !ok { rp.pages.Notice(w, "repo", "You do not have permission to create a repo in this knot.") return @@ -1037,7 +1037,7 @@ func (rp *Repo) ForkRepo(w http.ResponseWriter, r *http.Request) { // in the user's account. existingRepo, err := db.GetRepo( rp.db, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("name", forkName), ) if err != nil { @@ -1066,7 +1066,7 @@ func (rp *Repo) ForkRepo(w http.ResponseWriter, r *http.Request) { // create an atproto record for this fork rkey := tid.TID() repo := &models.Repo{ - Did: user.Active.Did, + Did: user.Did, Name: forkName, Knot: targetKnot, Rkey: rkey, @@ -1086,7 +1086,7 @@ func (rp *Repo) ForkRepo(w http.ResponseWriter, r *http.Request) { atresp, err := comatproto.RepoPutRecord(r.Context(), atpClient, &comatproto.RepoPutRecord_Input{ Collection: tangled.RepoNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: rkey, Record: &lexutil.LexiconTypeDecoder{ Val: &record, @@ -1165,8 +1165,8 @@ func (rp *Repo) ForkRepo(w http.ResponseWriter, r *http.Request) { } // acls - p, _ := securejoin.SecureJoin(user.Active.Did, forkName) - err = rp.enforcer.AddRepo(user.Active.Did, targetKnot, p) + p, _ := securejoin.SecureJoin(user.Did, forkName) + err = rp.enforcer.AddRepo(user.Did, targetKnot, p) if err != nil { l.Error("failed to add ACLs", "err", err) rp.pages.Notice(w, "repo", "Failed to set up repository permissions.") @@ -1191,7 +1191,7 @@ func (rp *Repo) ForkRepo(w http.ResponseWriter, r *http.Request) { aturi = "" rp.notifier.NewRepo(r.Context(), repo) - rp.pages.HxLocation(w, fmt.Sprintf("/%s/%s", user.Active.Did, forkName)) + rp.pages.HxLocation(w, fmt.Sprintf("/%s/%s", user.Did, forkName)) } } diff --git a/appview/repo/settings.go b/appview/repo/settings.go index ff537f44..c412193c 100644 --- a/appview/repo/settings.go +++ b/appview/repo/settings.go @@ -70,7 +70,7 @@ func (rp *Repo) SetDefaultBranch(w http.ResponseWriter, r *http.Request) { func (rp *Repo) Secrets(w http.ResponseWriter, r *http.Request) { user := rp.oauth.GetMultiAccountUser(r) l := rp.logger.With("handler", "Secrets") - l = l.With("did", user.Active.Did) + l = l.With("did", user.Did) f, err := rp.repoResolver.Resolve(r) if err != nil { diff --git a/appview/reporesolver/resolver.go b/appview/reporesolver/resolver.go index a7c0e6ed..f0872dad 100644 --- a/appview/reporesolver/resolver.go +++ b/appview/reporesolver/resolver.go @@ -70,8 +70,8 @@ func (rr *RepoResolver) GetRepoInfo(r *http.Request, user *oauth.MultiAccountUse isStarred := false roles := repoinfo.RolesInRepo{} if user != nil { - isStarred = db.GetStarStatus(rr.execer, user.Active.Did, repoAt) - roles.Roles = rr.enforcer.GetPermissionsInRepo(user.Active.Did, repo.Knot, repo.DidSlashRepo()) + isStarred = db.GetStarStatus(rr.execer, user.Did, repoAt) + roles.Roles = rr.enforcer.GetPermissionsInRepo(user.Did, repo.Knot, repo.DidSlashRepo()) } stats := repo.RepoStats diff --git a/appview/settings/settings.go b/appview/settings/settings.go index ed76911f..a3bc4595 100644 --- a/appview/settings/settings.go +++ b/appview/settings/settings.go @@ -121,7 +121,7 @@ func (s *Settings) updateNotificationPreferences(w http.ResponseWriter, r *http. func (s *Settings) keysSettings(w http.ResponseWriter, r *http.Request) { user := s.OAuth.GetMultiAccountUser(r) - pubKeys, err := db.GetPublicKeysForDid(s.Db, user.Active.Did) + pubKeys, err := db.GetPublicKeysForDid(s.Db, user.Did) if err != nil { log.Println(err) } @@ -134,7 +134,7 @@ func (s *Settings) keysSettings(w http.ResponseWriter, r *http.Request) { func (s *Settings) emailsSettings(w http.ResponseWriter, r *http.Request) { user := s.OAuth.GetMultiAccountUser(r) - emails, err := db.GetAllEmails(s.Db, user.Active.Did) + emails, err := db.GetAllEmails(s.Db, user.Did) if err != nil { log.Println(err) } diff --git a/appview/spindles/spindles.go b/appview/spindles/spindles.go index 5e27f2d6..01e81c4d 100644 --- a/appview/spindles/spindles.go +++ b/appview/spindles/spindles.go @@ -59,7 +59,7 @@ func (s *Spindles) spindles(w http.ResponseWriter, r *http.Request) { user := s.OAuth.GetMultiAccountUser(r) all, err := db.GetSpindles( s.Db, - orm.FilterEq("owner", user.Active.Did), + orm.FilterEq("owner", user.Did), ) if err != nil { s.Logger.Error("failed to fetch spindles", "err", err) @@ -78,7 +78,7 @@ func (s *Spindles) dashboard(w http.ResponseWriter, r *http.Request) { l := s.Logger.With("handler", "dashboard") user := s.OAuth.GetMultiAccountUser(r) - l = l.With("user", user.Active.Did) + l = l.With("user", user.Did) instance := chi.URLParam(r, "instance") if instance == "" { @@ -89,7 +89,7 @@ func (s *Spindles) dashboard(w http.ResponseWriter, r *http.Request) { spindles, err := db.GetSpindles( s.Db, orm.FilterEq("instance", instance), - orm.FilterEq("owner", user.Active.Did), + orm.FilterEq("owner", user.Did), orm.FilterIsNot("verified", "null"), ) if err != nil || len(spindles) != 1 { @@ -161,7 +161,7 @@ func (s *Spindles) register(w http.ResponseWriter, r *http.Request) { return } l = l.With("instance", instance) - l = l.With("user", user.Active.Did) + l = l.With("user", user.Did) tx, err := s.Db.Begin() if err != nil { @@ -175,7 +175,7 @@ func (s *Spindles) register(w http.ResponseWriter, r *http.Request) { }() err = db.AddSpindle(tx, models.Spindle{ - Owner: syntax.DID(user.Active.Did), + Owner: syntax.DID(user.Did), Instance: instance, }) if err != nil { @@ -199,7 +199,7 @@ func (s *Spindles) register(w http.ResponseWriter, r *http.Request) { return } - ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.SpindleNSID, user.Active.Did, instance) + ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.SpindleNSID, user.Did, instance) var exCid *string if ex != nil { exCid = ex.Cid @@ -208,7 +208,7 @@ func (s *Spindles) register(w http.ResponseWriter, r *http.Request) { // re-announce by registering under same rkey _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.SpindleNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: instance, Record: &lexutil.LexiconTypeDecoder{ Val: &tangled.Spindle{ @@ -239,14 +239,14 @@ func (s *Spindles) register(w http.ResponseWriter, r *http.Request) { } // begin verification - err = serververify.RunVerification(r.Context(), instance, user.Active.Did, s.Config.Core.Dev) + err = serververify.RunVerification(r.Context(), instance, user.Did, s.Config.Core.Dev) if err != nil { l.Error("verification failed", "err", err) s.Pages.HxRefresh(w) return } - _, err = serververify.MarkSpindleVerified(s.Db, s.Enforcer, instance, user.Active.Did) + _, err = serververify.MarkSpindleVerified(s.Db, s.Enforcer, instance, user.Did) if err != nil { l.Error("failed to mark verified", "err", err) s.Pages.HxRefresh(w) @@ -276,7 +276,7 @@ func (s *Spindles) delete(w http.ResponseWriter, r *http.Request) { spindles, err := db.GetSpindles( s.Db, - orm.FilterEq("owner", user.Active.Did), + orm.FilterEq("owner", user.Did), orm.FilterEq("instance", instance), ) if err != nil || len(spindles) != 1 { @@ -285,8 +285,8 @@ func (s *Spindles) delete(w http.ResponseWriter, r *http.Request) { return } - if string(spindles[0].Owner) != user.Active.Did { - l.Error("unauthorized", "user", user.Active.Did, "owner", spindles[0].Owner) + if string(spindles[0].Owner) != user.Did { + l.Error("unauthorized", "user", user.Did, "owner", spindles[0].Owner) s.Pages.Notice(w, noticeId, "Failed to delete spindle, unauthorized deletion attempt.") return } @@ -305,7 +305,7 @@ func (s *Spindles) delete(w http.ResponseWriter, r *http.Request) { // remove spindle members first err = db.RemoveSpindleMember( tx, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("instance", instance), ) if err != nil { @@ -316,7 +316,7 @@ func (s *Spindles) delete(w http.ResponseWriter, r *http.Request) { err = db.DeleteSpindle( tx, - orm.FilterEq("owner", user.Active.Did), + orm.FilterEq("owner", user.Did), orm.FilterEq("instance", instance), ) if err != nil { @@ -344,7 +344,7 @@ func (s *Spindles) delete(w http.ResponseWriter, r *http.Request) { _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ Collection: tangled.SpindleNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: instance, }) if err != nil { @@ -392,11 +392,11 @@ func (s *Spindles) retry(w http.ResponseWriter, r *http.Request) { return } l = l.With("instance", instance) - l = l.With("user", user.Active.Did) + l = l.With("user", user.Did) spindles, err := db.GetSpindles( s.Db, - orm.FilterEq("owner", user.Active.Did), + orm.FilterEq("owner", user.Did), orm.FilterEq("instance", instance), ) if err != nil || len(spindles) != 1 { @@ -405,14 +405,14 @@ func (s *Spindles) retry(w http.ResponseWriter, r *http.Request) { return } - if string(spindles[0].Owner) != user.Active.Did { - l.Error("unauthorized", "user", user.Active.Did, "owner", spindles[0].Owner) + if string(spindles[0].Owner) != user.Did { + l.Error("unauthorized", "user", user.Did, "owner", spindles[0].Owner) s.Pages.Notice(w, noticeId, "Failed to verify spindle, unauthorized verification attempt.") return } // begin verification - err = serververify.RunVerification(r.Context(), instance, user.Active.Did, s.Config.Core.Dev) + err = serververify.RunVerification(r.Context(), instance, user.Did, s.Config.Core.Dev) if err != nil { l.Error("verification failed", "err", err) @@ -430,7 +430,7 @@ func (s *Spindles) retry(w http.ResponseWriter, r *http.Request) { return } - rowId, err := serververify.MarkSpindleVerified(s.Db, s.Enforcer, instance, user.Active.Did) + rowId, err := serververify.MarkSpindleVerified(s.Db, s.Enforcer, instance, user.Did) if err != nil { l.Error("failed to mark verified", "err", err) s.Pages.Notice(w, noticeId, err.Error()) @@ -468,11 +468,11 @@ func (s *Spindles) addMember(w http.ResponseWriter, r *http.Request) { return } l = l.With("instance", instance) - l = l.With("user", user.Active.Did) + l = l.With("user", user.Did) spindles, err := db.GetSpindles( s.Db, - orm.FilterEq("owner", user.Active.Did), + orm.FilterEq("owner", user.Did), orm.FilterEq("instance", instance), ) if err != nil || len(spindles) != 1 { @@ -487,8 +487,8 @@ func (s *Spindles) addMember(w http.ResponseWriter, r *http.Request) { s.Pages.Notice(w, noticeId, defaultErr) } - if string(spindles[0].Owner) != user.Active.Did { - l.Error("unauthorized", "user", user.Active.Did, "owner", spindles[0].Owner) + if string(spindles[0].Owner) != user.Did { + l.Error("unauthorized", "user", user.Did, "owner", spindles[0].Owner) s.Pages.Notice(w, noticeId, "Failed to add member, unauthorized attempt.") return } @@ -537,7 +537,7 @@ func (s *Spindles) addMember(w http.ResponseWriter, r *http.Request) { // add member to db if err = db.AddSpindleMember(tx, models.SpindleMember{ - Did: syntax.DID(user.Active.Did), + Did: syntax.DID(user.Did), Rkey: rkey, Instance: instance, Subject: memberId.DID, @@ -555,7 +555,7 @@ func (s *Spindles) addMember(w http.ResponseWriter, r *http.Request) { _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.SpindleMemberNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: rkey, Record: &lexutil.LexiconTypeDecoder{ Val: &tangled.SpindleMember{ @@ -604,11 +604,11 @@ func (s *Spindles) removeMember(w http.ResponseWriter, r *http.Request) { return } l = l.With("instance", instance) - l = l.With("user", user.Active.Did) + l = l.With("user", user.Did) spindles, err := db.GetSpindles( s.Db, - orm.FilterEq("owner", user.Active.Did), + orm.FilterEq("owner", user.Did), orm.FilterEq("instance", instance), ) if err != nil || len(spindles) != 1 { @@ -617,8 +617,8 @@ func (s *Spindles) removeMember(w http.ResponseWriter, r *http.Request) { return } - if string(spindles[0].Owner) != user.Active.Did { - l.Error("unauthorized", "user", user.Active.Did, "owner", spindles[0].Owner) + if string(spindles[0].Owner) != user.Did { + l.Error("unauthorized", "user", user.Did, "owner", spindles[0].Owner) s.Pages.Notice(w, noticeId, "Failed to remove member, unauthorized attempt.") return } @@ -653,7 +653,7 @@ func (s *Spindles) removeMember(w http.ResponseWriter, r *http.Request) { // get the record from the DB first: members, err := db.GetSpindleMembers( s.Db, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("instance", instance), orm.FilterEq("subject", memberId.DID), ) @@ -666,7 +666,7 @@ func (s *Spindles) removeMember(w http.ResponseWriter, r *http.Request) { // remove from db if err = db.RemoveSpindleMember( tx, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("instance", instance), orm.FilterEq("subject", memberId.DID), ); err != nil { @@ -692,7 +692,7 @@ func (s *Spindles) removeMember(w http.ResponseWriter, r *http.Request) { // remove from pds _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ Collection: tangled.SpindleMemberNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: members[0].Rkey, }) if err != nil { diff --git a/appview/state/accounts.go b/appview/state/accounts.go index 078340bc..ec8d963b 100644 --- a/appview/state/accounts.go +++ b/appview/state/accounts.go @@ -41,7 +41,7 @@ func (s *State) RemoveAccount(w http.ResponseWriter, r *http.Request) { } currentUser := s.oauth.GetMultiAccountUser(r) - isCurrentAccount := currentUser != nil && currentUser.Active.Did == did + isCurrentAccount := currentUser != nil && currentUser.Did == did var remainingAccounts []string if currentUser != nil { diff --git a/appview/state/follow.go b/appview/state/follow.go index 73e2781a..55c45e5e 100644 --- a/appview/state/follow.go +++ b/appview/state/follow.go @@ -29,7 +29,7 @@ func (s *State) Follow(w http.ResponseWriter, r *http.Request) { return } - if currentUser.Active.Did == subjectIdent.DID.String() { + if currentUser.Did == subjectIdent.DID.String() { log.Println("cant follow or unfollow yourself") return } @@ -46,7 +46,7 @@ func (s *State) Follow(w http.ResponseWriter, r *http.Request) { rkey := tid.TID() resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.GraphFollowNSID, - Repo: currentUser.Active.Did, + Repo: currentUser.Did, Rkey: rkey, Record: &lexutil.LexiconTypeDecoder{ Val: &tangled.GraphFollow{ @@ -62,7 +62,7 @@ func (s *State) Follow(w http.ResponseWriter, r *http.Request) { log.Println("created atproto record: ", resp.Uri) follow := &models.Follow{ - UserDid: currentUser.Active.Did, + UserDid: currentUser.Did, SubjectDid: subjectIdent.DID.String(), Rkey: rkey, } @@ -89,7 +89,7 @@ func (s *State) Follow(w http.ResponseWriter, r *http.Request) { return case http.MethodDelete: // find the record in the db - follow, err := db.GetFollow(s.db, currentUser.Active.Did, subjectIdent.DID.String()) + follow, err := db.GetFollow(s.db, currentUser.Did, subjectIdent.DID.String()) if err != nil { log.Println("failed to get follow relationship") return @@ -97,7 +97,7 @@ func (s *State) Follow(w http.ResponseWriter, r *http.Request) { _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ Collection: tangled.GraphFollowNSID, - Repo: currentUser.Active.Did, + Repo: currentUser.Did, Rkey: follow.Rkey, }) @@ -106,7 +106,7 @@ func (s *State) Follow(w http.ResponseWriter, r *http.Request) { return } - err = db.DeleteFollowByRkey(s.db, currentUser.Active.Did, follow.Rkey) + err = db.DeleteFollowByRkey(s.db, currentUser.Did, follow.Rkey) if err != nil { log.Println("failed to delete follow from DB") // this is not an issue, the firehose event might have already done this diff --git a/appview/state/login.go b/appview/state/login.go index 3509f1c2..aaab11f5 100644 --- a/appview/state/login.go +++ b/appview/state/login.go @@ -74,7 +74,7 @@ func (s *State) Logout(w http.ResponseWriter, r *http.Request) { return } - currentDid := currentUser.Active.Did + currentDid := currentUser.Did var remainingAccounts []string for _, acc := range currentUser.Accounts { diff --git a/appview/state/profile.go b/appview/state/profile.go index 11887455..e795e065 100644 --- a/appview/state/profile.go +++ b/appview/state/profile.go @@ -80,7 +80,7 @@ func (s *State) profile(r *http.Request) (*pages.ProfileCard, error) { loggedInUser := s.oauth.GetMultiAccountUser(r) followStatus := models.IsNotFollowing if loggedInUser != nil { - followStatus = db.GetFollowStatus(s.db, loggedInUser.Active.Did, did) + followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, did) } now := time.Now() @@ -305,9 +305,9 @@ func (s *State) followPage( loggedInUserFollowing := make(map[string]struct{}) if loggedInUser != nil { - following, err := db.GetFollowing(s.db, loggedInUser.Active.Did) + following, err := db.GetFollowing(s.db, loggedInUser.Did) if err != nil { - l.Error("failed to get follow list", "err", err, "loggedInUser", loggedInUser.Active.Did) + l.Error("failed to get follow list", "err", err, "loggedInUser", loggedInUser.Did) return ¶ms, err } loggedInUserFollowing = make(map[string]struct{}, len(following)) @@ -322,7 +322,7 @@ func (s *State) followPage( followStatus := models.IsNotFollowing if _, exists := loggedInUserFollowing[did]; exists { followStatus = models.IsFollowing - } else if loggedInUser != nil && loggedInUser.Active.Did == did { + } else if loggedInUser != nil && loggedInUser.Did == did { followStatus = models.IsSelf } @@ -528,9 +528,9 @@ func (s *State) UpdateProfileBio(w http.ResponseWriter, r *http.Request) { return } - profile, err := db.GetProfile(s.db, user.Active.Did) + profile, err := db.GetProfile(s.db, user.Did) if err != nil { - log.Printf("getting profile data for %s: %s", user.Active.Did, err) + log.Printf("getting profile data for %s: %s", user.Did, err) } profile.Description = r.FormValue("description") @@ -576,9 +576,9 @@ func (s *State) UpdateProfilePins(w http.ResponseWriter, r *http.Request) { return } - profile, err := db.GetProfile(s.db, user.Active.Did) + profile, err := db.GetProfile(s.db, user.Did) if err != nil { - log.Printf("getting profile data for %s: %s", user.Active.Did, err) + log.Printf("getting profile data for %s: %s", user.Did, err) } i := 0 @@ -633,7 +633,7 @@ func (s *State) updateProfile(profile *models.Profile, w http.ResponseWriter, r vanityStats = append(vanityStats, string(v.Kind)) } - ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.ActorProfileNSID, user.Active.Did, "self") + ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.ActorProfileNSID, user.Did, "self") var cid *string if ex != nil { cid = ex.Cid @@ -641,7 +641,7 @@ func (s *State) updateProfile(profile *models.Profile, w http.ResponseWriter, r _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.ActorProfileNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: "self", Record: &lexutil.LexiconTypeDecoder{ Val: &tangled.ActorProfile{ @@ -670,15 +670,15 @@ func (s *State) updateProfile(profile *models.Profile, w http.ResponseWriter, r s.notifier.UpdateProfile(r.Context(), profile) - s.pages.HxRedirect(w, "/"+user.Active.Did) + s.pages.HxRedirect(w, "/"+user.Did) } func (s *State) EditBioFragment(w http.ResponseWriter, r *http.Request) { user := s.oauth.GetMultiAccountUser(r) - profile, err := db.GetProfile(s.db, user.Active.Did) + profile, err := db.GetProfile(s.db, user.Did) if err != nil { - log.Printf("getting profile data for %s: %s", user.Active.Did, err) + log.Printf("getting profile data for %s: %s", user.Did, err) } s.pages.EditBioFragment(w, pages.EditBioParams{ @@ -690,19 +690,19 @@ func (s *State) EditBioFragment(w http.ResponseWriter, r *http.Request) { func (s *State) EditPinsFragment(w http.ResponseWriter, r *http.Request) { user := s.oauth.GetMultiAccountUser(r) - profile, err := db.GetProfile(s.db, user.Active.Did) + profile, err := db.GetProfile(s.db, user.Did) if err != nil { - log.Printf("getting profile data for %s: %s", user.Active.Did, err) + log.Printf("getting profile data for %s: %s", user.Did, err) } - repos, err := db.GetRepos(s.db, 0, orm.FilterEq("did", user.Active.Did)) + repos, err := db.GetRepos(s.db, 0, orm.FilterEq("did", user.Did)) if err != nil { - log.Printf("getting repos for %s: %s", user.Active.Did, err) + log.Printf("getting repos for %s: %s", user.Did, err) } - collaboratingRepos, err := db.CollaboratingIn(s.db, user.Active.Did) + collaboratingRepos, err := db.CollaboratingIn(s.db, user.Did) if err != nil { - log.Printf("getting collaborating repos for %s: %s", user.Active.Did, err) + log.Printf("getting collaborating repos for %s: %s", user.Did, err) } allRepos := []pages.PinnedRepo{} @@ -732,7 +732,7 @@ func (s *State) EditPinsFragment(w http.ResponseWriter, r *http.Request) { func (s *State) UploadProfileAvatar(w http.ResponseWriter, r *http.Request) { l := s.logger.With("handler", "UploadProfileAvatar") user := s.oauth.GetMultiAccountUser(r) - l = l.With("did", user.Active.Did) + l = l.With("did", user.Did) // Parse multipart form (10MB max) if err := r.ParseMultipartForm(10 << 20); err != nil { @@ -779,7 +779,7 @@ func (s *State) UploadProfileAvatar(w http.ResponseWriter, r *http.Request) { l.Info("uploaded avatar blob", "cid", uploadBlobResp.Blob.Ref.String()) // get current profile record from PDS to get its CID for swap - getRecordResp, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.ActorProfileNSID, user.Active.Did, "self") + getRecordResp, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.ActorProfileNSID, user.Did, "self") if err != nil { l.Error("failed to get current profile record", "err", err) s.pages.Notice(w, "avatar-error", "Failed to get current profile from your PDS") @@ -803,7 +803,7 @@ func (s *State) UploadProfileAvatar(w http.ResponseWriter, r *http.Request) { _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.ActorProfileNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: "self", Record: &lexutil.LexiconTypeDecoder{Val: profileRecord}, SwapRecord: getRecordResp.Cid, @@ -817,10 +817,10 @@ func (s *State) UploadProfileAvatar(w http.ResponseWriter, r *http.Request) { l.Info("successfully updated profile with avatar") - profile, err := db.GetProfile(s.db, user.Active.Did) + profile, err := db.GetProfile(s.db, user.Did) if err != nil { l.Warn("getting profile data from DB", "err", err) - profile = &models.Profile{Did: user.Active.Did} + profile = &models.Profile{Did: user.Did} } profile.Avatar = uploadBlobResp.Blob.Ref.String() @@ -846,7 +846,7 @@ func (s *State) UploadProfileAvatar(w http.ResponseWriter, r *http.Request) { func (s *State) RemoveProfileAvatar(w http.ResponseWriter, r *http.Request) { l := s.logger.With("handler", "RemoveProfileAvatar") user := s.oauth.GetMultiAccountUser(r) - l = l.With("did", user.Active.Did) + l = l.With("did", user.Did) client, err := s.oauth.AuthorizedClient(r) if err != nil { @@ -855,7 +855,7 @@ func (s *State) RemoveProfileAvatar(w http.ResponseWriter, r *http.Request) { return } - getRecordResp, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.ActorProfileNSID, user.Active.Did, "self") + getRecordResp, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.ActorProfileNSID, user.Did, "self") if err != nil { l.Error("failed to get current profile record", "err", err) s.pages.Notice(w, "avatar-error", "Failed to get current profile from your PDS") @@ -879,7 +879,7 @@ func (s *State) RemoveProfileAvatar(w http.ResponseWriter, r *http.Request) { _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.ActorProfileNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: "self", Record: &lexutil.LexiconTypeDecoder{Val: profileRecord}, SwapRecord: getRecordResp.Cid, @@ -893,10 +893,10 @@ func (s *State) RemoveProfileAvatar(w http.ResponseWriter, r *http.Request) { l.Info("successfully removed avatar from PDS") - profile, err := db.GetProfile(s.db, user.Active.Did) + profile, err := db.GetProfile(s.db, user.Did) if err != nil { l.Warn("getting profile data from DB", "err", err) - profile = &models.Profile{Did: user.Active.Did} + profile = &models.Profile{Did: user.Did} } profile.Avatar = "" diff --git a/appview/state/reaction.go b/appview/state/reaction.go index 4dfceede..aa56cb34 100644 --- a/appview/state/reaction.go +++ b/appview/state/reaction.go @@ -49,7 +49,7 @@ func (s *State) React(w http.ResponseWriter, r *http.Request) { rkey := tid.TID() resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.FeedReactionNSID, - Repo: currentUser.Active.Did, + Repo: currentUser.Did, Rkey: rkey, Record: &lexutil.LexiconTypeDecoder{ Val: &tangled.FeedReaction{ @@ -64,7 +64,7 @@ func (s *State) React(w http.ResponseWriter, r *http.Request) { return } - err = db.AddReaction(s.db, currentUser.Active.Did, subjectUri, reactionKind, rkey) + err = db.AddReaction(s.db, currentUser.Did, subjectUri, reactionKind, rkey) if err != nil { log.Println("failed to react", err) return @@ -87,15 +87,15 @@ func (s *State) React(w http.ResponseWriter, r *http.Request) { return case http.MethodDelete: - reaction, err := db.GetReaction(s.db, currentUser.Active.Did, subjectUri, reactionKind) + reaction, err := db.GetReaction(s.db, currentUser.Did, subjectUri, reactionKind) if err != nil { - log.Println("failed to get reaction relationship for", currentUser.Active.Did, subjectUri) + log.Println("failed to get reaction relationship for", currentUser.Did, subjectUri) return } _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ Collection: tangled.FeedReactionNSID, - Repo: currentUser.Active.Did, + Repo: currentUser.Did, Rkey: reaction.Rkey, }) @@ -104,7 +104,7 @@ func (s *State) React(w http.ResponseWriter, r *http.Request) { return } - err = db.DeleteReactionByRkey(s.db, currentUser.Active.Did, reaction.Rkey) + err = db.DeleteReactionByRkey(s.db, currentUser.Did, reaction.Rkey) if err != nil { log.Println("failed to delete reaction from DB") // this is not an issue, the firehose event might have already done this diff --git a/appview/state/star.go b/appview/state/star.go index 64ceb55a..648c3f95 100644 --- a/appview/state/star.go +++ b/appview/state/star.go @@ -42,7 +42,7 @@ func (s *State) Star(w http.ResponseWriter, r *http.Request) { rkey := tid.TID() resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ Collection: tangled.FeedStarNSID, - Repo: currentUser.Active.Did, + Repo: currentUser.Did, Rkey: rkey, Record: &lexutil.LexiconTypeDecoder{ Val: &tangled.FeedStar{ @@ -57,7 +57,7 @@ func (s *State) Star(w http.ResponseWriter, r *http.Request) { log.Println("created atproto record: ", resp.Uri) star := &models.Star{ - Did: currentUser.Active.Did, + Did: currentUser.Did, RepoAt: subjectUri, Rkey: rkey, } @@ -84,7 +84,7 @@ func (s *State) Star(w http.ResponseWriter, r *http.Request) { return case http.MethodDelete: // find the record in the db - star, err := db.GetStar(s.db, currentUser.Active.Did, subjectUri) + star, err := db.GetStar(s.db, currentUser.Did, subjectUri) if err != nil { log.Println("failed to get star relationship") return @@ -92,7 +92,7 @@ func (s *State) Star(w http.ResponseWriter, r *http.Request) { _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ Collection: tangled.FeedStarNSID, - Repo: currentUser.Active.Did, + Repo: currentUser.Did, Rkey: star.Rkey, }) @@ -101,7 +101,7 @@ func (s *State) Star(w http.ResponseWriter, r *http.Request) { return } - err = db.DeleteStarByRkey(s.db, currentUser.Active.Did, star.Rkey) + err = db.DeleteStarByRkey(s.db, currentUser.Did, star.Rkey) if err != nil { log.Println("failed to delete star from DB") // this is not an issue, the firehose event might have already done this diff --git a/appview/state/state.go b/appview/state/state.go index 570050f8..0441c932 100644 --- a/appview/state/state.go +++ b/appview/state/state.go @@ -249,7 +249,7 @@ func (s *State) Timeline(w http.ResponseWriter, r *http.Request) { var userDid string if user != nil { - userDid = user.Active.Did + userDid = user.Did } timeline, err := db.MakeTimeline(s.db, 50, userDid, filtered) if err != nil { @@ -284,11 +284,11 @@ func (s *State) UpgradeBanner(w http.ResponseWriter, r *http.Request) { } l := s.logger.With("handler", "UpgradeBanner") - l = l.With("did", user.Active.Did) + l = l.With("did", user.Did) regs, err := db.GetRegistrations( s.db, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("needs_upgrade", 1), ) if err != nil { @@ -297,7 +297,7 @@ func (s *State) UpgradeBanner(w http.ResponseWriter, r *http.Request) { spindles, err := db.GetSpindles( s.db, - orm.FilterEq("owner", user.Active.Did), + orm.FilterEq("owner", user.Did), orm.FilterEq("needs_upgrade", 1), ) if err != nil { @@ -412,7 +412,7 @@ func (s *State) NewRepo(w http.ResponseWriter, r *http.Request) { switch r.Method { case http.MethodGet: user := s.oauth.GetMultiAccountUser(r) - knots, err := s.enforcer.GetKnotsForUser(user.Active.Did) + knots, err := s.enforcer.GetKnotsForUser(user.Did) if err != nil { s.pages.Notice(w, "repo", "Invalid user account.") return @@ -427,7 +427,7 @@ func (s *State) NewRepo(w http.ResponseWriter, r *http.Request) { l := s.logger.With("handler", "NewRepo") user := s.oauth.GetMultiAccountUser(r) - l = l.With("did", user.Active.Did) + l = l.With("did", user.Did) // form validation domain := r.FormValue("domain") @@ -459,7 +459,7 @@ func (s *State) NewRepo(w http.ResponseWriter, r *http.Request) { description := r.FormValue("description") // ACL validation - ok, err := s.enforcer.E.Enforce(user.Active.Did, domain, domain, "repo:create") + ok, err := s.enforcer.E.Enforce(user.Did, domain, domain, "repo:create") if err != nil || !ok { l.Info("unauthorized") s.pages.Notice(w, "repo", "You do not have permission to create a repo in this knot.") @@ -469,7 +469,7 @@ func (s *State) NewRepo(w http.ResponseWriter, r *http.Request) { // Check for existing repos existingRepo, err := db.GetRepo( s.db, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("name", repoName), ) if err == nil && existingRepo != nil { @@ -481,7 +481,7 @@ func (s *State) NewRepo(w http.ResponseWriter, r *http.Request) { // create atproto record for this repo rkey := tid.TID() repo := &models.Repo{ - Did: user.Active.Did, + Did: user.Did, Name: repoName, Knot: domain, Rkey: rkey, @@ -500,7 +500,7 @@ func (s *State) NewRepo(w http.ResponseWriter, r *http.Request) { atresp, err := comatproto.RepoPutRecord(r.Context(), atpClient, &comatproto.RepoPutRecord_Input{ Collection: tangled.RepoNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: rkey, Record: &lexutil.LexiconTypeDecoder{ Val: &record, @@ -577,8 +577,8 @@ func (s *State) NewRepo(w http.ResponseWriter, r *http.Request) { } // acls - p, _ := securejoin.SecureJoin(user.Active.Did, repoName) - err = s.enforcer.AddRepo(user.Active.Did, domain, p) + p, _ := securejoin.SecureJoin(user.Did, repoName) + err = s.enforcer.AddRepo(user.Did, domain, p) if err != nil { l.Error("acl setup failed", "err", err) s.pages.Notice(w, "repo", "Failed to set up repository permissions.") @@ -603,7 +603,7 @@ func (s *State) NewRepo(w http.ResponseWriter, r *http.Request) { aturi = "" s.notifier.NewRepo(r.Context(), repo) - s.pages.HxLocation(w, fmt.Sprintf("/%s/%s", user.Active.Did, repoName)) + s.pages.HxLocation(w, fmt.Sprintf("/%s/%s", user.Did, repoName)) } } diff --git a/appview/strings/strings.go b/appview/strings/strings.go index 0a9c2692..58a1e50a 100644 --- a/appview/strings/strings.go +++ b/appview/strings/strings.go @@ -156,7 +156,7 @@ func (s *Strings) contents(w http.ResponseWriter, r *http.Request) { user := s.OAuth.GetMultiAccountUser(r) isStarred := false if user != nil { - isStarred = db.GetStarStatus(s.Db, user.Active.Did, string.AtUri()) + isStarred = db.GetStarStatus(s.Db, user.Did, string.AtUri()) } s.Pages.SingleString(w, pages.SingleStringParams{ @@ -216,8 +216,8 @@ func (s *Strings) edit(w http.ResponseWriter, r *http.Request) { first := all[0] // verify that the logged in user owns this string - if user.Active.Did != id.DID.String() { - l.Error("unauthorized request", "expected", id.DID, "got", user.Active.Did) + if user.Did != id.DID.String() { + l.Error("unauthorized request", "expected", id.DID, "got", user.Did) w.WriteHeader(http.StatusUnauthorized) return } @@ -299,7 +299,7 @@ func (s *Strings) edit(w http.ResponseWriter, r *http.Request) { s.Notifier.EditString(r.Context(), &entry) // if that went okay, redir to the string - s.Pages.HxRedirect(w, "/strings/"+user.Active.Did+"/"+entry.Rkey) + s.Pages.HxRedirect(w, "/strings/"+user.Did+"/"+entry.Rkey) } } @@ -335,7 +335,7 @@ func (s *Strings) create(w http.ResponseWriter, r *http.Request) { description := r.FormValue("description") string := models.String{ - Did: syntax.DID(user.Active.Did), + Did: syntax.DID(user.Did), Rkey: tid.TID(), Filename: filename, Description: description, @@ -353,7 +353,7 @@ func (s *Strings) create(w http.ResponseWriter, r *http.Request) { resp, err := comatproto.RepoPutRecord(r.Context(), client, &atproto.RepoPutRecord_Input{ Collection: tangled.StringNSID, - Repo: user.Active.Did, + Repo: user.Did, Rkey: string.Rkey, Record: &lexutil.LexiconTypeDecoder{ Val: &record, @@ -375,7 +375,7 @@ func (s *Strings) create(w http.ResponseWriter, r *http.Request) { s.Notifier.NewString(r.Context(), &string) // successful - s.Pages.HxRedirect(w, "/strings/"+user.Active.Did+"/"+string.Rkey) + s.Pages.HxRedirect(w, "/strings/"+user.Did+"/"+string.Rkey) } } @@ -402,23 +402,23 @@ func (s *Strings) delete(w http.ResponseWriter, r *http.Request) { return } - if user.Active.Did != id.DID.String() { - fail("You cannot delete this string", fmt.Errorf("unauthorized deletion, %s != %s", user.Active.Did, id.DID.String())) + if user.Did != id.DID.String() { + fail("You cannot delete this string", fmt.Errorf("unauthorized deletion, %s != %s", user.Did, id.DID.String())) return } if err := db.DeleteString( s.Db, - orm.FilterEq("did", user.Active.Did), + orm.FilterEq("did", user.Did), orm.FilterEq("rkey", rkey), ); err != nil { fail("Failed to delete string.", err) return } - s.Notifier.DeleteString(r.Context(), user.Active.Did, rkey) + s.Notifier.DeleteString(r.Context(), user.Did, rkey) - s.Pages.HxRedirect(w, "/strings/"+user.Active.Did) + s.Pages.HxRedirect(w, "/strings/"+user.Did) } func (s *Strings) comment(w http.ResponseWriter, r *http.Request) { -- 2.51.2