MCPcopy Create free account
hub / github.com/gogs/gogs / repoAssignment

Function repoAssignment

internal/route/api/v1/api.go:24–71  ·  view source on GitHub ↗

repoAssignment extracts information from URL parameters to retrieve the repository, and makes sure the context user has at least the read access to the repository.

()

Source from the content-addressed store, hash-verified

22// repoAssignment extracts information from URL parameters to retrieve the repository,
23// and makes sure the context user has at least the read access to the repository.
24func repoAssignment() macaron.Handler {
25 return func(c *context.APIContext) {
26 username := c.Params(":username")
27 reponame := c.Params(":reponame")
28
29 var err error
30 var owner *database.User
31
32 // Check if the context user is the repository owner.
33 if c.IsLogged && c.User.LowerName == strings.ToLower(username) {
34 owner = c.User
35 } else {
36 owner, err = database.Handle.Users().GetByUsername(c.Req.Context(), username)
37 if err != nil {
38 c.NotFoundOrError(err, "get user by name")
39 return
40 }
41 }
42 c.Repo.Owner = owner
43
44 repo, err := database.Handle.Repositories().GetByName(c.Req.Context(), owner.ID, reponame)
45 if err != nil {
46 c.NotFoundOrError(err, "get repository by name")
47 return
48 } else if err = repo.GetOwner(); err != nil {
49 c.Error(err, "get owner")
50 return
51 }
52
53 if c.IsTokenAuth && c.User.IsAdmin {
54 c.Repo.AccessMode = database.AccessModeOwner
55 } else {
56 c.Repo.AccessMode = database.Handle.Permissions().AccessMode(c.Req.Context(), c.UserID(), repo.ID,
57 database.AccessModeOptions{
58 OwnerID: repo.OwnerID,
59 Private: repo.IsPrivate,
60 },
61 )
62 }
63
64 if !c.Repo.HasAccess() {
65 c.NotFound()
66 return
67 }
68
69 c.Repo.Repository = repo
70 }
71}
72
73// orgAssignment extracts information from URL parameters to retrieve the organization or team.
74func orgAssignment(args ...bool) macaron.Handler {

Callers 1

RegisterRoutesFunction · 0.85

Calls 12

GetByUsernameMethod · 0.80
UsersMethod · 0.80
GetByNameMethod · 0.80
RepositoriesMethod · 0.80
GetOwnerMethod · 0.80
AccessModeMethod · 0.80
PermissionsMethod · 0.80
UserIDMethod · 0.80
NotFoundMethod · 0.65
NotFoundOrErrorMethod · 0.45
ErrorMethod · 0.45
HasAccessMethod · 0.45

Tested by

no test coverage detected