##// END OF EJS Templates
fixed missing permission for being able to write to group on repository settings ref #468
marcink -
r2986:f8d82768 beta
parent child Browse files
Show More
@@ -1,349 +1,350 b''
1 1 """ this is forms validation classes
2 2 http://formencode.org/module-formencode.validators.html
3 3 for list off all availible validators
4 4
5 5 we can create our own validators
6 6
7 7 The table below outlines the options which can be used in a schema in addition to the validators themselves
8 8 pre_validators [] These validators will be applied before the schema
9 9 chained_validators [] These validators will be applied after the schema
10 10 allow_extra_fields False If True, then it is not an error when keys that aren't associated with a validator are present
11 11 filter_extra_fields False If True, then keys that aren't associated with a validator are removed
12 12 if_key_missing NoDefault If this is given, then any keys that aren't available but are expected will be replaced with this value (and then validated). This does not override a present .if_missing attribute on validators. NoDefault is a special FormEncode class to mean that no default values has been specified and therefore missing keys shouldn't take a default value.
13 13 ignore_key_missing False If True, then missing keys will be missing in the result, if the validator doesn't have .if_missing on it already
14 14
15 15
16 16 <name> = formencode.validators.<name of validator>
17 17 <name> must equal form name
18 18 list=[1,2,3,4,5]
19 19 for SELECT use formencode.All(OneOf(list), Int())
20 20
21 21 """
22 22 import logging
23 23
24 24 import formencode
25 25 from formencode import All
26 26
27 27 from pylons.i18n.translation import _
28 28
29 29 from rhodecode.model import validators as v
30 30 from rhodecode import BACKENDS
31 31
32 32 log = logging.getLogger(__name__)
33 33
34 34
35 35 class LoginForm(formencode.Schema):
36 36 allow_extra_fields = True
37 37 filter_extra_fields = True
38 38 username = v.UnicodeString(
39 39 strip=True,
40 40 min=1,
41 41 not_empty=True,
42 42 messages={
43 43 'empty': _(u'Please enter a login'),
44 44 'tooShort': _(u'Enter a value %(min)i characters long or more')}
45 45 )
46 46
47 47 password = v.UnicodeString(
48 48 strip=False,
49 49 min=3,
50 50 not_empty=True,
51 51 messages={
52 52 'empty': _(u'Please enter a password'),
53 53 'tooShort': _(u'Enter %(min)i characters or more')}
54 54 )
55 55
56 56 remember = v.StringBoolean(if_missing=False)
57 57
58 58 chained_validators = [v.ValidAuth()]
59 59
60 60
61 61 def UserForm(edit=False, old_data={}):
62 62 class _UserForm(formencode.Schema):
63 63 allow_extra_fields = True
64 64 filter_extra_fields = True
65 65 username = All(v.UnicodeString(strip=True, min=1, not_empty=True),
66 66 v.ValidUsername(edit, old_data))
67 67 if edit:
68 68 new_password = All(
69 69 v.ValidPassword(),
70 70 v.UnicodeString(strip=False, min=6, not_empty=False)
71 71 )
72 72 password_confirmation = All(
73 73 v.ValidPassword(),
74 74 v.UnicodeString(strip=False, min=6, not_empty=False),
75 75 )
76 76 admin = v.StringBoolean(if_missing=False)
77 77 else:
78 78 password = All(
79 79 v.ValidPassword(),
80 80 v.UnicodeString(strip=False, min=6, not_empty=True)
81 81 )
82 82 password_confirmation = All(
83 83 v.ValidPassword(),
84 84 v.UnicodeString(strip=False, min=6, not_empty=False)
85 85 )
86 86
87 87 active = v.StringBoolean(if_missing=False)
88 88 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
89 89 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
90 90 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
91 91
92 92 chained_validators = [v.ValidPasswordsMatch()]
93 93
94 94 return _UserForm
95 95
96 96
97 97 def UsersGroupForm(edit=False, old_data={}, available_members=[]):
98 98 class _UsersGroupForm(formencode.Schema):
99 99 allow_extra_fields = True
100 100 filter_extra_fields = True
101 101
102 102 users_group_name = All(
103 103 v.UnicodeString(strip=True, min=1, not_empty=True),
104 104 v.ValidUsersGroup(edit, old_data)
105 105 )
106 106
107 107 users_group_active = v.StringBoolean(if_missing=False)
108 108
109 109 if edit:
110 110 users_group_members = v.OneOf(
111 111 available_members, hideList=False, testValueList=True,
112 112 if_missing=None, not_empty=False
113 113 )
114 114
115 115 return _UsersGroupForm
116 116
117 117
118 118 def ReposGroupForm(edit=False, old_data={}, available_groups=[]):
119 119 class _ReposGroupForm(formencode.Schema):
120 120 allow_extra_fields = True
121 121 filter_extra_fields = False
122 122
123 123 group_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
124 124 v.SlugifyName())
125 125 group_description = v.UnicodeString(strip=True, min=1,
126 126 not_empty=True)
127 127 group_parent_id = v.OneOf(available_groups, hideList=False,
128 128 testValueList=True,
129 129 if_missing=None, not_empty=False)
130 130 enable_locking = v.StringBoolean(if_missing=False)
131 131 recursive = v.StringBoolean(if_missing=False)
132 132 chained_validators = [v.ValidReposGroup(edit, old_data),
133 133 v.ValidPerms('group')]
134 134
135 135 return _ReposGroupForm
136 136
137 137
138 138 def RegisterForm(edit=False, old_data={}):
139 139 class _RegisterForm(formencode.Schema):
140 140 allow_extra_fields = True
141 141 filter_extra_fields = True
142 142 username = All(
143 143 v.ValidUsername(edit, old_data),
144 144 v.UnicodeString(strip=True, min=1, not_empty=True)
145 145 )
146 146 password = All(
147 147 v.ValidPassword(),
148 148 v.UnicodeString(strip=False, min=6, not_empty=True)
149 149 )
150 150 password_confirmation = All(
151 151 v.ValidPassword(),
152 152 v.UnicodeString(strip=False, min=6, not_empty=True)
153 153 )
154 154 active = v.StringBoolean(if_missing=False)
155 155 firstname = v.UnicodeString(strip=True, min=1, not_empty=False)
156 156 lastname = v.UnicodeString(strip=True, min=1, not_empty=False)
157 157 email = All(v.Email(not_empty=True), v.UniqSystemEmail(old_data))
158 158
159 159 chained_validators = [v.ValidPasswordsMatch()]
160 160
161 161 return _RegisterForm
162 162
163 163
164 164 def PasswordResetForm():
165 165 class _PasswordResetForm(formencode.Schema):
166 166 allow_extra_fields = True
167 167 filter_extra_fields = True
168 168 email = All(v.ValidSystemEmail(), v.Email(not_empty=True))
169 169 return _PasswordResetForm
170 170
171 171
172 172 def RepoForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
173 173 repo_groups=[], landing_revs=[]):
174 174 class _RepoForm(formencode.Schema):
175 175 allow_extra_fields = True
176 176 filter_extra_fields = False
177 177 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
178 178 v.SlugifyName())
179 179 clone_uri = All(v.UnicodeString(strip=True, min=1, not_empty=False))
180 180 repo_group = All(v.CanWriteGroup(),
181 181 v.OneOf(repo_groups, hideList=True))
182 182 repo_type = v.OneOf(supported_backends)
183 183 description = v.UnicodeString(strip=True, min=1, not_empty=False)
184 184 private = v.StringBoolean(if_missing=False)
185 185 enable_statistics = v.StringBoolean(if_missing=False)
186 186 enable_downloads = v.StringBoolean(if_missing=False)
187 187 enable_locking = v.StringBoolean(if_missing=False)
188 188 landing_rev = v.OneOf(landing_revs, hideList=True)
189 189
190 190 if edit:
191 191 #this is repo owner
192 192 user = All(v.UnicodeString(not_empty=True), v.ValidRepoUser())
193 193
194 194 chained_validators = [v.ValidCloneUri(),
195 195 v.ValidRepoName(edit, old_data),
196 196 v.ValidPerms()]
197 197 return _RepoForm
198 198
199 199
200 200 def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
201 201 repo_groups=[], landing_revs=[]):
202 202 class _RepoForkForm(formencode.Schema):
203 203 allow_extra_fields = True
204 204 filter_extra_fields = False
205 205 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
206 206 v.SlugifyName())
207 207 repo_group = All(v.CanWriteGroup(),
208 208 v.OneOf(repo_groups, hideList=True))
209 209 repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
210 210 description = v.UnicodeString(strip=True, min=1, not_empty=True)
211 211 private = v.StringBoolean(if_missing=False)
212 212 copy_permissions = v.StringBoolean(if_missing=False)
213 213 update_after_clone = v.StringBoolean(if_missing=False)
214 214 fork_parent_id = v.UnicodeString()
215 215 chained_validators = [v.ValidForkName(edit, old_data)]
216 216 landing_rev = v.OneOf(landing_revs, hideList=True)
217 217
218 218 return _RepoForkForm
219 219
220 220
221 221 def RepoSettingsForm(edit=False, old_data={},
222 222 supported_backends=BACKENDS.keys(), repo_groups=[],
223 223 landing_revs=[]):
224 224 class _RepoForm(formencode.Schema):
225 225 allow_extra_fields = True
226 226 filter_extra_fields = False
227 227 repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
228 228 v.SlugifyName())
229 229 description = v.UnicodeString(strip=True, min=1, not_empty=True)
230 repo_group = v.OneOf(repo_groups, hideList=True)
230 repo_group = All(v.CanWriteGroup(),
231 v.OneOf(repo_groups, hideList=True))
231 232 private = v.StringBoolean(if_missing=False)
232 233 landing_rev = v.OneOf(landing_revs, hideList=True)
233 234 chained_validators = [v.ValidRepoName(edit, old_data), v.ValidPerms(),
234 235 v.ValidSettings()]
235 236 return _RepoForm
236 237
237 238
238 239 def ApplicationSettingsForm():
239 240 class _ApplicationSettingsForm(formencode.Schema):
240 241 allow_extra_fields = True
241 242 filter_extra_fields = False
242 243 rhodecode_title = v.UnicodeString(strip=True, min=1, not_empty=True)
243 244 rhodecode_realm = v.UnicodeString(strip=True, min=1, not_empty=True)
244 245 rhodecode_ga_code = v.UnicodeString(strip=True, min=1, not_empty=False)
245 246
246 247 return _ApplicationSettingsForm
247 248
248 249
249 250 def ApplicationVisualisationForm():
250 251 class _ApplicationVisualisationForm(formencode.Schema):
251 252 allow_extra_fields = True
252 253 filter_extra_fields = False
253 254 rhodecode_show_public_icon = v.StringBoolean(if_missing=False)
254 255 rhodecode_show_private_icon = v.StringBoolean(if_missing=False)
255 256 rhodecode_stylify_metatags = v.StringBoolean(if_missing=False)
256 257
257 258 rhodecode_lightweight_dashboard = v.StringBoolean(if_missing=False)
258 259 rhodecode_lightweight_journal = v.StringBoolean(if_missing=False)
259 260
260 261 return _ApplicationVisualisationForm
261 262
262 263
263 264 def ApplicationUiSettingsForm():
264 265 class _ApplicationUiSettingsForm(formencode.Schema):
265 266 allow_extra_fields = True
266 267 filter_extra_fields = False
267 268 web_push_ssl = v.StringBoolean(if_missing=False)
268 269 paths_root_path = All(
269 270 v.ValidPath(),
270 271 v.UnicodeString(strip=True, min=1, not_empty=True)
271 272 )
272 273 hooks_changegroup_update = v.StringBoolean(if_missing=False)
273 274 hooks_changegroup_repo_size = v.StringBoolean(if_missing=False)
274 275 hooks_changegroup_push_logger = v.StringBoolean(if_missing=False)
275 276 hooks_outgoing_pull_logger = v.StringBoolean(if_missing=False)
276 277
277 278 extensions_largefiles = v.StringBoolean(if_missing=False)
278 279 extensions_hgsubversion = v.StringBoolean(if_missing=False)
279 280 extensions_hggit = v.StringBoolean(if_missing=False)
280 281
281 282 return _ApplicationUiSettingsForm
282 283
283 284
284 285 def DefaultPermissionsForm(perms_choices, register_choices, create_choices,
285 286 fork_choices):
286 287 class _DefaultPermissionsForm(formencode.Schema):
287 288 allow_extra_fields = True
288 289 filter_extra_fields = True
289 290 overwrite_default = v.StringBoolean(if_missing=False)
290 291 anonymous = v.StringBoolean(if_missing=False)
291 292 default_perm = v.OneOf(perms_choices)
292 293 default_register = v.OneOf(register_choices)
293 294 default_create = v.OneOf(create_choices)
294 295 default_fork = v.OneOf(fork_choices)
295 296
296 297 return _DefaultPermissionsForm
297 298
298 299
299 300 def LdapSettingsForm(tls_reqcert_choices, search_scope_choices,
300 301 tls_kind_choices):
301 302 class _LdapSettingsForm(formencode.Schema):
302 303 allow_extra_fields = True
303 304 filter_extra_fields = True
304 305 #pre_validators = [LdapLibValidator]
305 306 ldap_active = v.StringBoolean(if_missing=False)
306 307 ldap_host = v.UnicodeString(strip=True,)
307 308 ldap_port = v.Number(strip=True,)
308 309 ldap_tls_kind = v.OneOf(tls_kind_choices)
309 310 ldap_tls_reqcert = v.OneOf(tls_reqcert_choices)
310 311 ldap_dn_user = v.UnicodeString(strip=True,)
311 312 ldap_dn_pass = v.UnicodeString(strip=True,)
312 313 ldap_base_dn = v.UnicodeString(strip=True,)
313 314 ldap_filter = v.UnicodeString(strip=True,)
314 315 ldap_search_scope = v.OneOf(search_scope_choices)
315 316 ldap_attr_login = All(
316 317 v.AttrLoginValidator(),
317 318 v.UnicodeString(strip=True,)
318 319 )
319 320 ldap_attr_firstname = v.UnicodeString(strip=True,)
320 321 ldap_attr_lastname = v.UnicodeString(strip=True,)
321 322 ldap_attr_email = v.UnicodeString(strip=True,)
322 323
323 324 return _LdapSettingsForm
324 325
325 326
326 327 def UserExtraEmailForm():
327 328 class _UserExtraEmailForm(formencode.Schema):
328 329 email = All(v.UniqSystemEmail(), v.Email)
329 330
330 331 return _UserExtraEmailForm
331 332
332 333
333 334 def PullRequestForm(repo_id):
334 335 class _PullRequestForm(formencode.Schema):
335 336 allow_extra_fields = True
336 337 filter_extra_fields = True
337 338
338 339 user = v.UnicodeString(strip=True, required=True)
339 340 org_repo = v.UnicodeString(strip=True, required=True)
340 341 org_ref = v.UnicodeString(strip=True, required=True)
341 342 other_repo = v.UnicodeString(strip=True, required=True)
342 343 other_ref = v.UnicodeString(strip=True, required=True)
343 344 revisions = All(v.NotReviewedRevisions(repo_id)(), v.UniqueList(not_empty=True))
344 345 review_members = v.UniqueList(not_empty=True)
345 346
346 347 pullrequest_title = v.UnicodeString(strip=True, required=True, min=3)
347 348 pullrequest_desc = v.UnicodeString(strip=True, required=False)
348 349
349 350 return _PullRequestForm
General Comments 0
You need to be logged in to leave comments. Login now