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

Function RepoAssignment

internal/context/repo.go:121–296  ·  view source on GitHub ↗

[0]: issues, [1]: wiki

(pages ...bool)

Source from the content-addressed store, hash-verified

119
120// [0]: issues, [1]: wiki
121func RepoAssignment(pages ...bool) macaron.Handler {
122 return func(c *Context) {
123 var (
124 owner *database.User
125 err error
126 isIssuesPage bool
127 isWikiPage bool
128 )
129
130 if len(pages) > 0 {
131 isIssuesPage = pages[0]
132 }
133 if len(pages) > 1 {
134 isWikiPage = pages[1]
135 }
136
137 ownerName := c.Params(":username")
138 repoName := strings.TrimSuffix(c.Params(":reponame"), ".git")
139
140 // Check if the user is the same as the repository owner
141 if c.IsLogged && c.User.LowerName == strings.ToLower(ownerName) {
142 owner = c.User
143 } else {
144 owner, err = database.Handle.Users().GetByUsername(c.Req.Context(), ownerName)
145 if err != nil {
146 c.NotFoundOrError(err, "get user by name")
147 return
148 }
149 }
150 c.Repo.Owner = owner
151 c.Data["Username"] = c.Repo.Owner.Name
152
153 repo, err := database.GetRepositoryByName(owner.ID, repoName)
154 if err != nil {
155 c.NotFoundOrError(err, "get repository by name")
156 return
157 }
158
159 c.Repo.Repository = repo
160 c.Data["RepoName"] = c.Repo.Repository.Name
161 c.Data["IsBareRepo"] = c.Repo.Repository.IsBare
162 c.Repo.RepoLink = repo.Link()
163 c.Data["RepoLink"] = c.Repo.RepoLink
164 c.Data["RepoRelPath"] = c.Repo.Owner.Name + "/" + c.Repo.Repository.Name
165
166 // Admin has super access
167 if c.IsLogged && c.User.IsAdmin {
168 c.Repo.AccessMode = database.AccessModeOwner
169 } else {
170 c.Repo.AccessMode = database.Handle.Permissions().AccessMode(c.Req.Context(), c.UserID(), repo.ID,
171 database.AccessModeOptions{
172 OwnerID: repo.OwnerID,
173 Private: repo.IsPrivate,
174 },
175 )
176 }
177
178 // If the authenticated user has no direct access, see if the repository is a fork

Callers 1

runWebFunction · 0.92

Calls 15

GetRepositoryByNameFunction · 0.92
GetMirrorByRepoIDFunction · 0.92
RepoPathFunction · 0.92
IsWatchingFunction · 0.92
IsStaringFunction · 0.92
GetByUsernameMethod · 0.80
UsersMethod · 0.80
AccessModeMethod · 0.80
PermissionsMethod · 0.80
UserIDMethod · 0.80
IsPartialPublicMethod · 0.80
CanGuestViewIssuesMethod · 0.80

Tested by

no test coverage detected