forked from
tangled.org/core
this repo has no description
1package pull
2
3import (
4 "context"
5
6 "tangled.org/core/appview/db"
7 "tangled.org/core/appview/models"
8 "tangled.org/core/appview/pages/repoinfo"
9 "tangled.org/core/appview/session"
10)
11
12func (s *Service) ClosePull(ctx context.Context, pull *models.Pull2) error {
13 l := s.logger.With("method", "CloseIssue")
14 sess := session.FromContext(ctx)
15 if sess == nil {
16 l.Error("user session is missing in context")
17 return ErrUnAuthenticated
18 }
19 sessDid := sess.Data.AccountDID
20 l = l.With("did", sessDid)
21
22 // TODO: make this more granular
23 roles := repoinfo.RolesInRepo{Roles: s.enforcer.GetPermissionsInRepo(sessDid.String(), pull.Repo.Knot, pull.Repo.DidSlashRepo())}
24 isRepoOwner := roles.IsOwner()
25 isCollaborator := roles.IsCollaborator()
26 isAuthor := sessDid == pull.Did
27 if !(isRepoOwner || isCollaborator || isAuthor) {
28 l.Error("user is not authorized")
29 return ErrForbidden
30 }
31
32 err := db.ClosePull2(s.db, pull.AtUri())
33 if err != nil {
34 l.Error("db.ClosePull2 failed", "err", err)
35 return ErrDatabaseFail
36 }
37
38 // change the issue state (this will pass down to the notifiers)
39 pull.State = models.PullClosed
40
41 panic("unimplemented")
42 // s.notifier.NewPullState(ctx, sessDid, pull)
43}
44
45func (s *Service) ReopenPull(ctx context.Context, pull *models.Pull2) error {
46 panic("unimplemented")
47}