Monorepo for Tangled tangled.org

appview: remove oauth.User type #1027

open opened by boltless.me targeting master from sl/uvpzuszrulvq

This is not required anymore. MultiAccountUser can just hold active user DID.

Signed-off-by: Seongmin Lee git@boltless.me

Labels

None yet.

assignee

None yet.

Participants 1
AT URI
at://did:plc:xasnlahkri4ewmbuzly2rlc5/sh.tangled.repo.pull/3mdcq5ouzmj22
+204 -214
Diff #0
+19 -19
appview/issues/issues.go
··· 102 103 userReactions := map[models.ReactionKind]bool{} 104 if user != nil { 105 - userReactions = db.GetReactionStatusMap(rp.db, user.Active.Did, issue.AtUri()) 106 } 107 108 backlinks, err := db.GetBacklinks(rp.db, issue.AtUri()) ··· 181 return 182 } 183 184 - ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoIssueNSID, user.Active.Did, newIssue.Rkey) 185 if err != nil { 186 l.Error("failed to get record", "err", err) 187 rp.pages.Notice(w, noticeId, "Failed to edit issue, no record found on PDS.") ··· 190 191 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 192 Collection: tangled.RepoIssueNSID, 193 - Repo: user.Active.Did, 194 Rkey: newIssue.Rkey, 195 SwapRecord: ex.Cid, 196 Record: &lexutil.LexiconTypeDecoder{ ··· 305 return 306 } 307 308 - roles := repoinfo.RolesInRepo{Roles: rp.enforcer.GetPermissionsInRepo(user.Active.Did, f.Knot, f.DidSlashRepo())} 309 isRepoOwner := roles.IsOwner() 310 isCollaborator := roles.IsCollaborator() 311 - isIssueOwner := user.Active.Did == issue.Did 312 313 // TODO: make this more granular 314 if isIssueOwner || isRepoOwner || isCollaborator { ··· 325 issue.Open = false 326 327 // notify about the issue closure 328 - rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Active.Did), issue) 329 330 ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) 331 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", ownerSlashRepo, issue.IssueId)) ··· 353 return 354 } 355 356 - roles := repoinfo.RolesInRepo{Roles: rp.enforcer.GetPermissionsInRepo(user.Active.Did, f.Knot, f.DidSlashRepo())} 357 isRepoOwner := roles.IsOwner() 358 isCollaborator := roles.IsCollaborator() 359 - isIssueOwner := user.Active.Did == issue.Did 360 361 if isCollaborator || isRepoOwner || isIssueOwner { 362 err := db.ReopenIssues( ··· 372 issue.Open = true 373 374 // notify about the issue reopen 375 - rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Active.Did), issue) 376 377 ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) 378 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", ownerSlashRepo, issue.IssueId)) ··· 415 mentions, references := rp.mentionsResolver.Resolve(r.Context(), body) 416 417 comment := models.IssueComment{ 418 - Did: user.Active.Did, 419 Rkey: tid.TID(), 420 IssueAt: issue.AtUri().String(), 421 ReplyTo: replyTo, ··· 556 } 557 comment := comments[0] 558 559 - if comment.Did != user.Active.Did { 560 - l.Error("unauthorized comment edit", "expectedDid", comment.Did, "gotDid", user.Active.Did) 561 http.Error(w, "you are not the author of this comment", http.StatusUnauthorized) 562 return 563 } ··· 607 // rkey is optional, it was introduced later 608 if newComment.Rkey != "" { 609 // update the record on pds 610 - ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoIssueCommentNSID, user.Active.Did, comment.Rkey) 611 if err != nil { 612 l.Error("failed to get record", "err", err, "did", newComment.Did, "rkey", newComment.Rkey) 613 rp.pages.Notice(w, fmt.Sprintf("comment-%s-status", commentId), "Failed to update description, no record found on PDS.") ··· 616 617 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 618 Collection: tangled.RepoIssueCommentNSID, 619 - Repo: user.Active.Did, 620 Rkey: newComment.Rkey, 621 SwapRecord: ex.Cid, 622 Record: &lexutil.LexiconTypeDecoder{ ··· 738 } 739 comment := comments[0] 740 741 - if comment.Did != user.Active.Did { 742 - l.Error("unauthorized action", "expectedDid", comment.Did, "gotDid", user.Active.Did) 743 http.Error(w, "you are not the author of this comment", http.StatusUnauthorized) 744 return 745 } ··· 768 } 769 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 770 Collection: tangled.RepoIssueCommentNSID, 771 - Repo: user.Active.Did, 772 Rkey: comment.Rkey, 773 }) 774 if err != nil { ··· 920 Title: r.FormValue("title"), 921 Body: body, 922 Open: true, 923 - Did: user.Active.Did, 924 Created: time.Now(), 925 Mentions: mentions, 926 References: references, ··· 944 } 945 resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 946 Collection: tangled.RepoIssueNSID, 947 - Repo: user.Active.Did, 948 Rkey: issue.Rkey, 949 Record: &lexutil.LexiconTypeDecoder{ 950 Val: &record,
··· 102 103 userReactions := map[models.ReactionKind]bool{} 104 if user != nil { 105 + userReactions = db.GetReactionStatusMap(rp.db, user.Did, issue.AtUri()) 106 } 107 108 backlinks, err := db.GetBacklinks(rp.db, issue.AtUri()) ··· 181 return 182 } 183 184 + ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoIssueNSID, user.Did, newIssue.Rkey) 185 if err != nil { 186 l.Error("failed to get record", "err", err) 187 rp.pages.Notice(w, noticeId, "Failed to edit issue, no record found on PDS.") ··· 190 191 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 192 Collection: tangled.RepoIssueNSID, 193 + Repo: user.Did, 194 Rkey: newIssue.Rkey, 195 SwapRecord: ex.Cid, 196 Record: &lexutil.LexiconTypeDecoder{ ··· 305 return 306 } 307 308 + roles := repoinfo.RolesInRepo{Roles: rp.enforcer.GetPermissionsInRepo(user.Did, f.Knot, f.DidSlashRepo())} 309 isRepoOwner := roles.IsOwner() 310 isCollaborator := roles.IsCollaborator() 311 + isIssueOwner := user.Did == issue.Did 312 313 // TODO: make this more granular 314 if isIssueOwner || isRepoOwner || isCollaborator { ··· 325 issue.Open = false 326 327 // notify about the issue closure 328 + rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Did), issue) 329 330 ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) 331 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", ownerSlashRepo, issue.IssueId)) ··· 353 return 354 } 355 356 + roles := repoinfo.RolesInRepo{Roles: rp.enforcer.GetPermissionsInRepo(user.Did, f.Knot, f.DidSlashRepo())} 357 isRepoOwner := roles.IsOwner() 358 isCollaborator := roles.IsCollaborator() 359 + isIssueOwner := user.Did == issue.Did 360 361 if isCollaborator || isRepoOwner || isIssueOwner { 362 err := db.ReopenIssues( ··· 372 issue.Open = true 373 374 // notify about the issue reopen 375 + rp.notifier.NewIssueState(r.Context(), syntax.DID(user.Did), issue) 376 377 ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) 378 rp.pages.HxLocation(w, fmt.Sprintf("/%s/issues/%d", ownerSlashRepo, issue.IssueId)) ··· 415 mentions, references := rp.mentionsResolver.Resolve(r.Context(), body) 416 417 comment := models.IssueComment{ 418 + Did: user.Did, 419 Rkey: tid.TID(), 420 IssueAt: issue.AtUri().String(), 421 ReplyTo: replyTo, ··· 556 } 557 comment := comments[0] 558 559 + if comment.Did != user.Did { 560 + l.Error("unauthorized comment edit", "expectedDid", comment.Did, "gotDid", user.Did) 561 http.Error(w, "you are not the author of this comment", http.StatusUnauthorized) 562 return 563 } ··· 607 // rkey is optional, it was introduced later 608 if newComment.Rkey != "" { 609 // update the record on pds 610 + ex, err := comatproto.RepoGetRecord(r.Context(), client, "", tangled.RepoIssueCommentNSID, user.Did, comment.Rkey) 611 if err != nil { 612 l.Error("failed to get record", "err", err, "did", newComment.Did, "rkey", newComment.Rkey) 613 rp.pages.Notice(w, fmt.Sprintf("comment-%s-status", commentId), "Failed to update description, no record found on PDS.") ··· 616 617 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 618 Collection: tangled.RepoIssueCommentNSID, 619 + Repo: user.Did, 620 Rkey: newComment.Rkey, 621 SwapRecord: ex.Cid, 622 Record: &lexutil.LexiconTypeDecoder{ ··· 738 } 739 comment := comments[0] 740 741 + if comment.Did != user.Did { 742 + l.Error("unauthorized action", "expectedDid", comment.Did, "gotDid", user.Did) 743 http.Error(w, "you are not the author of this comment", http.StatusUnauthorized) 744 return 745 } ··· 768 } 769 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 770 Collection: tangled.RepoIssueCommentNSID, 771 + Repo: user.Did, 772 Rkey: comment.Rkey, 773 }) 774 if err != nil { ··· 920 Title: r.FormValue("title"), 921 Body: body, 922 Open: true, 923 + Did: user.Did, 924 Created: time.Now(), 925 Mentions: mentions, 926 References: references, ··· 944 } 945 resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 946 Collection: tangled.RepoIssueNSID, 947 + Repo: user.Did, 948 Rkey: issue.Rkey, 949 Record: &lexutil.LexiconTypeDecoder{ 950 Val: &record,
+24 -24
appview/knots/knots.go
··· 60 user := k.OAuth.GetMultiAccountUser(r) 61 registrations, err := db.GetRegistrations( 62 k.Db, 63 - orm.FilterEq("did", user.Active.Did), 64 ) 65 if err != nil { 66 k.Logger.Error("failed to fetch knot registrations", "err", err) ··· 78 l := k.Logger.With("handler", "dashboard") 79 80 user := k.OAuth.GetMultiAccountUser(r) 81 - l = l.With("user", user.Active.Did) 82 83 domain := chi.URLParam(r, "domain") 84 if domain == "" { ··· 88 89 registrations, err := db.GetRegistrations( 90 k.Db, 91 - orm.FilterEq("did", user.Active.Did), 92 orm.FilterEq("domain", domain), 93 ) 94 if err != nil { ··· 158 return 159 } 160 l = l.With("domain", domain) 161 - l = l.With("user", user.Active.Did) 162 163 tx, err := k.Db.Begin() 164 if err != nil { ··· 171 k.Enforcer.E.LoadPolicy() 172 }() 173 174 - err = db.AddKnot(tx, domain, user.Active.Did) 175 if err != nil { 176 l.Error("failed to insert", "err", err) 177 fail() ··· 193 return 194 } 195 196 - ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.KnotNSID, user.Active.Did, domain) 197 var exCid *string 198 if ex != nil { 199 exCid = ex.Cid ··· 202 // re-announce by registering under same rkey 203 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 204 Collection: tangled.KnotNSID, 205 - Repo: user.Active.Did, 206 Rkey: domain, 207 Record: &lexutil.LexiconTypeDecoder{ 208 Val: &tangled.Knot{ ··· 233 } 234 235 // begin verification 236 - err = serververify.RunVerification(r.Context(), domain, user.Active.Did, k.Config.Core.Dev) 237 if err != nil { 238 l.Error("verification failed", "err", err) 239 k.Pages.HxRefresh(w) 240 return 241 } 242 243 - err = serververify.MarkKnotVerified(k.Db, k.Enforcer, domain, user.Active.Did) 244 if err != nil { 245 l.Error("failed to mark verified", "err", err) 246 k.Pages.HxRefresh(w) ··· 277 // get record from db first 278 registrations, err := db.GetRegistrations( 279 k.Db, 280 - orm.FilterEq("did", user.Active.Did), 281 orm.FilterEq("domain", domain), 282 ) 283 if err != nil { ··· 305 306 err = db.DeleteKnot( 307 tx, 308 - orm.FilterEq("did", user.Active.Did), 309 orm.FilterEq("domain", domain), 310 ) 311 if err != nil { ··· 333 334 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 335 Collection: tangled.KnotNSID, 336 - Repo: user.Active.Did, 337 Rkey: domain, 338 }) 339 if err != nil { ··· 381 return 382 } 383 l = l.With("domain", domain) 384 - l = l.With("user", user.Active.Did) 385 386 // get record from db first 387 registrations, err := db.GetRegistrations( 388 k.Db, 389 - orm.FilterEq("did", user.Active.Did), 390 orm.FilterEq("domain", domain), 391 ) 392 if err != nil { ··· 402 registration := registrations[0] 403 404 // begin verification 405 - err = serververify.RunVerification(r.Context(), domain, user.Active.Did, k.Config.Core.Dev) 406 if err != nil { 407 l.Error("verification failed", "err", err) 408 ··· 420 return 421 } 422 423 - err = serververify.MarkKnotVerified(k.Db, k.Enforcer, domain, user.Active.Did) 424 if err != nil { 425 l.Error("failed to mark verified", "err", err) 426 k.Pages.Notice(w, noticeId, err.Error()) ··· 439 return 440 } 441 442 - ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.KnotNSID, user.Active.Did, domain) 443 var exCid *string 444 if ex != nil { 445 exCid = ex.Cid ··· 448 // ignore the error here 449 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 450 Collection: tangled.KnotNSID, 451 - Repo: user.Active.Did, 452 Rkey: domain, 453 Record: &lexutil.LexiconTypeDecoder{ 454 Val: &tangled.Knot{ ··· 477 // Get updated registration to show 478 registrations, err = db.GetRegistrations( 479 k.Db, 480 - orm.FilterEq("did", user.Active.Did), 481 orm.FilterEq("domain", domain), 482 ) 483 if err != nil { ··· 509 return 510 } 511 l = l.With("domain", domain) 512 - l = l.With("user", user.Active.Did) 513 514 registrations, err := db.GetRegistrations( 515 k.Db, 516 - orm.FilterEq("did", user.Active.Did), 517 orm.FilterEq("domain", domain), 518 orm.FilterIsNot("registered", "null"), 519 ) ··· 566 567 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 568 Collection: tangled.KnotMemberNSID, 569 - Repo: user.Active.Did, 570 Rkey: rkey, 571 Record: &lexutil.LexiconTypeDecoder{ 572 Val: &tangled.KnotMember{ ··· 617 return 618 } 619 l = l.With("domain", domain) 620 - l = l.With("user", user.Active.Did) 621 622 registrations, err := db.GetRegistrations( 623 k.Db, 624 - orm.FilterEq("did", user.Active.Did), 625 orm.FilterEq("domain", domain), 626 orm.FilterIsNot("registered", "null"), 627 )
··· 60 user := k.OAuth.GetMultiAccountUser(r) 61 registrations, err := db.GetRegistrations( 62 k.Db, 63 + orm.FilterEq("did", user.Did), 64 ) 65 if err != nil { 66 k.Logger.Error("failed to fetch knot registrations", "err", err) ··· 78 l := k.Logger.With("handler", "dashboard") 79 80 user := k.OAuth.GetMultiAccountUser(r) 81 + l = l.With("user", user.Did) 82 83 domain := chi.URLParam(r, "domain") 84 if domain == "" { ··· 88 89 registrations, err := db.GetRegistrations( 90 k.Db, 91 + orm.FilterEq("did", user.Did), 92 orm.FilterEq("domain", domain), 93 ) 94 if err != nil { ··· 158 return 159 } 160 l = l.With("domain", domain) 161 + l = l.With("user", user.Did) 162 163 tx, err := k.Db.Begin() 164 if err != nil { ··· 171 k.Enforcer.E.LoadPolicy() 172 }() 173 174 + err = db.AddKnot(tx, domain, user.Did) 175 if err != nil { 176 l.Error("failed to insert", "err", err) 177 fail() ··· 193 return 194 } 195 196 + ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.KnotNSID, user.Did, domain) 197 var exCid *string 198 if ex != nil { 199 exCid = ex.Cid ··· 202 // re-announce by registering under same rkey 203 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 204 Collection: tangled.KnotNSID, 205 + Repo: user.Did, 206 Rkey: domain, 207 Record: &lexutil.LexiconTypeDecoder{ 208 Val: &tangled.Knot{ ··· 233 } 234 235 // begin verification 236 + err = serververify.RunVerification(r.Context(), domain, user.Did, k.Config.Core.Dev) 237 if err != nil { 238 l.Error("verification failed", "err", err) 239 k.Pages.HxRefresh(w) 240 return 241 } 242 243 + err = serververify.MarkKnotVerified(k.Db, k.Enforcer, domain, user.Did) 244 if err != nil { 245 l.Error("failed to mark verified", "err", err) 246 k.Pages.HxRefresh(w) ··· 277 // get record from db first 278 registrations, err := db.GetRegistrations( 279 k.Db, 280 + orm.FilterEq("did", user.Did), 281 orm.FilterEq("domain", domain), 282 ) 283 if err != nil { ··· 305 306 err = db.DeleteKnot( 307 tx, 308 + orm.FilterEq("did", user.Did), 309 orm.FilterEq("domain", domain), 310 ) 311 if err != nil { ··· 333 334 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 335 Collection: tangled.KnotNSID, 336 + Repo: user.Did, 337 Rkey: domain, 338 }) 339 if err != nil { ··· 381 return 382 } 383 l = l.With("domain", domain) 384 + l = l.With("user", user.Did) 385 386 // get record from db first 387 registrations, err := db.GetRegistrations( 388 k.Db, 389 + orm.FilterEq("did", user.Did), 390 orm.FilterEq("domain", domain), 391 ) 392 if err != nil { ··· 402 registration := registrations[0] 403 404 // begin verification 405 + err = serververify.RunVerification(r.Context(), domain, user.Did, k.Config.Core.Dev) 406 if err != nil { 407 l.Error("verification failed", "err", err) 408 ··· 420 return 421 } 422 423 + err = serververify.MarkKnotVerified(k.Db, k.Enforcer, domain, user.Did) 424 if err != nil { 425 l.Error("failed to mark verified", "err", err) 426 k.Pages.Notice(w, noticeId, err.Error()) ··· 439 return 440 } 441 442 + ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.KnotNSID, user.Did, domain) 443 var exCid *string 444 if ex != nil { 445 exCid = ex.Cid ··· 448 // ignore the error here 449 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 450 Collection: tangled.KnotNSID, 451 + Repo: user.Did, 452 Rkey: domain, 453 Record: &lexutil.LexiconTypeDecoder{ 454 Val: &tangled.Knot{ ··· 477 // Get updated registration to show 478 registrations, err = db.GetRegistrations( 479 k.Db, 480 + orm.FilterEq("did", user.Did), 481 orm.FilterEq("domain", domain), 482 ) 483 if err != nil { ··· 509 return 510 } 511 l = l.With("domain", domain) 512 + l = l.With("user", user.Did) 513 514 registrations, err := db.GetRegistrations( 515 k.Db, 516 + orm.FilterEq("did", user.Did), 517 orm.FilterEq("domain", domain), 518 orm.FilterIsNot("registered", "null"), 519 ) ··· 566 567 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 568 Collection: tangled.KnotMemberNSID, 569 + Repo: user.Did, 570 Rkey: rkey, 571 Record: &lexutil.LexiconTypeDecoder{ 572 Val: &tangled.KnotMember{ ··· 617 return 618 } 619 l = l.With("domain", domain) 620 + l = l.With("user", user.Did) 621 622 registrations, err := db.GetRegistrations( 623 k.Db, 624 + orm.FilterEq("did", user.Did), 625 orm.FilterEq("domain", domain), 626 orm.FilterIsNot("registered", "null"), 627 )
+1 -1
appview/labels/labels.go
··· 82 return 83 } 84 85 - did := user.Active.Did 86 rkey := tid.TID() 87 performedAt := time.Now() 88 indexedAt := time.Now()
··· 82 return 83 } 84 85 + did := user.Did 86 rkey := tid.TID() 87 performedAt := time.Now() 88 indexedAt := time.Now()
+4 -4
appview/middleware/middleware.go
··· 128 return 129 } 130 131 - ok, err := mw.enforcer.E.HasGroupingPolicy(actor.Active.Did, group, domain) 132 if err != nil || !ok { 133 - log.Printf("%s does not have perms of a %s in domain %s", actor.Active.Did, group, domain) 134 http.Error(w, "Forbiden", http.StatusUnauthorized) 135 return 136 } ··· 161 return 162 } 163 164 - ok, err := mw.enforcer.E.Enforce(actor.Active.Did, f.Knot, f.DidSlashRepo(), requiredPerm) 165 if err != nil || !ok { 166 - log.Printf("%s does not have perms of a %s in repo %s", actor.Active.Did, requiredPerm, f.DidSlashRepo()) 167 http.Error(w, "Forbiden", http.StatusUnauthorized) 168 return 169 }
··· 128 return 129 } 130 131 + ok, err := mw.enforcer.E.HasGroupingPolicy(actor.Did, group, domain) 132 if err != nil || !ok { 133 + log.Printf("%s does not have perms of a %s in domain %s", actor.Did, group, domain) 134 http.Error(w, "Forbiden", http.StatusUnauthorized) 135 return 136 } ··· 161 return 162 } 163 164 + ok, err := mw.enforcer.E.Enforce(actor.Did, f.Knot, f.DidSlashRepo(), requiredPerm) 165 if err != nil || !ok { 166 + log.Printf("%s does not have perms of a %s in repo %s", actor.Did, requiredPerm, f.DidSlashRepo()) 167 http.Error(w, "Forbiden", http.StatusUnauthorized) 168 return 169 }
+4 -4
appview/notifications/notifications.go
··· 54 55 total, err := db.CountNotifications( 56 n.db, 57 - orm.FilterEq("recipient_did", user.Active.Did), 58 ) 59 if err != nil { 60 l.Error("failed to get total notifications", "err", err) ··· 65 notifications, err := db.GetNotificationsWithEntities( 66 n.db, 67 page, 68 - orm.FilterEq("recipient_did", user.Active.Did), 69 ) 70 if err != nil { 71 l.Error("failed to get notifications", "err", err) ··· 73 return 74 } 75 76 - err = db.MarkAllNotificationsRead(n.db, user.Active.Did) 77 if err != nil { 78 l.Error("failed to mark notifications as read", "err", err) 79 } ··· 98 99 count, err := db.CountNotifications( 100 n.db, 101 - orm.FilterEq("recipient_did", user.Active.Did), 102 orm.FilterEq("read", 0), 103 ) 104 if err != nil {
··· 54 55 total, err := db.CountNotifications( 56 n.db, 57 + orm.FilterEq("recipient_did", user.Did), 58 ) 59 if err != nil { 60 l.Error("failed to get total notifications", "err", err) ··· 65 notifications, err := db.GetNotificationsWithEntities( 66 n.db, 67 page, 68 + orm.FilterEq("recipient_did", user.Did), 69 ) 70 if err != nil { 71 l.Error("failed to get notifications", "err", err) ··· 73 return 74 } 75 76 + err = db.MarkAllNotificationsRead(n.db, user.Did) 77 if err != nil { 78 l.Error("failed to mark notifications as read", "err", err) 79 } ··· 98 99 count, err := db.CountNotifications( 100 n.db, 101 + orm.FilterEq("recipient_did", user.Did), 102 orm.FilterEq("read", 0), 103 ) 104 if err != nil {
+2 -8
appview/oauth/accounts.go
··· 22 } 23 24 type MultiAccountUser struct { 25 - Active User 26 Accounts []AccountInfo 27 } 28 29 - func (m *MultiAccountUser) Did() string { 30 - return m.Active.Did 31 - } 32 - 33 func (o *OAuth) GetAccounts(r *http.Request) *AccountRegistry { 34 session, err := o.SessStore.Get(r, AccountsName) 35 if err != nil || session.IsNew { ··· 116 117 registry := o.GetAccounts(r) 118 return &MultiAccountUser{ 119 - Active: User{ 120 - Did: sess.Data.AccountDID.String(), 121 - }, 122 Accounts: registry.Accounts, 123 } 124 }
··· 22 } 23 24 type MultiAccountUser struct { 25 + Did string 26 Accounts []AccountInfo 27 } 28 29 func (o *OAuth) GetAccounts(r *http.Request) *AccountRegistry { 30 session, err := o.SessStore.Get(r, AccountsName) 31 if err != nil || session.IsNew { ··· 112 113 registry := o.GetAccounts(r) 114 return &MultiAccountUser{ 115 + Did: sess.Data.AccountDID.String(), 116 Accounts: registry.Accounts, 117 } 118 }
+1 -5
appview/oauth/oauth.go
··· 225 return o.saveAccounts(w, r, registry) 226 } 227 228 - type User struct { 229 - Did string 230 - } 231 - 232 func (o *OAuth) GetDid(r *http.Request) string { 233 if u := o.GetMultiAccountUser(r); u != nil { 234 - return u.Did() 235 } 236 237 return ""
··· 225 return o.saveAccounts(w, r, registry) 226 } 227 228 func (o *OAuth) GetDid(r *http.Request) string { 229 if u := o.GetMultiAccountUser(r); u != nil { 230 + return u.Did 231 } 232 233 return ""
+22 -22
appview/pulls/pulls.go
··· 128 mergeCheckResponse := s.mergeCheck(r, f, pull, stack) 129 branchDeleteStatus := s.branchDeleteStatus(r, f, pull) 130 resubmitResult := pages.Unknown 131 - if user.Active.Did == pull.OwnerDid { 132 resubmitResult = s.resubmitCheck(r, f, pull, stack) 133 } 134 ··· 191 mergeCheckResponse := s.mergeCheck(r, f, pull, stack) 192 branchDeleteStatus := s.branchDeleteStatus(r, f, pull) 193 resubmitResult := pages.Unknown 194 - if user != nil && user.Active.Did == pull.OwnerDid { 195 resubmitResult = s.resubmitCheck(r, f, pull, stack) 196 } 197 ··· 232 233 userReactions := map[models.ReactionKind]bool{} 234 if user != nil { 235 - userReactions = db.GetReactionStatusMap(s.db, user.Active.Did, pull.AtUri()) 236 } 237 238 labelDefs, err := db.GetLabelDefinitions( ··· 402 } 403 404 // user can only delete branch if they are a collaborator in the repo that the branch belongs to 405 - perms := s.enforcer.GetPermissionsInRepo(user.Active.Did, repo.Knot, repo.DidSlashRepo()) 406 if !slices.Contains(perms, "repo:push") { 407 return nil 408 } ··· 737 } 738 atResp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 739 Collection: tangled.RepoPullCommentNSID, 740 - Repo: user.Active.Did, 741 Rkey: tid.TID(), 742 Record: &lexutil.LexiconTypeDecoder{ 743 Val: &tangled.RepoPullComment{ ··· 754 } 755 756 comment := &models.PullComment{ 757 - OwnerDid: user.Active.Did, 758 RepoAt: f.RepoAt().String(), 759 PullId: pull.PullId, 760 Body: body, ··· 849 fromFork := r.FormValue("fork") 850 sourceBranch := r.FormValue("sourceBranch") 851 patch := r.FormValue("patch") 852 - userDid := syntax.DID(user.Active.Did) 853 854 if targetBranch == "" { 855 s.pages.Notice(w, "pull", "Target branch is required.") ··· 1479 func (s *Pulls) CompareForksFragment(w http.ResponseWriter, r *http.Request) { 1480 user := s.oauth.GetMultiAccountUser(r) 1481 1482 - forks, err := db.GetForksByDid(s.db, user.Active.Did) 1483 if err != nil { 1484 log.Println("failed to get forks", err) 1485 return ··· 1626 return 1627 } 1628 1629 - if user == nil || user.Active.Did != pull.OwnerDid { 1630 log.Println("unauthorized user") 1631 w.WriteHeader(http.StatusUnauthorized) 1632 return ··· 1640 1641 patch := r.FormValue("patch") 1642 1643 - s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, "", "") 1644 } 1645 1646 func (s *Pulls) resubmitBranch(w http.ResponseWriter, r *http.Request) { ··· 1653 return 1654 } 1655 1656 - if user == nil || user.Active.Did != pull.OwnerDid { 1657 log.Println("unauthorized user") 1658 w.WriteHeader(http.StatusUnauthorized) 1659 return ··· 1665 return 1666 } 1667 1668 - roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Active.Did, f.Knot, f.DidSlashRepo())} 1669 if !roles.IsPushAllowed() { 1670 log.Println("unauthorized user") 1671 w.WriteHeader(http.StatusUnauthorized) ··· 1705 patch := comparison.FormatPatchRaw 1706 combined := comparison.CombinedPatchRaw 1707 1708 - s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, combined, sourceRev) 1709 } 1710 1711 func (s *Pulls) resubmitFork(w http.ResponseWriter, r *http.Request) { ··· 1718 return 1719 } 1720 1721 - if user == nil || user.Active.Did != pull.OwnerDid { 1722 log.Println("unauthorized user") 1723 w.WriteHeader(http.StatusUnauthorized) 1724 return ··· 1802 patch := comparison.FormatPatchRaw 1803 combined := comparison.CombinedPatchRaw 1804 1805 - s.resubmitPullHelper(w, r, f, syntax.DID(user.Active.Did), pull, patch, combined, sourceRev) 1806 } 1807 1808 func (s *Pulls) resubmitPullHelper( ··· 2227 2228 // notify about the pull merge 2229 for _, p := range pullsToMerge { 2230 - s.notifier.NewPullState(r.Context(), syntax.DID(user.Active.Did), p) 2231 } 2232 2233 ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) ··· 2251 } 2252 2253 // auth filter: only owner or collaborators can close 2254 - roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Active.Did, f.Knot, f.DidSlashRepo())} 2255 isOwner := roles.IsOwner() 2256 isCollaborator := roles.IsCollaborator() 2257 - isPullAuthor := user.Active.Did == pull.OwnerDid 2258 isCloseAllowed := isOwner || isCollaborator || isPullAuthor 2259 if !isCloseAllowed { 2260 log.Println("failed to close pull") ··· 2300 } 2301 2302 for _, p := range pullsToClose { 2303 - s.notifier.NewPullState(r.Context(), syntax.DID(user.Active.Did), p) 2304 } 2305 2306 ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) ··· 2325 } 2326 2327 // auth filter: only owner or collaborators can close 2328 - roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Active.Did, f.Knot, f.DidSlashRepo())} 2329 isOwner := roles.IsOwner() 2330 isCollaborator := roles.IsCollaborator() 2331 - isPullAuthor := user.Active.Did == pull.OwnerDid 2332 isCloseAllowed := isOwner || isCollaborator || isPullAuthor 2333 if !isCloseAllowed { 2334 log.Println("failed to close pull") ··· 2374 } 2375 2376 for _, p := range pullsToReopen { 2377 - s.notifier.NewPullState(r.Context(), syntax.DID(user.Active.Did), p) 2378 } 2379 2380 ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f)
··· 128 mergeCheckResponse := s.mergeCheck(r, f, pull, stack) 129 branchDeleteStatus := s.branchDeleteStatus(r, f, pull) 130 resubmitResult := pages.Unknown 131 + if user.Did == pull.OwnerDid { 132 resubmitResult = s.resubmitCheck(r, f, pull, stack) 133 } 134 ··· 191 mergeCheckResponse := s.mergeCheck(r, f, pull, stack) 192 branchDeleteStatus := s.branchDeleteStatus(r, f, pull) 193 resubmitResult := pages.Unknown 194 + if user != nil && user.Did == pull.OwnerDid { 195 resubmitResult = s.resubmitCheck(r, f, pull, stack) 196 } 197 ··· 232 233 userReactions := map[models.ReactionKind]bool{} 234 if user != nil { 235 + userReactions = db.GetReactionStatusMap(s.db, user.Did, pull.AtUri()) 236 } 237 238 labelDefs, err := db.GetLabelDefinitions( ··· 402 } 403 404 // user can only delete branch if they are a collaborator in the repo that the branch belongs to 405 + perms := s.enforcer.GetPermissionsInRepo(user.Did, repo.Knot, repo.DidSlashRepo()) 406 if !slices.Contains(perms, "repo:push") { 407 return nil 408 } ··· 737 } 738 atResp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 739 Collection: tangled.RepoPullCommentNSID, 740 + Repo: user.Did, 741 Rkey: tid.TID(), 742 Record: &lexutil.LexiconTypeDecoder{ 743 Val: &tangled.RepoPullComment{ ··· 754 } 755 756 comment := &models.PullComment{ 757 + OwnerDid: user.Did, 758 RepoAt: f.RepoAt().String(), 759 PullId: pull.PullId, 760 Body: body, ··· 849 fromFork := r.FormValue("fork") 850 sourceBranch := r.FormValue("sourceBranch") 851 patch := r.FormValue("patch") 852 + userDid := syntax.DID(user.Did) 853 854 if targetBranch == "" { 855 s.pages.Notice(w, "pull", "Target branch is required.") ··· 1479 func (s *Pulls) CompareForksFragment(w http.ResponseWriter, r *http.Request) { 1480 user := s.oauth.GetMultiAccountUser(r) 1481 1482 + forks, err := db.GetForksByDid(s.db, user.Did) 1483 if err != nil { 1484 log.Println("failed to get forks", err) 1485 return ··· 1626 return 1627 } 1628 1629 + if user == nil || user.Did != pull.OwnerDid { 1630 log.Println("unauthorized user") 1631 w.WriteHeader(http.StatusUnauthorized) 1632 return ··· 1640 1641 patch := r.FormValue("patch") 1642 1643 + s.resubmitPullHelper(w, r, f, syntax.DID(user.Did), pull, patch, "", "") 1644 } 1645 1646 func (s *Pulls) resubmitBranch(w http.ResponseWriter, r *http.Request) { ··· 1653 return 1654 } 1655 1656 + if user == nil || user.Did != pull.OwnerDid { 1657 log.Println("unauthorized user") 1658 w.WriteHeader(http.StatusUnauthorized) 1659 return ··· 1665 return 1666 } 1667 1668 + roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Did, f.Knot, f.DidSlashRepo())} 1669 if !roles.IsPushAllowed() { 1670 log.Println("unauthorized user") 1671 w.WriteHeader(http.StatusUnauthorized) ··· 1705 patch := comparison.FormatPatchRaw 1706 combined := comparison.CombinedPatchRaw 1707 1708 + s.resubmitPullHelper(w, r, f, syntax.DID(user.Did), pull, patch, combined, sourceRev) 1709 } 1710 1711 func (s *Pulls) resubmitFork(w http.ResponseWriter, r *http.Request) { ··· 1718 return 1719 } 1720 1721 + if user == nil || user.Did != pull.OwnerDid { 1722 log.Println("unauthorized user") 1723 w.WriteHeader(http.StatusUnauthorized) 1724 return ··· 1802 patch := comparison.FormatPatchRaw 1803 combined := comparison.CombinedPatchRaw 1804 1805 + s.resubmitPullHelper(w, r, f, syntax.DID(user.Did), pull, patch, combined, sourceRev) 1806 } 1807 1808 func (s *Pulls) resubmitPullHelper( ··· 2227 2228 // notify about the pull merge 2229 for _, p := range pullsToMerge { 2230 + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) 2231 } 2232 2233 ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) ··· 2251 } 2252 2253 // auth filter: only owner or collaborators can close 2254 + roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Did, f.Knot, f.DidSlashRepo())} 2255 isOwner := roles.IsOwner() 2256 isCollaborator := roles.IsCollaborator() 2257 + isPullAuthor := user.Did == pull.OwnerDid 2258 isCloseAllowed := isOwner || isCollaborator || isPullAuthor 2259 if !isCloseAllowed { 2260 log.Println("failed to close pull") ··· 2300 } 2301 2302 for _, p := range pullsToClose { 2303 + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) 2304 } 2305 2306 ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f) ··· 2325 } 2326 2327 // auth filter: only owner or collaborators can close 2328 + roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(user.Did, f.Knot, f.DidSlashRepo())} 2329 isOwner := roles.IsOwner() 2330 isCollaborator := roles.IsCollaborator() 2331 + isPullAuthor := user.Did == pull.OwnerDid 2332 isCloseAllowed := isOwner || isCollaborator || isPullAuthor 2333 if !isCloseAllowed { 2334 log.Println("failed to close pull") ··· 2374 } 2375 2376 for _, p := range pullsToReopen { 2377 + s.notifier.NewPullState(r.Context(), syntax.DID(user.Did), p) 2378 } 2379 2380 ownerSlashRepo := reporesolver.GetBaseRepoPath(r, f)
+4 -4
appview/repo/artifact.go
··· 75 76 putRecordResp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 77 Collection: tangled.RepoArtifactNSID, 78 - Repo: user.Active.Did, 79 Rkey: rkey, 80 Record: &lexutil.LexiconTypeDecoder{ 81 Val: &tangled.RepoArtifact{ ··· 104 defer tx.Rollback() 105 106 artifact := models.Artifact{ 107 - Did: user.Active.Did, 108 Rkey: rkey, 109 RepoAt: f.RepoAt(), 110 Tag: tag.Tag.Hash, ··· 251 252 artifact := artifacts[0] 253 254 - if user.Active.Did != artifact.Did { 255 log.Println("user not authorized to delete artifact", err) 256 rp.pages.Notice(w, "remove", "Unauthorized deletion of artifact.") 257 return ··· 259 260 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 261 Collection: tangled.RepoArtifactNSID, 262 - Repo: user.Active.Did, 263 Rkey: artifact.Rkey, 264 }) 265 if err != nil {
··· 75 76 putRecordResp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 77 Collection: tangled.RepoArtifactNSID, 78 + Repo: user.Did, 79 Rkey: rkey, 80 Record: &lexutil.LexiconTypeDecoder{ 81 Val: &tangled.RepoArtifact{ ··· 104 defer tx.Rollback() 105 106 artifact := models.Artifact{ 107 + Did: user.Did, 108 Rkey: rkey, 109 RepoAt: f.RepoAt(), 110 Tag: tag.Tag.Hash, ··· 251 252 artifact := artifacts[0] 253 254 + if user.Did != artifact.Did { 255 log.Println("user not authorized to delete artifact", err) 256 rp.pages.Notice(w, "remove", "Unauthorized deletion of artifact.") 257 return ··· 259 260 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 261 Collection: tangled.RepoArtifactNSID, 262 + Repo: user.Did, 263 Rkey: artifact.Rkey, 264 }) 265 if err != nil {
+21 -21
appview/repo/repo.go
··· 83 func (rp *Repo) EditSpindle(w http.ResponseWriter, r *http.Request) { 84 user := rp.oauth.GetMultiAccountUser(r) 85 l := rp.logger.With("handler", "EditSpindle") 86 - l = l.With("did", user.Active.Did) 87 88 errorId := "operation-error" 89 fail := func(msg string, err error) { ··· 107 108 if !removingSpindle { 109 // ensure that this is a valid spindle for this user 110 - validSpindles, err := rp.enforcer.GetSpindlesForUser(user.Active.Did) 111 if err != nil { 112 fail("Failed to find spindles. Try again later.", err) 113 return ··· 170 func (rp *Repo) AddLabelDef(w http.ResponseWriter, r *http.Request) { 171 user := rp.oauth.GetMultiAccountUser(r) 172 l := rp.logger.With("handler", "AddLabel") 173 - l = l.With("did", user.Active.Did) 174 175 f, err := rp.repoResolver.Resolve(r) 176 if err != nil { ··· 216 } 217 218 label := models.LabelDefinition{ 219 - Did: user.Active.Did, 220 Rkey: tid.TID(), 221 Name: name, 222 ValueType: valueType, ··· 329 func (rp *Repo) DeleteLabelDef(w http.ResponseWriter, r *http.Request) { 330 user := rp.oauth.GetMultiAccountUser(r) 331 l := rp.logger.With("handler", "DeleteLabel") 332 - l = l.With("did", user.Active.Did) 333 334 f, err := rp.repoResolver.Resolve(r) 335 if err != nil { ··· 437 func (rp *Repo) SubscribeLabel(w http.ResponseWriter, r *http.Request) { 438 user := rp.oauth.GetMultiAccountUser(r) 439 l := rp.logger.With("handler", "SubscribeLabel") 440 - l = l.With("did", user.Active.Did) 441 442 f, err := rp.repoResolver.Resolve(r) 443 if err != nil { ··· 523 func (rp *Repo) UnsubscribeLabel(w http.ResponseWriter, r *http.Request) { 524 user := rp.oauth.GetMultiAccountUser(r) 525 l := rp.logger.With("handler", "UnsubscribeLabel") 526 - l = l.With("did", user.Active.Did) 527 528 f, err := rp.repoResolver.Resolve(r) 529 if err != nil { ··· 694 func (rp *Repo) AddCollaborator(w http.ResponseWriter, r *http.Request) { 695 user := rp.oauth.GetMultiAccountUser(r) 696 l := rp.logger.With("handler", "AddCollaborator") 697 - l = l.With("did", user.Active.Did) 698 699 f, err := rp.repoResolver.Resolve(r) 700 if err != nil { ··· 723 return 724 } 725 726 - if collaboratorIdent.DID.String() == user.Active.Did { 727 fail("You seem to be adding yourself as a collaborator.", nil) 728 return 729 } ··· 743 createdAt := time.Now() 744 resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 745 Collection: tangled.RepoCollaboratorNSID, 746 - Repo: currentUser.Active.Did, 747 Rkey: rkey, 748 Record: &lexutil.LexiconTypeDecoder{ 749 Val: &tangled.RepoCollaborator{ ··· 792 } 793 794 err = db.AddCollaborator(tx, models.Collaborator{ 795 - Did: syntax.DID(currentUser.Active.Did), 796 Rkey: rkey, 797 SubjectDid: collaboratorIdent.DID, 798 RepoAt: f.RepoAt(), ··· 840 } 841 _, err = comatproto.RepoDeleteRecord(r.Context(), atpClient, &comatproto.RepoDeleteRecord_Input{ 842 Collection: tangled.RepoNSID, 843 - Repo: user.Active.Did, 844 Rkey: f.Rkey, 845 }) 846 if err != nil { ··· 969 r.Context(), 970 client, 971 &tangled.RepoForkSync_Input{ 972 - Did: user.Active.Did, 973 Name: f.Name, 974 Source: f.Source, 975 Branch: ref, ··· 998 switch r.Method { 999 case http.MethodGet: 1000 user := rp.oauth.GetMultiAccountUser(r) 1001 - knots, err := rp.enforcer.GetKnotsForUser(user.Active.Did) 1002 if err != nil { 1003 rp.pages.Notice(w, "repo", "Invalid user account.") 1004 return ··· 1020 } 1021 l = l.With("targetKnot", targetKnot) 1022 1023 - ok, err := rp.enforcer.E.Enforce(user.Active.Did, targetKnot, targetKnot, "repo:create") 1024 if err != nil || !ok { 1025 rp.pages.Notice(w, "repo", "You do not have permission to create a repo in this knot.") 1026 return ··· 1037 // in the user's account. 1038 existingRepo, err := db.GetRepo( 1039 rp.db, 1040 - orm.FilterEq("did", user.Active.Did), 1041 orm.FilterEq("name", forkName), 1042 ) 1043 if err != nil { ··· 1066 // create an atproto record for this fork 1067 rkey := tid.TID() 1068 repo := &models.Repo{ 1069 - Did: user.Active.Did, 1070 Name: forkName, 1071 Knot: targetKnot, 1072 Rkey: rkey, ··· 1086 1087 atresp, err := comatproto.RepoPutRecord(r.Context(), atpClient, &comatproto.RepoPutRecord_Input{ 1088 Collection: tangled.RepoNSID, 1089 - Repo: user.Active.Did, 1090 Rkey: rkey, 1091 Record: &lexutil.LexiconTypeDecoder{ 1092 Val: &record, ··· 1165 } 1166 1167 // acls 1168 - p, _ := securejoin.SecureJoin(user.Active.Did, forkName) 1169 - err = rp.enforcer.AddRepo(user.Active.Did, targetKnot, p) 1170 if err != nil { 1171 l.Error("failed to add ACLs", "err", err) 1172 rp.pages.Notice(w, "repo", "Failed to set up repository permissions.") ··· 1191 aturi = "" 1192 1193 rp.notifier.NewRepo(r.Context(), repo) 1194 - rp.pages.HxLocation(w, fmt.Sprintf("/%s/%s", user.Active.Did, forkName)) 1195 } 1196 } 1197
··· 83 func (rp *Repo) EditSpindle(w http.ResponseWriter, r *http.Request) { 84 user := rp.oauth.GetMultiAccountUser(r) 85 l := rp.logger.With("handler", "EditSpindle") 86 + l = l.With("did", user.Did) 87 88 errorId := "operation-error" 89 fail := func(msg string, err error) { ··· 107 108 if !removingSpindle { 109 // ensure that this is a valid spindle for this user 110 + validSpindles, err := rp.enforcer.GetSpindlesForUser(user.Did) 111 if err != nil { 112 fail("Failed to find spindles. Try again later.", err) 113 return ··· 170 func (rp *Repo) AddLabelDef(w http.ResponseWriter, r *http.Request) { 171 user := rp.oauth.GetMultiAccountUser(r) 172 l := rp.logger.With("handler", "AddLabel") 173 + l = l.With("did", user.Did) 174 175 f, err := rp.repoResolver.Resolve(r) 176 if err != nil { ··· 216 } 217 218 label := models.LabelDefinition{ 219 + Did: user.Did, 220 Rkey: tid.TID(), 221 Name: name, 222 ValueType: valueType, ··· 329 func (rp *Repo) DeleteLabelDef(w http.ResponseWriter, r *http.Request) { 330 user := rp.oauth.GetMultiAccountUser(r) 331 l := rp.logger.With("handler", "DeleteLabel") 332 + l = l.With("did", user.Did) 333 334 f, err := rp.repoResolver.Resolve(r) 335 if err != nil { ··· 437 func (rp *Repo) SubscribeLabel(w http.ResponseWriter, r *http.Request) { 438 user := rp.oauth.GetMultiAccountUser(r) 439 l := rp.logger.With("handler", "SubscribeLabel") 440 + l = l.With("did", user.Did) 441 442 f, err := rp.repoResolver.Resolve(r) 443 if err != nil { ··· 523 func (rp *Repo) UnsubscribeLabel(w http.ResponseWriter, r *http.Request) { 524 user := rp.oauth.GetMultiAccountUser(r) 525 l := rp.logger.With("handler", "UnsubscribeLabel") 526 + l = l.With("did", user.Did) 527 528 f, err := rp.repoResolver.Resolve(r) 529 if err != nil { ··· 694 func (rp *Repo) AddCollaborator(w http.ResponseWriter, r *http.Request) { 695 user := rp.oauth.GetMultiAccountUser(r) 696 l := rp.logger.With("handler", "AddCollaborator") 697 + l = l.With("did", user.Did) 698 699 f, err := rp.repoResolver.Resolve(r) 700 if err != nil { ··· 723 return 724 } 725 726 + if collaboratorIdent.DID.String() == user.Did { 727 fail("You seem to be adding yourself as a collaborator.", nil) 728 return 729 } ··· 743 createdAt := time.Now() 744 resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 745 Collection: tangled.RepoCollaboratorNSID, 746 + Repo: currentUser.Did, 747 Rkey: rkey, 748 Record: &lexutil.LexiconTypeDecoder{ 749 Val: &tangled.RepoCollaborator{ ··· 792 } 793 794 err = db.AddCollaborator(tx, models.Collaborator{ 795 + Did: syntax.DID(currentUser.Did), 796 Rkey: rkey, 797 SubjectDid: collaboratorIdent.DID, 798 RepoAt: f.RepoAt(), ··· 840 } 841 _, err = comatproto.RepoDeleteRecord(r.Context(), atpClient, &comatproto.RepoDeleteRecord_Input{ 842 Collection: tangled.RepoNSID, 843 + Repo: user.Did, 844 Rkey: f.Rkey, 845 }) 846 if err != nil { ··· 969 r.Context(), 970 client, 971 &tangled.RepoForkSync_Input{ 972 + Did: user.Did, 973 Name: f.Name, 974 Source: f.Source, 975 Branch: ref, ··· 998 switch r.Method { 999 case http.MethodGet: 1000 user := rp.oauth.GetMultiAccountUser(r) 1001 + knots, err := rp.enforcer.GetKnotsForUser(user.Did) 1002 if err != nil { 1003 rp.pages.Notice(w, "repo", "Invalid user account.") 1004 return ··· 1020 } 1021 l = l.With("targetKnot", targetKnot) 1022 1023 + ok, err := rp.enforcer.E.Enforce(user.Did, targetKnot, targetKnot, "repo:create") 1024 if err != nil || !ok { 1025 rp.pages.Notice(w, "repo", "You do not have permission to create a repo in this knot.") 1026 return ··· 1037 // in the user's account. 1038 existingRepo, err := db.GetRepo( 1039 rp.db, 1040 + orm.FilterEq("did", user.Did), 1041 orm.FilterEq("name", forkName), 1042 ) 1043 if err != nil { ··· 1066 // create an atproto record for this fork 1067 rkey := tid.TID() 1068 repo := &models.Repo{ 1069 + Did: user.Did, 1070 Name: forkName, 1071 Knot: targetKnot, 1072 Rkey: rkey, ··· 1086 1087 atresp, err := comatproto.RepoPutRecord(r.Context(), atpClient, &comatproto.RepoPutRecord_Input{ 1088 Collection: tangled.RepoNSID, 1089 + Repo: user.Did, 1090 Rkey: rkey, 1091 Record: &lexutil.LexiconTypeDecoder{ 1092 Val: &record, ··· 1165 } 1166 1167 // acls 1168 + p, _ := securejoin.SecureJoin(user.Did, forkName) 1169 + err = rp.enforcer.AddRepo(user.Did, targetKnot, p) 1170 if err != nil { 1171 l.Error("failed to add ACLs", "err", err) 1172 rp.pages.Notice(w, "repo", "Failed to set up repository permissions.") ··· 1191 aturi = "" 1192 1193 rp.notifier.NewRepo(r.Context(), repo) 1194 + rp.pages.HxLocation(w, fmt.Sprintf("/%s/%s", user.Did, forkName)) 1195 } 1196 } 1197
+1 -1
appview/repo/settings.go
··· 70 func (rp *Repo) Secrets(w http.ResponseWriter, r *http.Request) { 71 user := rp.oauth.GetMultiAccountUser(r) 72 l := rp.logger.With("handler", "Secrets") 73 - l = l.With("did", user.Active.Did) 74 75 f, err := rp.repoResolver.Resolve(r) 76 if err != nil {
··· 70 func (rp *Repo) Secrets(w http.ResponseWriter, r *http.Request) { 71 user := rp.oauth.GetMultiAccountUser(r) 72 l := rp.logger.With("handler", "Secrets") 73 + l = l.With("did", user.Did) 74 75 f, err := rp.repoResolver.Resolve(r) 76 if err != nil {
+2 -2
appview/reporesolver/resolver.go
··· 70 isStarred := false 71 roles := repoinfo.RolesInRepo{} 72 if user != nil { 73 - isStarred = db.GetStarStatus(rr.execer, user.Active.Did, repoAt) 74 - roles.Roles = rr.enforcer.GetPermissionsInRepo(user.Active.Did, repo.Knot, repo.DidSlashRepo()) 75 } 76 77 stats := repo.RepoStats
··· 70 isStarred := false 71 roles := repoinfo.RolesInRepo{} 72 if user != nil { 73 + isStarred = db.GetStarStatus(rr.execer, user.Did, repoAt) 74 + roles.Roles = rr.enforcer.GetPermissionsInRepo(user.Did, repo.Knot, repo.DidSlashRepo()) 75 } 76 77 stats := repo.RepoStats
+2 -2
appview/settings/settings.go
··· 121 122 func (s *Settings) keysSettings(w http.ResponseWriter, r *http.Request) { 123 user := s.OAuth.GetMultiAccountUser(r) 124 - pubKeys, err := db.GetPublicKeysForDid(s.Db, user.Active.Did) 125 if err != nil { 126 log.Println(err) 127 } ··· 134 135 func (s *Settings) emailsSettings(w http.ResponseWriter, r *http.Request) { 136 user := s.OAuth.GetMultiAccountUser(r) 137 - emails, err := db.GetAllEmails(s.Db, user.Active.Did) 138 if err != nil { 139 log.Println(err) 140 }
··· 121 122 func (s *Settings) keysSettings(w http.ResponseWriter, r *http.Request) { 123 user := s.OAuth.GetMultiAccountUser(r) 124 + pubKeys, err := db.GetPublicKeysForDid(s.Db, user.Did) 125 if err != nil { 126 log.Println(err) 127 } ··· 134 135 func (s *Settings) emailsSettings(w http.ResponseWriter, r *http.Request) { 136 user := s.OAuth.GetMultiAccountUser(r) 137 + emails, err := db.GetAllEmails(s.Db, user.Did) 138 if err != nil { 139 log.Println(err) 140 }
+34 -34
appview/spindles/spindles.go
··· 59 user := s.OAuth.GetMultiAccountUser(r) 60 all, err := db.GetSpindles( 61 s.Db, 62 - orm.FilterEq("owner", user.Active.Did), 63 ) 64 if err != nil { 65 s.Logger.Error("failed to fetch spindles", "err", err) ··· 78 l := s.Logger.With("handler", "dashboard") 79 80 user := s.OAuth.GetMultiAccountUser(r) 81 - l = l.With("user", user.Active.Did) 82 83 instance := chi.URLParam(r, "instance") 84 if instance == "" { ··· 89 spindles, err := db.GetSpindles( 90 s.Db, 91 orm.FilterEq("instance", instance), 92 - orm.FilterEq("owner", user.Active.Did), 93 orm.FilterIsNot("verified", "null"), 94 ) 95 if err != nil || len(spindles) != 1 { ··· 161 return 162 } 163 l = l.With("instance", instance) 164 - l = l.With("user", user.Active.Did) 165 166 tx, err := s.Db.Begin() 167 if err != nil { ··· 175 }() 176 177 err = db.AddSpindle(tx, models.Spindle{ 178 - Owner: syntax.DID(user.Active.Did), 179 Instance: instance, 180 }) 181 if err != nil { ··· 199 return 200 } 201 202 - ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.SpindleNSID, user.Active.Did, instance) 203 var exCid *string 204 if ex != nil { 205 exCid = ex.Cid ··· 208 // re-announce by registering under same rkey 209 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 210 Collection: tangled.SpindleNSID, 211 - Repo: user.Active.Did, 212 Rkey: instance, 213 Record: &lexutil.LexiconTypeDecoder{ 214 Val: &tangled.Spindle{ ··· 239 } 240 241 // begin verification 242 - err = serververify.RunVerification(r.Context(), instance, user.Active.Did, s.Config.Core.Dev) 243 if err != nil { 244 l.Error("verification failed", "err", err) 245 s.Pages.HxRefresh(w) 246 return 247 } 248 249 - _, err = serververify.MarkSpindleVerified(s.Db, s.Enforcer, instance, user.Active.Did) 250 if err != nil { 251 l.Error("failed to mark verified", "err", err) 252 s.Pages.HxRefresh(w) ··· 276 277 spindles, err := db.GetSpindles( 278 s.Db, 279 - orm.FilterEq("owner", user.Active.Did), 280 orm.FilterEq("instance", instance), 281 ) 282 if err != nil || len(spindles) != 1 { ··· 285 return 286 } 287 288 - if string(spindles[0].Owner) != user.Active.Did { 289 - l.Error("unauthorized", "user", user.Active.Did, "owner", spindles[0].Owner) 290 s.Pages.Notice(w, noticeId, "Failed to delete spindle, unauthorized deletion attempt.") 291 return 292 } ··· 305 // remove spindle members first 306 err = db.RemoveSpindleMember( 307 tx, 308 - orm.FilterEq("did", user.Active.Did), 309 orm.FilterEq("instance", instance), 310 ) 311 if err != nil { ··· 316 317 err = db.DeleteSpindle( 318 tx, 319 - orm.FilterEq("owner", user.Active.Did), 320 orm.FilterEq("instance", instance), 321 ) 322 if err != nil { ··· 344 345 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 346 Collection: tangled.SpindleNSID, 347 - Repo: user.Active.Did, 348 Rkey: instance, 349 }) 350 if err != nil { ··· 392 return 393 } 394 l = l.With("instance", instance) 395 - l = l.With("user", user.Active.Did) 396 397 spindles, err := db.GetSpindles( 398 s.Db, 399 - orm.FilterEq("owner", user.Active.Did), 400 orm.FilterEq("instance", instance), 401 ) 402 if err != nil || len(spindles) != 1 { ··· 405 return 406 } 407 408 - if string(spindles[0].Owner) != user.Active.Did { 409 - l.Error("unauthorized", "user", user.Active.Did, "owner", spindles[0].Owner) 410 s.Pages.Notice(w, noticeId, "Failed to verify spindle, unauthorized verification attempt.") 411 return 412 } 413 414 // begin verification 415 - err = serververify.RunVerification(r.Context(), instance, user.Active.Did, s.Config.Core.Dev) 416 if err != nil { 417 l.Error("verification failed", "err", err) 418 ··· 430 return 431 } 432 433 - rowId, err := serververify.MarkSpindleVerified(s.Db, s.Enforcer, instance, user.Active.Did) 434 if err != nil { 435 l.Error("failed to mark verified", "err", err) 436 s.Pages.Notice(w, noticeId, err.Error()) ··· 468 return 469 } 470 l = l.With("instance", instance) 471 - l = l.With("user", user.Active.Did) 472 473 spindles, err := db.GetSpindles( 474 s.Db, 475 - orm.FilterEq("owner", user.Active.Did), 476 orm.FilterEq("instance", instance), 477 ) 478 if err != nil || len(spindles) != 1 { ··· 487 s.Pages.Notice(w, noticeId, defaultErr) 488 } 489 490 - if string(spindles[0].Owner) != user.Active.Did { 491 - l.Error("unauthorized", "user", user.Active.Did, "owner", spindles[0].Owner) 492 s.Pages.Notice(w, noticeId, "Failed to add member, unauthorized attempt.") 493 return 494 } ··· 537 538 // add member to db 539 if err = db.AddSpindleMember(tx, models.SpindleMember{ 540 - Did: syntax.DID(user.Active.Did), 541 Rkey: rkey, 542 Instance: instance, 543 Subject: memberId.DID, ··· 555 556 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 557 Collection: tangled.SpindleMemberNSID, 558 - Repo: user.Active.Did, 559 Rkey: rkey, 560 Record: &lexutil.LexiconTypeDecoder{ 561 Val: &tangled.SpindleMember{ ··· 604 return 605 } 606 l = l.With("instance", instance) 607 - l = l.With("user", user.Active.Did) 608 609 spindles, err := db.GetSpindles( 610 s.Db, 611 - orm.FilterEq("owner", user.Active.Did), 612 orm.FilterEq("instance", instance), 613 ) 614 if err != nil || len(spindles) != 1 { ··· 617 return 618 } 619 620 - if string(spindles[0].Owner) != user.Active.Did { 621 - l.Error("unauthorized", "user", user.Active.Did, "owner", spindles[0].Owner) 622 s.Pages.Notice(w, noticeId, "Failed to remove member, unauthorized attempt.") 623 return 624 } ··· 653 // get the record from the DB first: 654 members, err := db.GetSpindleMembers( 655 s.Db, 656 - orm.FilterEq("did", user.Active.Did), 657 orm.FilterEq("instance", instance), 658 orm.FilterEq("subject", memberId.DID), 659 ) ··· 666 // remove from db 667 if err = db.RemoveSpindleMember( 668 tx, 669 - orm.FilterEq("did", user.Active.Did), 670 orm.FilterEq("instance", instance), 671 orm.FilterEq("subject", memberId.DID), 672 ); err != nil { ··· 692 // remove from pds 693 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 694 Collection: tangled.SpindleMemberNSID, 695 - Repo: user.Active.Did, 696 Rkey: members[0].Rkey, 697 }) 698 if err != nil {
··· 59 user := s.OAuth.GetMultiAccountUser(r) 60 all, err := db.GetSpindles( 61 s.Db, 62 + orm.FilterEq("owner", user.Did), 63 ) 64 if err != nil { 65 s.Logger.Error("failed to fetch spindles", "err", err) ··· 78 l := s.Logger.With("handler", "dashboard") 79 80 user := s.OAuth.GetMultiAccountUser(r) 81 + l = l.With("user", user.Did) 82 83 instance := chi.URLParam(r, "instance") 84 if instance == "" { ··· 89 spindles, err := db.GetSpindles( 90 s.Db, 91 orm.FilterEq("instance", instance), 92 + orm.FilterEq("owner", user.Did), 93 orm.FilterIsNot("verified", "null"), 94 ) 95 if err != nil || len(spindles) != 1 { ··· 161 return 162 } 163 l = l.With("instance", instance) 164 + l = l.With("user", user.Did) 165 166 tx, err := s.Db.Begin() 167 if err != nil { ··· 175 }() 176 177 err = db.AddSpindle(tx, models.Spindle{ 178 + Owner: syntax.DID(user.Did), 179 Instance: instance, 180 }) 181 if err != nil { ··· 199 return 200 } 201 202 + ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.SpindleNSID, user.Did, instance) 203 var exCid *string 204 if ex != nil { 205 exCid = ex.Cid ··· 208 // re-announce by registering under same rkey 209 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 210 Collection: tangled.SpindleNSID, 211 + Repo: user.Did, 212 Rkey: instance, 213 Record: &lexutil.LexiconTypeDecoder{ 214 Val: &tangled.Spindle{ ··· 239 } 240 241 // begin verification 242 + err = serververify.RunVerification(r.Context(), instance, user.Did, s.Config.Core.Dev) 243 if err != nil { 244 l.Error("verification failed", "err", err) 245 s.Pages.HxRefresh(w) 246 return 247 } 248 249 + _, err = serververify.MarkSpindleVerified(s.Db, s.Enforcer, instance, user.Did) 250 if err != nil { 251 l.Error("failed to mark verified", "err", err) 252 s.Pages.HxRefresh(w) ··· 276 277 spindles, err := db.GetSpindles( 278 s.Db, 279 + orm.FilterEq("owner", user.Did), 280 orm.FilterEq("instance", instance), 281 ) 282 if err != nil || len(spindles) != 1 { ··· 285 return 286 } 287 288 + if string(spindles[0].Owner) != user.Did { 289 + l.Error("unauthorized", "user", user.Did, "owner", spindles[0].Owner) 290 s.Pages.Notice(w, noticeId, "Failed to delete spindle, unauthorized deletion attempt.") 291 return 292 } ··· 305 // remove spindle members first 306 err = db.RemoveSpindleMember( 307 tx, 308 + orm.FilterEq("did", user.Did), 309 orm.FilterEq("instance", instance), 310 ) 311 if err != nil { ··· 316 317 err = db.DeleteSpindle( 318 tx, 319 + orm.FilterEq("owner", user.Did), 320 orm.FilterEq("instance", instance), 321 ) 322 if err != nil { ··· 344 345 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 346 Collection: tangled.SpindleNSID, 347 + Repo: user.Did, 348 Rkey: instance, 349 }) 350 if err != nil { ··· 392 return 393 } 394 l = l.With("instance", instance) 395 + l = l.With("user", user.Did) 396 397 spindles, err := db.GetSpindles( 398 s.Db, 399 + orm.FilterEq("owner", user.Did), 400 orm.FilterEq("instance", instance), 401 ) 402 if err != nil || len(spindles) != 1 { ··· 405 return 406 } 407 408 + if string(spindles[0].Owner) != user.Did { 409 + l.Error("unauthorized", "user", user.Did, "owner", spindles[0].Owner) 410 s.Pages.Notice(w, noticeId, "Failed to verify spindle, unauthorized verification attempt.") 411 return 412 } 413 414 // begin verification 415 + err = serververify.RunVerification(r.Context(), instance, user.Did, s.Config.Core.Dev) 416 if err != nil { 417 l.Error("verification failed", "err", err) 418 ··· 430 return 431 } 432 433 + rowId, err := serververify.MarkSpindleVerified(s.Db, s.Enforcer, instance, user.Did) 434 if err != nil { 435 l.Error("failed to mark verified", "err", err) 436 s.Pages.Notice(w, noticeId, err.Error()) ··· 468 return 469 } 470 l = l.With("instance", instance) 471 + l = l.With("user", user.Did) 472 473 spindles, err := db.GetSpindles( 474 s.Db, 475 + orm.FilterEq("owner", user.Did), 476 orm.FilterEq("instance", instance), 477 ) 478 if err != nil || len(spindles) != 1 { ··· 487 s.Pages.Notice(w, noticeId, defaultErr) 488 } 489 490 + if string(spindles[0].Owner) != user.Did { 491 + l.Error("unauthorized", "user", user.Did, "owner", spindles[0].Owner) 492 s.Pages.Notice(w, noticeId, "Failed to add member, unauthorized attempt.") 493 return 494 } ··· 537 538 // add member to db 539 if err = db.AddSpindleMember(tx, models.SpindleMember{ 540 + Did: syntax.DID(user.Did), 541 Rkey: rkey, 542 Instance: instance, 543 Subject: memberId.DID, ··· 555 556 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 557 Collection: tangled.SpindleMemberNSID, 558 + Repo: user.Did, 559 Rkey: rkey, 560 Record: &lexutil.LexiconTypeDecoder{ 561 Val: &tangled.SpindleMember{ ··· 604 return 605 } 606 l = l.With("instance", instance) 607 + l = l.With("user", user.Did) 608 609 spindles, err := db.GetSpindles( 610 s.Db, 611 + orm.FilterEq("owner", user.Did), 612 orm.FilterEq("instance", instance), 613 ) 614 if err != nil || len(spindles) != 1 { ··· 617 return 618 } 619 620 + if string(spindles[0].Owner) != user.Did { 621 + l.Error("unauthorized", "user", user.Did, "owner", spindles[0].Owner) 622 s.Pages.Notice(w, noticeId, "Failed to remove member, unauthorized attempt.") 623 return 624 } ··· 653 // get the record from the DB first: 654 members, err := db.GetSpindleMembers( 655 s.Db, 656 + orm.FilterEq("did", user.Did), 657 orm.FilterEq("instance", instance), 658 orm.FilterEq("subject", memberId.DID), 659 ) ··· 666 // remove from db 667 if err = db.RemoveSpindleMember( 668 tx, 669 + orm.FilterEq("did", user.Did), 670 orm.FilterEq("instance", instance), 671 orm.FilterEq("subject", memberId.DID), 672 ); err != nil { ··· 692 // remove from pds 693 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 694 Collection: tangled.SpindleMemberNSID, 695 + Repo: user.Did, 696 Rkey: members[0].Rkey, 697 }) 698 if err != nil {
+1 -1
appview/state/accounts.go
··· 41 } 42 43 currentUser := s.oauth.GetMultiAccountUser(r) 44 - isCurrentAccount := currentUser != nil && currentUser.Active.Did == did 45 46 var remainingAccounts []string 47 if currentUser != nil {
··· 41 } 42 43 currentUser := s.oauth.GetMultiAccountUser(r) 44 + isCurrentAccount := currentUser != nil && currentUser.Did == did 45 46 var remainingAccounts []string 47 if currentUser != nil {
+6 -6
appview/state/follow.go
··· 29 return 30 } 31 32 - if currentUser.Active.Did == subjectIdent.DID.String() { 33 log.Println("cant follow or unfollow yourself") 34 return 35 } ··· 46 rkey := tid.TID() 47 resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 48 Collection: tangled.GraphFollowNSID, 49 - Repo: currentUser.Active.Did, 50 Rkey: rkey, 51 Record: &lexutil.LexiconTypeDecoder{ 52 Val: &tangled.GraphFollow{ ··· 62 log.Println("created atproto record: ", resp.Uri) 63 64 follow := &models.Follow{ 65 - UserDid: currentUser.Active.Did, 66 SubjectDid: subjectIdent.DID.String(), 67 Rkey: rkey, 68 } ··· 89 return 90 case http.MethodDelete: 91 // find the record in the db 92 - follow, err := db.GetFollow(s.db, currentUser.Active.Did, subjectIdent.DID.String()) 93 if err != nil { 94 log.Println("failed to get follow relationship") 95 return ··· 97 98 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 99 Collection: tangled.GraphFollowNSID, 100 - Repo: currentUser.Active.Did, 101 Rkey: follow.Rkey, 102 }) 103 ··· 106 return 107 } 108 109 - err = db.DeleteFollowByRkey(s.db, currentUser.Active.Did, follow.Rkey) 110 if err != nil { 111 log.Println("failed to delete follow from DB") 112 // this is not an issue, the firehose event might have already done this
··· 29 return 30 } 31 32 + if currentUser.Did == subjectIdent.DID.String() { 33 log.Println("cant follow or unfollow yourself") 34 return 35 } ··· 46 rkey := tid.TID() 47 resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 48 Collection: tangled.GraphFollowNSID, 49 + Repo: currentUser.Did, 50 Rkey: rkey, 51 Record: &lexutil.LexiconTypeDecoder{ 52 Val: &tangled.GraphFollow{ ··· 62 log.Println("created atproto record: ", resp.Uri) 63 64 follow := &models.Follow{ 65 + UserDid: currentUser.Did, 66 SubjectDid: subjectIdent.DID.String(), 67 Rkey: rkey, 68 } ··· 89 return 90 case http.MethodDelete: 91 // find the record in the db 92 + follow, err := db.GetFollow(s.db, currentUser.Did, subjectIdent.DID.String()) 93 if err != nil { 94 log.Println("failed to get follow relationship") 95 return ··· 97 98 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 99 Collection: tangled.GraphFollowNSID, 100 + Repo: currentUser.Did, 101 Rkey: follow.Rkey, 102 }) 103 ··· 106 return 107 } 108 109 + err = db.DeleteFollowByRkey(s.db, currentUser.Did, follow.Rkey) 110 if err != nil { 111 log.Println("failed to delete follow from DB") 112 // this is not an issue, the firehose event might have already done this
+1 -1
appview/state/login.go
··· 74 return 75 } 76 77 - currentDid := currentUser.Active.Did 78 79 var remainingAccounts []string 80 for _, acc := range currentUser.Accounts {
··· 74 return 75 } 76 77 + currentDid := currentUser.Did 78 79 var remainingAccounts []string 80 for _, acc := range currentUser.Accounts {
+19 -19
appview/state/profile.go
··· 80 loggedInUser := s.oauth.GetMultiAccountUser(r) 81 followStatus := models.IsNotFollowing 82 if loggedInUser != nil { 83 - followStatus = db.GetFollowStatus(s.db, loggedInUser.Active.Did, did) 84 } 85 86 now := time.Now() ··· 305 306 loggedInUserFollowing := make(map[string]struct{}) 307 if loggedInUser != nil { 308 - following, err := db.GetFollowing(s.db, loggedInUser.Active.Did) 309 if err != nil { 310 - l.Error("failed to get follow list", "err", err, "loggedInUser", loggedInUser.Active.Did) 311 return &params, err 312 } 313 loggedInUserFollowing = make(map[string]struct{}, len(following)) ··· 322 followStatus := models.IsNotFollowing 323 if _, exists := loggedInUserFollowing[did]; exists { 324 followStatus = models.IsFollowing 325 - } else if loggedInUser != nil && loggedInUser.Active.Did == did { 326 followStatus = models.IsSelf 327 } 328 ··· 528 return 529 } 530 531 - profile, err := db.GetProfile(s.db, user.Active.Did) 532 if err != nil { 533 - log.Printf("getting profile data for %s: %s", user.Active.Did, err) 534 } 535 536 profile.Description = r.FormValue("description") ··· 576 return 577 } 578 579 - profile, err := db.GetProfile(s.db, user.Active.Did) 580 if err != nil { 581 - log.Printf("getting profile data for %s: %s", user.Active.Did, err) 582 } 583 584 i := 0 ··· 633 vanityStats = append(vanityStats, string(v.Kind)) 634 } 635 636 - ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.ActorProfileNSID, user.Active.Did, "self") 637 var cid *string 638 if ex != nil { 639 cid = ex.Cid ··· 641 642 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 643 Collection: tangled.ActorProfileNSID, 644 - Repo: user.Active.Did, 645 Rkey: "self", 646 Record: &lexutil.LexiconTypeDecoder{ 647 Val: &tangled.ActorProfile{ ··· 670 671 s.notifier.UpdateProfile(r.Context(), profile) 672 673 - s.pages.HxRedirect(w, "/"+user.Active.Did) 674 } 675 676 func (s *State) EditBioFragment(w http.ResponseWriter, r *http.Request) { 677 user := s.oauth.GetMultiAccountUser(r) 678 679 - profile, err := db.GetProfile(s.db, user.Active.Did) 680 if err != nil { 681 - log.Printf("getting profile data for %s: %s", user.Active.Did, err) 682 } 683 684 s.pages.EditBioFragment(w, pages.EditBioParams{ ··· 690 func (s *State) EditPinsFragment(w http.ResponseWriter, r *http.Request) { 691 user := s.oauth.GetMultiAccountUser(r) 692 693 - profile, err := db.GetProfile(s.db, user.Active.Did) 694 if err != nil { 695 - log.Printf("getting profile data for %s: %s", user.Active.Did, err) 696 } 697 698 - repos, err := db.GetRepos(s.db, 0, orm.FilterEq("did", user.Active.Did)) 699 if err != nil { 700 - log.Printf("getting repos for %s: %s", user.Active.Did, err) 701 } 702 703 - collaboratingRepos, err := db.CollaboratingIn(s.db, user.Active.Did) 704 if err != nil { 705 - log.Printf("getting collaborating repos for %s: %s", user.Active.Did, err) 706 } 707 708 allRepos := []pages.PinnedRepo{}
··· 80 loggedInUser := s.oauth.GetMultiAccountUser(r) 81 followStatus := models.IsNotFollowing 82 if loggedInUser != nil { 83 + followStatus = db.GetFollowStatus(s.db, loggedInUser.Did, did) 84 } 85 86 now := time.Now() ··· 305 306 loggedInUserFollowing := make(map[string]struct{}) 307 if loggedInUser != nil { 308 + following, err := db.GetFollowing(s.db, loggedInUser.Did) 309 if err != nil { 310 + l.Error("failed to get follow list", "err", err, "loggedInUser", loggedInUser.Did) 311 return &params, err 312 } 313 loggedInUserFollowing = make(map[string]struct{}, len(following)) ··· 322 followStatus := models.IsNotFollowing 323 if _, exists := loggedInUserFollowing[did]; exists { 324 followStatus = models.IsFollowing 325 + } else if loggedInUser != nil && loggedInUser.Did == did { 326 followStatus = models.IsSelf 327 } 328 ··· 528 return 529 } 530 531 + profile, err := db.GetProfile(s.db, user.Did) 532 if err != nil { 533 + log.Printf("getting profile data for %s: %s", user.Did, err) 534 } 535 536 profile.Description = r.FormValue("description") ··· 576 return 577 } 578 579 + profile, err := db.GetProfile(s.db, user.Did) 580 if err != nil { 581 + log.Printf("getting profile data for %s: %s", user.Did, err) 582 } 583 584 i := 0 ··· 633 vanityStats = append(vanityStats, string(v.Kind)) 634 } 635 636 + ex, _ := comatproto.RepoGetRecord(r.Context(), client, "", tangled.ActorProfileNSID, user.Did, "self") 637 var cid *string 638 if ex != nil { 639 cid = ex.Cid ··· 641 642 _, err = comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 643 Collection: tangled.ActorProfileNSID, 644 + Repo: user.Did, 645 Rkey: "self", 646 Record: &lexutil.LexiconTypeDecoder{ 647 Val: &tangled.ActorProfile{ ··· 670 671 s.notifier.UpdateProfile(r.Context(), profile) 672 673 + s.pages.HxRedirect(w, "/"+user.Did) 674 } 675 676 func (s *State) EditBioFragment(w http.ResponseWriter, r *http.Request) { 677 user := s.oauth.GetMultiAccountUser(r) 678 679 + profile, err := db.GetProfile(s.db, user.Did) 680 if err != nil { 681 + log.Printf("getting profile data for %s: %s", user.Did, err) 682 } 683 684 s.pages.EditBioFragment(w, pages.EditBioParams{ ··· 690 func (s *State) EditPinsFragment(w http.ResponseWriter, r *http.Request) { 691 user := s.oauth.GetMultiAccountUser(r) 692 693 + profile, err := db.GetProfile(s.db, user.Did) 694 if err != nil { 695 + log.Printf("getting profile data for %s: %s", user.Did, err) 696 } 697 698 + repos, err := db.GetRepos(s.db, 0, orm.FilterEq("did", user.Did)) 699 if err != nil { 700 + log.Printf("getting repos for %s: %s", user.Did, err) 701 } 702 703 + collaboratingRepos, err := db.CollaboratingIn(s.db, user.Did) 704 if err != nil { 705 + log.Printf("getting collaborating repos for %s: %s", user.Did, err) 706 } 707 708 allRepos := []pages.PinnedRepo{}
+6 -6
appview/state/reaction.go
··· 49 rkey := tid.TID() 50 resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 51 Collection: tangled.FeedReactionNSID, 52 - Repo: currentUser.Active.Did, 53 Rkey: rkey, 54 Record: &lexutil.LexiconTypeDecoder{ 55 Val: &tangled.FeedReaction{ ··· 64 return 65 } 66 67 - err = db.AddReaction(s.db, currentUser.Active.Did, subjectUri, reactionKind, rkey) 68 if err != nil { 69 log.Println("failed to react", err) 70 return ··· 87 88 return 89 case http.MethodDelete: 90 - reaction, err := db.GetReaction(s.db, currentUser.Active.Did, subjectUri, reactionKind) 91 if err != nil { 92 - log.Println("failed to get reaction relationship for", currentUser.Active.Did, subjectUri) 93 return 94 } 95 96 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 97 Collection: tangled.FeedReactionNSID, 98 - Repo: currentUser.Active.Did, 99 Rkey: reaction.Rkey, 100 }) 101 ··· 104 return 105 } 106 107 - err = db.DeleteReactionByRkey(s.db, currentUser.Active.Did, reaction.Rkey) 108 if err != nil { 109 log.Println("failed to delete reaction from DB") 110 // this is not an issue, the firehose event might have already done this
··· 49 rkey := tid.TID() 50 resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 51 Collection: tangled.FeedReactionNSID, 52 + Repo: currentUser.Did, 53 Rkey: rkey, 54 Record: &lexutil.LexiconTypeDecoder{ 55 Val: &tangled.FeedReaction{ ··· 64 return 65 } 66 67 + err = db.AddReaction(s.db, currentUser.Did, subjectUri, reactionKind, rkey) 68 if err != nil { 69 log.Println("failed to react", err) 70 return ··· 87 88 return 89 case http.MethodDelete: 90 + reaction, err := db.GetReaction(s.db, currentUser.Did, subjectUri, reactionKind) 91 if err != nil { 92 + log.Println("failed to get reaction relationship for", currentUser.Did, subjectUri) 93 return 94 } 95 96 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 97 Collection: tangled.FeedReactionNSID, 98 + Repo: currentUser.Did, 99 Rkey: reaction.Rkey, 100 }) 101 ··· 104 return 105 } 106 107 + err = db.DeleteReactionByRkey(s.db, currentUser.Did, reaction.Rkey) 108 if err != nil { 109 log.Println("failed to delete reaction from DB") 110 // this is not an issue, the firehose event might have already done this
+5 -5
appview/state/star.go
··· 42 rkey := tid.TID() 43 resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 44 Collection: tangled.FeedStarNSID, 45 - Repo: currentUser.Active.Did, 46 Rkey: rkey, 47 Record: &lexutil.LexiconTypeDecoder{ 48 Val: &tangled.FeedStar{ ··· 57 log.Println("created atproto record: ", resp.Uri) 58 59 star := &models.Star{ 60 - Did: currentUser.Active.Did, 61 RepoAt: subjectUri, 62 Rkey: rkey, 63 } ··· 84 return 85 case http.MethodDelete: 86 // find the record in the db 87 - star, err := db.GetStar(s.db, currentUser.Active.Did, subjectUri) 88 if err != nil { 89 log.Println("failed to get star relationship") 90 return ··· 92 93 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 94 Collection: tangled.FeedStarNSID, 95 - Repo: currentUser.Active.Did, 96 Rkey: star.Rkey, 97 }) 98 ··· 101 return 102 } 103 104 - err = db.DeleteStarByRkey(s.db, currentUser.Active.Did, star.Rkey) 105 if err != nil { 106 log.Println("failed to delete star from DB") 107 // this is not an issue, the firehose event might have already done this
··· 42 rkey := tid.TID() 43 resp, err := comatproto.RepoPutRecord(r.Context(), client, &comatproto.RepoPutRecord_Input{ 44 Collection: tangled.FeedStarNSID, 45 + Repo: currentUser.Did, 46 Rkey: rkey, 47 Record: &lexutil.LexiconTypeDecoder{ 48 Val: &tangled.FeedStar{ ··· 57 log.Println("created atproto record: ", resp.Uri) 58 59 star := &models.Star{ 60 + Did: currentUser.Did, 61 RepoAt: subjectUri, 62 Rkey: rkey, 63 } ··· 84 return 85 case http.MethodDelete: 86 // find the record in the db 87 + star, err := db.GetStar(s.db, currentUser.Did, subjectUri) 88 if err != nil { 89 log.Println("failed to get star relationship") 90 return ··· 92 93 _, err = comatproto.RepoDeleteRecord(r.Context(), client, &comatproto.RepoDeleteRecord_Input{ 94 Collection: tangled.FeedStarNSID, 95 + Repo: currentUser.Did, 96 Rkey: star.Rkey, 97 }) 98 ··· 101 return 102 } 103 104 + err = db.DeleteStarByRkey(s.db, currentUser.Did, star.Rkey) 105 if err != nil { 106 log.Println("failed to delete star from DB") 107 // this is not an issue, the firehose event might have already done this
+13 -13
appview/state/state.go
··· 249 250 var userDid string 251 if user != nil { 252 - userDid = user.Active.Did 253 } 254 timeline, err := db.MakeTimeline(s.db, 50, userDid, filtered) 255 if err != nil { ··· 284 } 285 286 l := s.logger.With("handler", "UpgradeBanner") 287 - l = l.With("did", user.Active.Did) 288 289 regs, err := db.GetRegistrations( 290 s.db, 291 - orm.FilterEq("did", user.Active.Did), 292 orm.FilterEq("needs_upgrade", 1), 293 ) 294 if err != nil { ··· 297 298 spindles, err := db.GetSpindles( 299 s.db, 300 - orm.FilterEq("owner", user.Active.Did), 301 orm.FilterEq("needs_upgrade", 1), 302 ) 303 if err != nil { ··· 412 switch r.Method { 413 case http.MethodGet: 414 user := s.oauth.GetMultiAccountUser(r) 415 - knots, err := s.enforcer.GetKnotsForUser(user.Active.Did) 416 if err != nil { 417 s.pages.Notice(w, "repo", "Invalid user account.") 418 return ··· 427 l := s.logger.With("handler", "NewRepo") 428 429 user := s.oauth.GetMultiAccountUser(r) 430 - l = l.With("did", user.Active.Did) 431 432 // form validation 433 domain := r.FormValue("domain") ··· 459 description := r.FormValue("description") 460 461 // ACL validation 462 - ok, err := s.enforcer.E.Enforce(user.Active.Did, domain, domain, "repo:create") 463 if err != nil || !ok { 464 l.Info("unauthorized") 465 s.pages.Notice(w, "repo", "You do not have permission to create a repo in this knot.") ··· 469 // Check for existing repos 470 existingRepo, err := db.GetRepo( 471 s.db, 472 - orm.FilterEq("did", user.Active.Did), 473 orm.FilterEq("name", repoName), 474 ) 475 if err == nil && existingRepo != nil { ··· 481 // create atproto record for this repo 482 rkey := tid.TID() 483 repo := &models.Repo{ 484 - Did: user.Active.Did, 485 Name: repoName, 486 Knot: domain, 487 Rkey: rkey, ··· 500 501 atresp, err := comatproto.RepoPutRecord(r.Context(), atpClient, &comatproto.RepoPutRecord_Input{ 502 Collection: tangled.RepoNSID, 503 - Repo: user.Active.Did, 504 Rkey: rkey, 505 Record: &lexutil.LexiconTypeDecoder{ 506 Val: &record, ··· 577 } 578 579 // acls 580 - p, _ := securejoin.SecureJoin(user.Active.Did, repoName) 581 - err = s.enforcer.AddRepo(user.Active.Did, domain, p) 582 if err != nil { 583 l.Error("acl setup failed", "err", err) 584 s.pages.Notice(w, "repo", "Failed to set up repository permissions.") ··· 603 aturi = "" 604 605 s.notifier.NewRepo(r.Context(), repo) 606 - s.pages.HxLocation(w, fmt.Sprintf("/%s/%s", user.Active.Did, repoName)) 607 } 608 } 609
··· 249 250 var userDid string 251 if user != nil { 252 + userDid = user.Did 253 } 254 timeline, err := db.MakeTimeline(s.db, 50, userDid, filtered) 255 if err != nil { ··· 284 } 285 286 l := s.logger.With("handler", "UpgradeBanner") 287 + l = l.With("did", user.Did) 288 289 regs, err := db.GetRegistrations( 290 s.db, 291 + orm.FilterEq("did", user.Did), 292 orm.FilterEq("needs_upgrade", 1), 293 ) 294 if err != nil { ··· 297 298 spindles, err := db.GetSpindles( 299 s.db, 300 + orm.FilterEq("owner", user.Did), 301 orm.FilterEq("needs_upgrade", 1), 302 ) 303 if err != nil { ··· 412 switch r.Method { 413 case http.MethodGet: 414 user := s.oauth.GetMultiAccountUser(r) 415 + knots, err := s.enforcer.GetKnotsForUser(user.Did) 416 if err != nil { 417 s.pages.Notice(w, "repo", "Invalid user account.") 418 return ··· 427 l := s.logger.With("handler", "NewRepo") 428 429 user := s.oauth.GetMultiAccountUser(r) 430 + l = l.With("did", user.Did) 431 432 // form validation 433 domain := r.FormValue("domain") ··· 459 description := r.FormValue("description") 460 461 // ACL validation 462 + ok, err := s.enforcer.E.Enforce(user.Did, domain, domain, "repo:create") 463 if err != nil || !ok { 464 l.Info("unauthorized") 465 s.pages.Notice(w, "repo", "You do not have permission to create a repo in this knot.") ··· 469 // Check for existing repos 470 existingRepo, err := db.GetRepo( 471 s.db, 472 + orm.FilterEq("did", user.Did), 473 orm.FilterEq("name", repoName), 474 ) 475 if err == nil && existingRepo != nil { ··· 481 // create atproto record for this repo 482 rkey := tid.TID() 483 repo := &models.Repo{ 484 + Did: user.Did, 485 Name: repoName, 486 Knot: domain, 487 Rkey: rkey, ··· 500 501 atresp, err := comatproto.RepoPutRecord(r.Context(), atpClient, &comatproto.RepoPutRecord_Input{ 502 Collection: tangled.RepoNSID, 503 + Repo: user.Did, 504 Rkey: rkey, 505 Record: &lexutil.LexiconTypeDecoder{ 506 Val: &record, ··· 577 } 578 579 // acls 580 + p, _ := securejoin.SecureJoin(user.Did, repoName) 581 + err = s.enforcer.AddRepo(user.Did, domain, p) 582 if err != nil { 583 l.Error("acl setup failed", "err", err) 584 s.pages.Notice(w, "repo", "Failed to set up repository permissions.") ··· 603 aturi = "" 604 605 s.notifier.NewRepo(r.Context(), repo) 606 + s.pages.HxLocation(w, fmt.Sprintf("/%s/%s", user.Did, repoName)) 607 } 608 } 609
+12 -12
appview/strings/strings.go
··· 156 user := s.OAuth.GetMultiAccountUser(r) 157 isStarred := false 158 if user != nil { 159 - isStarred = db.GetStarStatus(s.Db, user.Active.Did, string.AtUri()) 160 } 161 162 s.Pages.SingleString(w, pages.SingleStringParams{ ··· 216 first := all[0] 217 218 // verify that the logged in user owns this string 219 - if user.Active.Did != id.DID.String() { 220 - l.Error("unauthorized request", "expected", id.DID, "got", user.Active.Did) 221 w.WriteHeader(http.StatusUnauthorized) 222 return 223 } ··· 299 s.Notifier.EditString(r.Context(), &entry) 300 301 // if that went okay, redir to the string 302 - s.Pages.HxRedirect(w, "/strings/"+user.Active.Did+"/"+entry.Rkey) 303 } 304 305 } ··· 335 description := r.FormValue("description") 336 337 string := models.String{ 338 - Did: syntax.DID(user.Active.Did), 339 Rkey: tid.TID(), 340 Filename: filename, 341 Description: description, ··· 353 354 resp, err := comatproto.RepoPutRecord(r.Context(), client, &atproto.RepoPutRecord_Input{ 355 Collection: tangled.StringNSID, 356 - Repo: user.Active.Did, 357 Rkey: string.Rkey, 358 Record: &lexutil.LexiconTypeDecoder{ 359 Val: &record, ··· 375 s.Notifier.NewString(r.Context(), &string) 376 377 // successful 378 - s.Pages.HxRedirect(w, "/strings/"+user.Active.Did+"/"+string.Rkey) 379 } 380 } 381 ··· 402 return 403 } 404 405 - if user.Active.Did != id.DID.String() { 406 - fail("You cannot delete this string", fmt.Errorf("unauthorized deletion, %s != %s", user.Active.Did, id.DID.String())) 407 return 408 } 409 410 if err := db.DeleteString( 411 s.Db, 412 - orm.FilterEq("did", user.Active.Did), 413 orm.FilterEq("rkey", rkey), 414 ); err != nil { 415 fail("Failed to delete string.", err) 416 return 417 } 418 419 - s.Notifier.DeleteString(r.Context(), user.Active.Did, rkey) 420 421 - s.Pages.HxRedirect(w, "/strings/"+user.Active.Did) 422 } 423 424 func (s *Strings) comment(w http.ResponseWriter, r *http.Request) {
··· 156 user := s.OAuth.GetMultiAccountUser(r) 157 isStarred := false 158 if user != nil { 159 + isStarred = db.GetStarStatus(s.Db, user.Did, string.AtUri()) 160 } 161 162 s.Pages.SingleString(w, pages.SingleStringParams{ ··· 216 first := all[0] 217 218 // verify that the logged in user owns this string 219 + if user.Did != id.DID.String() { 220 + l.Error("unauthorized request", "expected", id.DID, "got", user.Did) 221 w.WriteHeader(http.StatusUnauthorized) 222 return 223 } ··· 299 s.Notifier.EditString(r.Context(), &entry) 300 301 // if that went okay, redir to the string 302 + s.Pages.HxRedirect(w, "/strings/"+user.Did+"/"+entry.Rkey) 303 } 304 305 } ··· 335 description := r.FormValue("description") 336 337 string := models.String{ 338 + Did: syntax.DID(user.Did), 339 Rkey: tid.TID(), 340 Filename: filename, 341 Description: description, ··· 353 354 resp, err := comatproto.RepoPutRecord(r.Context(), client, &atproto.RepoPutRecord_Input{ 355 Collection: tangled.StringNSID, 356 + Repo: user.Did, 357 Rkey: string.Rkey, 358 Record: &lexutil.LexiconTypeDecoder{ 359 Val: &record, ··· 375 s.Notifier.NewString(r.Context(), &string) 376 377 // successful 378 + s.Pages.HxRedirect(w, "/strings/"+user.Did+"/"+string.Rkey) 379 } 380 } 381 ··· 402 return 403 } 404 405 + if user.Did != id.DID.String() { 406 + fail("You cannot delete this string", fmt.Errorf("unauthorized deletion, %s != %s", user.Did, id.DID.String())) 407 return 408 } 409 410 if err := db.DeleteString( 411 s.Db, 412 + orm.FilterEq("did", user.Did), 413 orm.FilterEq("rkey", rkey), 414 ); err != nil { 415 fail("Failed to delete string.", err) 416 return 417 } 418 419 + s.Notifier.DeleteString(r.Context(), user.Did, rkey) 420 421 + s.Pages.HxRedirect(w, "/strings/"+user.Did) 422 } 423 424 func (s *Strings) comment(w http.ResponseWriter, r *http.Request) {

History

3 rounds 0 comments
sign up or login to add to the discussion
1 commit
expand
appview: remove oauth.User type
2/3 failed, 1/3 success
expand
merge conflicts detected
expand
  • appview/pages/templates/user/login.html:33
  • appview/state/profile.go:817
  • appview/pages/templates/user/login.html:31
  • appview/pages/templates/user/login.html:93
  • appview/repo/artifact.go:251
  • appview/state/profile.go:528
expand 0 comments
1 commit
expand
appview: remove oauth.User type
2/3 failed, 1/3 success
expand
expand 0 comments
boltless.me submitted #0
1 commit
expand
appview: remove oauth.User type
2/3 failed, 1/3 success
expand
expand 0 comments