Skip to content

Commit ed512bf

Browse files
committedNov 12, 2020
Deny push to the repositories which's owner is inactive
1 parent 461ef8b commit ed512bf

File tree

2 files changed

+33
-10
lines changed

2 files changed

+33
-10
lines changed
 

‎routers/private/serv.go

+29-10
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,28 @@ func ServCommand(ctx *macaron.Context) {
104104
results.RepoName = repoName[:len(repoName)-5]
105105
}
106106

107+
owner, err := models.GetUserByName(results.OwnerName)
108+
if err != nil {
109+
log.Error("Unable to get repository owner: %s/%s Error: %v", results.OwnerName, results.RepoName, err)
110+
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
111+
"results": results,
112+
"type": "InternalServerError",
113+
"err": fmt.Sprintf("Unable to get repository owner: %s/%s %v", results.OwnerName, results.RepoName, err),
114+
})
115+
return
116+
}
117+
if !owner.IsActive {
118+
ctx.JSON(http.StatusForbidden, map[string]interface{}{
119+
"results": results,
120+
"type": "ForbiddenError",
121+
"err": "Repository cannot be accessed, you could retry it later",
122+
})
123+
return
124+
}
125+
107126
// Now get the Repository and set the results section
108127
repoExist := true
109-
repo, err := models.GetRepositoryByOwnerAndName(results.OwnerName, results.RepoName)
128+
repo, err := models.GetRepositoryByName(owner.ID, results.RepoName)
110129
if err != nil {
111130
if models.IsErrRepoNotExist(err) {
112131
repoExist = false
@@ -133,6 +152,7 @@ func ServCommand(ctx *macaron.Context) {
133152
}
134153

135154
if repoExist {
155+
repo.Owner = owner
136156
repo.OwnerName = ownerName
137157
results.RepoID = repo.ID
138158

@@ -223,15 +243,6 @@ func ServCommand(ctx *macaron.Context) {
223243
// so for now use the owner of the repository
224244
results.UserName = results.OwnerName
225245
results.UserID = repo.OwnerID
226-
if err = repo.GetOwner(); err != nil {
227-
log.Error("Unable to get owner for repo %-v. Error: %v", repo, err)
228-
ctx.JSON(http.StatusInternalServerError, map[string]interface{}{
229-
"results": results,
230-
"type": "InternalServerError",
231-
"err": fmt.Sprintf("Unable to get owner for repo: %s/%s.", results.OwnerName, results.RepoName),
232-
})
233-
return
234-
}
235246
if !repo.Owner.KeepEmailPrivate {
236247
results.UserEmail = repo.Owner.Email
237248
}
@@ -256,6 +267,14 @@ func ServCommand(ctx *macaron.Context) {
256267
})
257268
return
258269
}
270+
271+
if !user.IsActive {
272+
ctx.JSON(http.StatusForbidden, map[string]interface{}{
273+
"err": "Your account is disabled.",
274+
})
275+
return
276+
}
277+
259278
results.UserName = user.Name
260279
if !user.KeepEmailPrivate {
261280
results.UserEmail = user.Email

‎routers/repo/http.go

+4
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ func HTTP(ctx *context.Context) {
105105
ctx.NotFoundOrServerError("GetUserByName", models.IsErrUserNotExist, err)
106106
return
107107
}
108+
if !owner.IsActive {
109+
ctx.HandleText(http.StatusForbidden, "Repository cannot be accessed. You cannot push or open issues/pull-requests.")
110+
return
111+
}
108112

109113
repoExist := true
110114
repo, err := models.GetRepositoryByName(owner.ID, reponame)

0 commit comments

Comments
 (0)
Please sign in to comment.