summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
Diffstat (limited to 'modules')
-rw-r--r--modules/lfs/locks.go115
1 files changed, 83 insertions, 32 deletions
diff --git a/modules/lfs/locks.go b/modules/lfs/locks.go
index 525a93645f..b1ca2f094a 100644
--- a/modules/lfs/locks.go
+++ b/modules/lfs/locks.go
@@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
+ "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
api "code.gitea.io/gitea/modules/structs"
)
@@ -44,7 +45,7 @@ func checkIsValidRequest(ctx *context.Context, post bool) bool {
return true
}
-func handleLockListOut(ctx *context.Context, lock *models.LFSLock, err error) {
+func handleLockListOut(ctx *context.Context, repo *models.Repository, lock *models.LFSLock, err error) {
if err != nil {
if models.IsErrLFSLockNotExist(err) {
ctx.JSON(200, api.LFSLockList{
@@ -57,7 +58,7 @@ func handleLockListOut(ctx *context.Context, lock *models.LFSLock, err error) {
})
return
}
- if ctx.Repo.Repository.ID != lock.RepoID {
+ if repo.ID != lock.RepoID {
ctx.JSON(200, api.LFSLockList{
Locks: []*api.LFSLock{},
})
@@ -75,17 +76,21 @@ func GetListLockHandler(ctx *context.Context) {
}
ctx.Resp.Header().Set("Content-Type", metaMediaType)
- err := models.CheckLFSAccessForRepo(ctx.User, ctx.Repo.Repository, models.AccessModeRead)
+ rv := unpack(ctx)
+
+ repository, err := models.GetRepositoryByOwnerAndName(rv.User, rv.Repo)
if err != nil {
- if models.IsErrLFSUnauthorizedAction(err) {
- ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
- ctx.JSON(401, api.LFSLockError{
- Message: "You must have pull access to list locks : " + err.Error(),
- })
- return
- }
- ctx.JSON(500, api.LFSLockError{
- Message: "unable to list lock : " + err.Error(),
+ log.Debug("Could not find repository: %s/%s - %s", rv.User, rv.Repo, err)
+ writeStatus(ctx, 404)
+ return
+ }
+ repository.MustOwner()
+
+ authenticated := authenticate(ctx, repository, rv.Authorization, false)
+ if !authenticated {
+ ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
+ ctx.JSON(401, api.LFSLockError{
+ Message: "You must have pull access to list locks",
})
return
}
@@ -100,19 +105,19 @@ func GetListLockHandler(ctx *context.Context) {
return
}
lock, err := models.GetLFSLockByID(int64(v))
- handleLockListOut(ctx, lock, err)
+ handleLockListOut(ctx, repository, lock, err)
return
}
path := ctx.Query("path")
if path != "" { //Case where we request a specific id
- lock, err := models.GetLFSLock(ctx.Repo.Repository, path)
- handleLockListOut(ctx, lock, err)
+ lock, err := models.GetLFSLock(repository, path)
+ handleLockListOut(ctx, repository, lock, err)
return
}
//If no query params path or id
- lockList, err := models.GetLFSLockByRepoID(ctx.Repo.Repository.ID)
+ lockList, err := models.GetLFSLockByRepoID(repository.ID)
if err != nil {
ctx.JSON(500, api.LFSLockError{
Message: "unable to list locks : " + err.Error(),
@@ -135,16 +140,36 @@ func PostLockHandler(ctx *context.Context) {
}
ctx.Resp.Header().Set("Content-Type", metaMediaType)
+ userName := ctx.Params("username")
+ repoName := strings.TrimSuffix(ctx.Params("reponame"), ".git")
+ authorization := ctx.Req.Header.Get("Authorization")
+
+ repository, err := models.GetRepositoryByOwnerAndName(userName, repoName)
+ if err != nil {
+ log.Debug("Could not find repository: %s/%s - %s", userName, repoName, err)
+ writeStatus(ctx, 404)
+ return
+ }
+ repository.MustOwner()
+
+ authenticated := authenticate(ctx, repository, authorization, true)
+ if !authenticated {
+ ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
+ ctx.JSON(401, api.LFSLockError{
+ Message: "You must have push access to create locks",
+ })
+ return
+ }
+
var req api.LFSLockRequest
dec := json.NewDecoder(ctx.Req.Body().ReadCloser())
- err := dec.Decode(&req)
- if err != nil {
+ if err := dec.Decode(&req); err != nil {
writeStatus(ctx, 400)
return
}
lock, err := models.CreateLFSLock(&models.LFSLock{
- Repo: ctx.Repo.Repository,
+ Repo: repository,
Path: req.Path,
Owner: ctx.User,
})
@@ -178,23 +203,29 @@ func VerifyLockHandler(ctx *context.Context) {
}
ctx.Resp.Header().Set("Content-Type", metaMediaType)
- err := models.CheckLFSAccessForRepo(ctx.User, ctx.Repo.Repository, models.AccessModeWrite)
+ userName := ctx.Params("username")
+ repoName := strings.TrimSuffix(ctx.Params("reponame"), ".git")
+ authorization := ctx.Req.Header.Get("Authorization")
+
+ repository, err := models.GetRepositoryByOwnerAndName(userName, repoName)
if err != nil {
- if models.IsErrLFSUnauthorizedAction(err) {
- ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
- ctx.JSON(401, api.LFSLockError{
- Message: "You must have push access to verify locks : " + err.Error(),
- })
- return
- }
- ctx.JSON(500, api.LFSLockError{
- Message: "unable to verify lock : " + err.Error(),
+ log.Debug("Could not find repository: %s/%s - %s", userName, repoName, err)
+ writeStatus(ctx, 404)
+ return
+ }
+ repository.MustOwner()
+
+ authenticated := authenticate(ctx, repository, authorization, true)
+ if !authenticated {
+ ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
+ ctx.JSON(401, api.LFSLockError{
+ Message: "You must have push access to verify locks",
})
return
}
//TODO handle body json cursor and limit
- lockList, err := models.GetLFSLockByRepoID(ctx.Repo.Repository.ID)
+ lockList, err := models.GetLFSLockByRepoID(repository.ID)
if err != nil {
ctx.JSON(500, api.LFSLockError{
Message: "unable to list locks : " + err.Error(),
@@ -223,10 +254,30 @@ func UnLockHandler(ctx *context.Context) {
}
ctx.Resp.Header().Set("Content-Type", metaMediaType)
+ userName := ctx.Params("username")
+ repoName := strings.TrimSuffix(ctx.Params("reponame"), ".git")
+ authorization := ctx.Req.Header.Get("Authorization")
+
+ repository, err := models.GetRepositoryByOwnerAndName(userName, repoName)
+ if err != nil {
+ log.Debug("Could not find repository: %s/%s - %s", userName, repoName, err)
+ writeStatus(ctx, 404)
+ return
+ }
+ repository.MustOwner()
+
+ authenticated := authenticate(ctx, repository, authorization, true)
+ if !authenticated {
+ ctx.Resp.Header().Set("WWW-Authenticate", "Basic realm=gitea-lfs")
+ ctx.JSON(401, api.LFSLockError{
+ Message: "You must have push access to delete locks",
+ })
+ return
+ }
+
var req api.LFSLockDeleteRequest
dec := json.NewDecoder(ctx.Req.Body().ReadCloser())
- err := dec.Decode(&req)
- if err != nil {
+ if err := dec.Decode(&req); err != nil {
writeStatus(ctx, 400)
return
}
ion> Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
summaryrefslogtreecommitdiffstats
path: root/l10n/templates/files_encryption.pot
blob: 66bce5370119348f0a05321f47efffc4702b4b78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199