this repo has no description
1package issue
2
3import (
4 "context"
5
6 "github.com/bluesky-social/indigo/atproto/syntax"
7 "tangled.org/core/appview/db"
8 "tangled.org/core/appview/models"
9 "tangled.org/core/appview/pages/repoinfo"
10 "tangled.org/core/appview/session"
11 "tangled.org/core/orm"
12)
13
14func (s *Service) CloseIssue(ctx context.Context, issue *models.Issue) error {
15 l := s.logger.With("method", "CloseIssue")
16 sess := session.FromContext(ctx)
17 if sess == nil {
18 l.Error("user session is missing in context")
19 return ErrUnAuthenticated
20 }
21 sessDid := sess.Data.AccountDID
22 l = l.With("did", sessDid)
23
24 // TODO: make this more granular
25 roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(sessDid.String(), issue.Repo.Knot, issue.Repo.DidSlashRepo())}
26 isRepoOwner := roles.IsOwner()
27 isCollaborator := roles.IsCollaborator()
28 isIssueOwner := sessDid == syntax.DID(issue.Did)
29 if !(isRepoOwner || isCollaborator || isIssueOwner) {
30 l.Error("user is not authorized")
31 return ErrForbidden
32 }
33
34 err := db.CloseIssues(
35 s.db,
36 orm.FilterEq("id", issue.Id),
37 )
38 if err != nil {
39 l.Error("db.CloseIssues failed", "err", err)
40 return ErrDatabaseFail
41 }
42
43 // change the issue state (this will pass down to the notifiers)
44 issue.Open = false
45
46 s.notifier.NewIssueState(ctx, sessDid, issue)
47 return nil
48}
49
50func (s *Service) ReopenIssue(ctx context.Context, issue *models.Issue) error {
51 l := s.logger.With("method", "ReopenIssue")
52 sess := session.FromContext(ctx)
53 if sess == nil {
54 l.Error("user session is missing in context")
55 return ErrUnAuthenticated
56 }
57 sessDid := sess.Data.AccountDID
58 l = l.With("did", sessDid)
59
60 // TODO: make this more granular
61 roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(sessDid.String(), issue.Repo.Knot, issue.Repo.DidSlashRepo())}
62 isRepoOwner := roles.IsOwner()
63 isCollaborator := roles.IsCollaborator()
64 isIssueOwner := sessDid == syntax.DID(issue.Did)
65 if !(isRepoOwner || isCollaborator || isIssueOwner) {
66 l.Error("user is not authorized")
67 return ErrForbidden
68 }
69
70 err := db.ReopenIssues(
71 s.db,
72 orm.FilterEq("id", issue.Id),
73 )
74 if err != nil {
75 l.Error("db.ReopenIssues failed", "err", err)
76 return ErrDatabaseFail
77 }
78
79 // change the issue state (this will pass down to the notifiers)
80 issue.Open = true
81
82 s.notifier.NewIssueState(ctx, sessDid, issue)
83 return nil
84}