You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

repo_form.go 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2017 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package auth
  6. import (
  7. "net/url"
  8. "strings"
  9. "code.gitea.io/gitea/models"
  10. "code.gitea.io/gitea/modules/setting"
  11. "code.gitea.io/gitea/routers/utils"
  12. "github.com/Unknwon/com"
  13. "github.com/go-macaron/binding"
  14. macaron "gopkg.in/macaron.v1"
  15. )
  16. // _______________________________________ _________.______________________ _______________.___.
  17. // \______ \_ _____/\______ \_____ \ / _____/| \__ ___/\_____ \\______ \__ | |
  18. // | _/| __)_ | ___// | \ \_____ \ | | | | / | \| _// | |
  19. // | | \| \ | | / | \/ \| | | | / | \ | \\____ |
  20. // |____|_ /_______ / |____| \_______ /_______ /|___| |____| \_______ /____|_ // ______|
  21. // \/ \/ \/ \/ \/ \/ \/
  22. // CreateRepoForm form for creating repository
  23. type CreateRepoForm struct {
  24. UID int64 `binding:"Required"`
  25. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  26. Private bool
  27. Description string `binding:"MaxSize(255)"`
  28. AutoInit bool
  29. Gitignores string
  30. License string
  31. Readme string
  32. }
  33. // Validate validates the fields
  34. func (f *CreateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  35. return validate(errs, ctx.Data, f, ctx.Locale)
  36. }
  37. // MigrateRepoForm form for migrating repository
  38. type MigrateRepoForm struct {
  39. // required: true
  40. CloneAddr string `json:"clone_addr" binding:"Required"`
  41. AuthUsername string `json:"auth_username"`
  42. AuthPassword string `json:"auth_password"`
  43. // required: true
  44. UID int64 `json:"uid" binding:"Required"`
  45. // required: true
  46. RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  47. Mirror bool `json:"mirror"`
  48. Private bool `json:"private"`
  49. Description string `json:"description" binding:"MaxSize(255)"`
  50. }
  51. // Validate validates the fields
  52. func (f *MigrateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  53. return validate(errs, ctx.Data, f, ctx.Locale)
  54. }
  55. // ParseRemoteAddr checks if given remote address is valid,
  56. // and returns composed URL with needed username and password.
  57. // It also checks if given user has permission when remote address
  58. // is actually a local path.
  59. func (f MigrateRepoForm) ParseRemoteAddr(user *models.User) (string, error) {
  60. remoteAddr := strings.TrimSpace(f.CloneAddr)
  61. // Remote address can be HTTP/HTTPS/Git URL or local path.
  62. if strings.HasPrefix(remoteAddr, "http://") ||
  63. strings.HasPrefix(remoteAddr, "https://") ||
  64. strings.HasPrefix(remoteAddr, "git://") {
  65. u, err := url.Parse(remoteAddr)
  66. if err != nil {
  67. return "", models.ErrInvalidCloneAddr{IsURLError: true}
  68. }
  69. if len(f.AuthUsername)+len(f.AuthPassword) > 0 {
  70. u.User = url.UserPassword(f.AuthUsername, f.AuthPassword)
  71. }
  72. remoteAddr = u.String()
  73. } else if !user.CanImportLocal() {
  74. return "", models.ErrInvalidCloneAddr{IsPermissionDenied: true}
  75. } else if !com.IsDir(remoteAddr) {
  76. return "", models.ErrInvalidCloneAddr{IsInvalidPath: true}
  77. }
  78. return remoteAddr, nil
  79. }
  80. // RepoSettingForm form for changing repository settings
  81. type RepoSettingForm struct {
  82. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  83. Description string `binding:"MaxSize(255)"`
  84. Website string `binding:"ValidUrl;MaxSize(255)"`
  85. Interval string
  86. MirrorAddress string
  87. Private bool
  88. EnablePrune bool
  89. // Advanced settings
  90. EnableWiki bool
  91. EnableExternalWiki bool
  92. ExternalWikiURL string
  93. EnableIssues bool
  94. EnableExternalTracker bool
  95. ExternalTrackerURL string
  96. TrackerURLFormat string
  97. TrackerIssueStyle string
  98. EnablePulls bool
  99. PullsIgnoreWhitespace bool
  100. PullsAllowMerge bool
  101. PullsAllowRebase bool
  102. PullsAllowRebaseMerge bool
  103. PullsAllowSquash bool
  104. EnableTimetracker bool
  105. AllowOnlyContributorsToTrackTime bool
  106. EnableIssueDependencies bool
  107. IsArchived bool
  108. // Admin settings
  109. EnableHealthCheck bool
  110. EnableCloseIssuesViaCommitInAnyBranch bool
  111. }
  112. // Validate validates the fields
  113. func (f *RepoSettingForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  114. return validate(errs, ctx.Data, f, ctx.Locale)
  115. }
  116. // __________ .__
  117. // \______ \____________ ____ ____ | |__
  118. // | | _/\_ __ \__ \ / \_/ ___\| | \
  119. // | | \ | | \// __ \| | \ \___| Y \
  120. // |______ / |__| (____ /___| /\___ >___| /
  121. // \/ \/ \/ \/ \/
  122. // ProtectBranchForm form for changing protected branch settings
  123. type ProtectBranchForm struct {
  124. Protected bool
  125. EnableWhitelist bool
  126. WhitelistUsers string
  127. WhitelistTeams string
  128. EnableMergeWhitelist bool
  129. MergeWhitelistUsers string
  130. MergeWhitelistTeams string
  131. RequiredApprovals int64
  132. ApprovalsWhitelistUsers string
  133. ApprovalsWhitelistTeams string
  134. }
  135. // Validate validates the fields
  136. func (f *ProtectBranchForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  137. return validate(errs, ctx.Data, f, ctx.Locale)
  138. }
  139. // __ __ ___. .__ .__ __
  140. // / \ / \ ____\_ |__ | |__ | |__ ____ | | __
  141. // \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
  142. // \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
  143. // \__/\ / \___ >___ /___| /___| /\____/|__|_ \
  144. // \/ \/ \/ \/ \/ \/
  145. // WebhookForm form for changing web hook
  146. type WebhookForm struct {
  147. Events string
  148. Create bool
  149. Delete bool
  150. Fork bool
  151. Issues bool
  152. IssueComment bool
  153. Release bool
  154. Push bool
  155. PullRequest bool
  156. Repository bool
  157. Active bool
  158. }
  159. // PushOnly if the hook will be triggered when push
  160. func (f WebhookForm) PushOnly() bool {
  161. return f.Events == "push_only"
  162. }
  163. // SendEverything if the hook will be triggered any event
  164. func (f WebhookForm) SendEverything() bool {
  165. return f.Events == "send_everything"
  166. }
  167. // ChooseEvents if the hook will be triggered choose events
  168. func (f WebhookForm) ChooseEvents() bool {
  169. return f.Events == "choose_events"
  170. }
  171. // NewWebhookForm form for creating web hook
  172. type NewWebhookForm struct {
  173. PayloadURL string `binding:"Required;ValidUrl"`
  174. ContentType int `binding:"Required"`
  175. Secret string
  176. WebhookForm
  177. }
  178. // Validate validates the fields
  179. func (f *NewWebhookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  180. return validate(errs, ctx.Data, f, ctx.Locale)
  181. }
  182. // NewGogshookForm form for creating gogs hook
  183. type NewGogshookForm struct {
  184. PayloadURL string `binding:"Required;ValidUrl"`
  185. ContentType int `binding:"Required"`
  186. Secret string
  187. WebhookForm
  188. }
  189. // Validate validates the fields
  190. func (f *NewGogshookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  191. return validate(errs, ctx.Data, f, ctx.Locale)
  192. }
  193. // NewSlackHookForm form for creating slack hook
  194. type NewSlackHookForm struct {
  195. PayloadURL string `binding:"Required;ValidUrl"`
  196. Channel string `binding:"Required"`
  197. Username string
  198. IconURL string
  199. Color string
  200. WebhookForm
  201. }
  202. // Validate validates the fields
  203. func (f *NewSlackHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  204. return validate(errs, ctx.Data, f, ctx.Locale)
  205. }
  206. // HasInvalidChannel validates the channel name is in the right format
  207. func (f NewSlackHookForm) HasInvalidChannel() bool {
  208. return !utils.IsValidSlackChannel(f.Channel)
  209. }
  210. // NewDiscordHookForm form for creating discord hook
  211. type NewDiscordHookForm struct {
  212. PayloadURL string `binding:"Required;ValidUrl"`
  213. Username string
  214. IconURL string
  215. WebhookForm
  216. }
  217. // Validate validates the fields
  218. func (f *NewDiscordHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  219. return validate(errs, ctx.Data, f, ctx.Locale)
  220. }
  221. // NewDingtalkHookForm form for creating dingtalk hook
  222. type NewDingtalkHookForm struct {
  223. PayloadURL string `binding:"Required;ValidUrl"`
  224. WebhookForm
  225. }
  226. // Validate validates the fields
  227. func (f *NewDingtalkHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  228. return validate(errs, ctx.Data, f, ctx.Locale)
  229. }
  230. // NewTelegramHookForm form for creating telegram hook
  231. type NewTelegramHookForm struct {
  232. BotToken string `binding:"Required"`
  233. ChatID string `binding:"Required"`
  234. WebhookForm
  235. }
  236. // Validate validates the fields
  237. func (f *NewTelegramHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  238. return validate(errs, ctx.Data, f, ctx.Locale)
  239. }
  240. // NewMSTeamsHookForm form for creating MS Teams hook
  241. type NewMSTeamsHookForm struct {
  242. PayloadURL string `binding:"Required;ValidUrl"`
  243. WebhookForm
  244. }
  245. // Validate validates the fields
  246. func (f *NewMSTeamsHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  247. return validate(errs, ctx.Data, f, ctx.Locale)
  248. }
  249. // .___
  250. // | | ______ ________ __ ____
  251. // | |/ ___// ___/ | \_/ __ \
  252. // | |\___ \ \___ \| | /\ ___/
  253. // |___/____ >____ >____/ \___ >
  254. // \/ \/ \/
  255. // CreateIssueForm form for creating issue
  256. type CreateIssueForm struct {
  257. Title string `binding:"Required;MaxSize(255)"`
  258. LabelIDs string `form:"label_ids"`
  259. AssigneeIDs string `form:"assignee_ids"`
  260. Ref string `form:"ref"`
  261. MilestoneID int64
  262. AssigneeID int64
  263. Content string
  264. Files []string
  265. }
  266. // Validate validates the fields
  267. func (f *CreateIssueForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  268. return validate(errs, ctx.Data, f, ctx.Locale)
  269. }
  270. // CreateCommentForm form for creating comment
  271. type CreateCommentForm struct {
  272. Content string
  273. Status string `binding:"OmitEmpty;In(reopen,close)"`
  274. Files []string
  275. }
  276. // Validate validates the fields
  277. func (f *CreateCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  278. return validate(errs, ctx.Data, f, ctx.Locale)
  279. }
  280. // ReactionForm form for adding and removing reaction
  281. type ReactionForm struct {
  282. Content string `binding:"Required;In(+1,-1,laugh,confused,heart,hooray)"`
  283. }
  284. // Validate validates the fields
  285. func (f *ReactionForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  286. return validate(errs, ctx.Data, f, ctx.Locale)
  287. }
  288. // IssueLockForm form for locking an issue
  289. type IssueLockForm struct {
  290. Reason string `binding:"Required"`
  291. }
  292. // Validate validates the fields
  293. func (i *IssueLockForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  294. return validate(errs, ctx.Data, i, ctx.Locale)
  295. }
  296. // HasValidReason checks to make sure that the reason submitted in
  297. // the form matches any of the values in the config
  298. func (i IssueLockForm) HasValidReason() bool {
  299. if strings.TrimSpace(i.Reason) == "" {
  300. return true
  301. }
  302. for _, v := range setting.Repository.Issue.LockReasons {
  303. if v == i.Reason {
  304. return true
  305. }
  306. }
  307. return false
  308. }
  309. // _____ .__.__ __
  310. // / \ |__| | ____ _______/ |_ ____ ____ ____
  311. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  312. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  313. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  314. // \/ \/ \/ \/ \/
  315. // CreateMilestoneForm form for creating milestone
  316. type CreateMilestoneForm struct {
  317. Title string `binding:"Required;MaxSize(50)"`
  318. Content string
  319. Deadline string
  320. }
  321. // Validate validates the fields
  322. func (f *CreateMilestoneForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  323. return validate(errs, ctx.Data, f, ctx.Locale)
  324. }
  325. // .____ ___. .__
  326. // | | _____ \_ |__ ____ | |
  327. // | | \__ \ | __ \_/ __ \| |
  328. // | |___ / __ \| \_\ \ ___/| |__
  329. // |_______ (____ /___ /\___ >____/
  330. // \/ \/ \/ \/
  331. // CreateLabelForm form for creating label
  332. type CreateLabelForm struct {
  333. ID int64
  334. Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
  335. Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
  336. Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
  337. }
  338. // Validate validates the fields
  339. func (f *CreateLabelForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  340. return validate(errs, ctx.Data, f, ctx.Locale)
  341. }
  342. // InitializeLabelsForm form for initializing labels
  343. type InitializeLabelsForm struct {
  344. TemplateName string `binding:"Required"`
  345. }
  346. // Validate validates the fields
  347. func (f *InitializeLabelsForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  348. return validate(errs, ctx.Data, f, ctx.Locale)
  349. }
  350. // __________ .__ .__ __________ __
  351. // \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
  352. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  353. // | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
  354. // |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
  355. // \/ \/ |__| \/ \/
  356. // MergePullRequestForm form for merging Pull Request
  357. // swagger:model MergePullRequestOption
  358. type MergePullRequestForm struct {
  359. // required: true
  360. // enum: merge,rebase,rebase-merge,squash
  361. Do string `binding:"Required;In(merge,rebase,rebase-merge,squash)"`
  362. MergeTitleField string
  363. MergeMessageField string
  364. }
  365. // Validate validates the fields
  366. func (f *MergePullRequestForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  367. return validate(errs, ctx.Data, f, ctx.Locale)
  368. }
  369. // CodeCommentForm form for adding code comments for PRs
  370. type CodeCommentForm struct {
  371. Content string `binding:"Required"`
  372. Side string `binding:"Required;In(previous,proposed)"`
  373. Line int64
  374. TreePath string `form:"path" binding:"Required"`
  375. IsReview bool `form:"is_review"`
  376. Reply int64 `form:"reply"`
  377. }
  378. // Validate validates the fields
  379. func (f *CodeCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  380. return validate(errs, ctx.Data, f, ctx.Locale)
  381. }
  382. // SubmitReviewForm for submitting a finished code review
  383. type SubmitReviewForm struct {
  384. Content string
  385. Type string `binding:"Required;In(approve,comment,reject)"`
  386. }
  387. // Validate validates the fields
  388. func (f *SubmitReviewForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  389. return validate(errs, ctx.Data, f, ctx.Locale)
  390. }
  391. // ReviewType will return the corresponding reviewtype for type
  392. func (f SubmitReviewForm) ReviewType() models.ReviewType {
  393. switch f.Type {
  394. case "approve":
  395. return models.ReviewTypeApprove
  396. case "comment":
  397. return models.ReviewTypeComment
  398. case "reject":
  399. return models.ReviewTypeReject
  400. default:
  401. return models.ReviewTypeUnknown
  402. }
  403. }
  404. // HasEmptyContent checks if the content of the review form is empty.
  405. func (f SubmitReviewForm) HasEmptyContent() bool {
  406. reviewType := f.ReviewType()
  407. return (reviewType == models.ReviewTypeComment || reviewType == models.ReviewTypeReject) &&
  408. len(strings.TrimSpace(f.Content)) == 0
  409. }
  410. // __________ .__
  411. // \______ \ ____ | | ____ _____ ______ ____
  412. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  413. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  414. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  415. // \/ \/ \/ \/ \/ \/
  416. // NewReleaseForm form for creating release
  417. type NewReleaseForm struct {
  418. TagName string `binding:"Required;GitRefName"`
  419. Target string `form:"tag_target" binding:"Required"`
  420. Title string `binding:"Required"`
  421. Content string
  422. Draft string
  423. Prerelease bool
  424. Files []string
  425. }
  426. // Validate validates the fields
  427. func (f *NewReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  428. return validate(errs, ctx.Data, f, ctx.Locale)
  429. }
  430. // EditReleaseForm form for changing release
  431. type EditReleaseForm struct {
  432. Title string `form:"title" binding:"Required"`
  433. Content string `form:"content"`
  434. Draft string `form:"draft"`
  435. Prerelease bool `form:"prerelease"`
  436. Files []string
  437. }
  438. // Validate validates the fields
  439. func (f *EditReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  440. return validate(errs, ctx.Data, f, ctx.Locale)
  441. }
  442. // __ __.__ __ .__
  443. // / \ / \__| | _|__|
  444. // \ \/\/ / | |/ / |
  445. // \ /| | <| |
  446. // \__/\ / |__|__|_ \__|
  447. // \/ \/
  448. // NewWikiForm form for creating wiki
  449. type NewWikiForm struct {
  450. Title string `binding:"Required"`
  451. Content string `binding:"Required"`
  452. Message string
  453. }
  454. // Validate validates the fields
  455. // FIXME: use code generation to generate this method.
  456. func (f *NewWikiForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  457. return validate(errs, ctx.Data, f, ctx.Locale)
  458. }
  459. // ___________ .___.__ __
  460. // \_ _____/ __| _/|__|/ |_
  461. // | __)_ / __ | | \ __\
  462. // | \/ /_/ | | || |
  463. // /_______ /\____ | |__||__|
  464. // \/ \/
  465. // EditRepoFileForm form for changing repository file
  466. type EditRepoFileForm struct {
  467. TreePath string `binding:"Required;MaxSize(500)"`
  468. Content string `binding:"Required"`
  469. CommitSummary string `binding:"MaxSize(100)"`
  470. CommitMessage string
  471. CommitChoice string `binding:"Required;MaxSize(50)"`
  472. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  473. LastCommit string
  474. }
  475. // Validate validates the fields
  476. func (f *EditRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  477. return validate(errs, ctx.Data, f, ctx.Locale)
  478. }
  479. // EditPreviewDiffForm form for changing preview diff
  480. type EditPreviewDiffForm struct {
  481. Content string
  482. }
  483. // Validate validates the fields
  484. func (f *EditPreviewDiffForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  485. return validate(errs, ctx.Data, f, ctx.Locale)
  486. }
  487. // ____ ___ .__ .___
  488. // | | \______ | | _________ __| _/
  489. // | | /\____ \| | / _ \__ \ / __ |
  490. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  491. // |______/ | __/|____/\____(____ /\____ |
  492. // |__| \/ \/
  493. //
  494. // UploadRepoFileForm form for uploading repository file
  495. type UploadRepoFileForm struct {
  496. TreePath string `binding:"MaxSize(500)"`
  497. CommitSummary string `binding:"MaxSize(100)"`
  498. CommitMessage string
  499. CommitChoice string `binding:"Required;MaxSize(50)"`
  500. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  501. Files []string
  502. }
  503. // Validate validates the fields
  504. func (f *UploadRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  505. return validate(errs, ctx.Data, f, ctx.Locale)
  506. }
  507. // RemoveUploadFileForm form for removing uploaded file
  508. type RemoveUploadFileForm struct {
  509. File string `binding:"Required;MaxSize(50)"`
  510. }
  511. // Validate validates the fields
  512. func (f *RemoveUploadFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  513. return validate(errs, ctx.Data, f, ctx.Locale)
  514. }
  515. // ________ .__ __
  516. // \______ \ ____ | | _____/ |_ ____
  517. // | | \_/ __ \| | _/ __ \ __\/ __ \
  518. // | ` \ ___/| |_\ ___/| | \ ___/
  519. // /_______ /\___ >____/\___ >__| \___ >
  520. // \/ \/ \/ \/
  521. // DeleteRepoFileForm form for deleting repository file
  522. type DeleteRepoFileForm struct {
  523. CommitSummary string `binding:"MaxSize(100)"`
  524. CommitMessage string
  525. CommitChoice string `binding:"Required;MaxSize(50)"`
  526. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  527. LastCommit string
  528. }
  529. // Validate validates the fields
  530. func (f *DeleteRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  531. return validate(errs, ctx.Data, f, ctx.Locale)
  532. }
  533. // ___________.__ ___________ __
  534. // \__ ___/|__| _____ ____ \__ ___/___________ ____ | | __ ___________
  535. // | | | |/ \_/ __ \ | | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
  536. // | | | | Y Y \ ___/ | | | | \// __ \\ \___| <\ ___/| | \/
  537. // |____| |__|__|_| /\___ > |____| |__| (____ /\___ >__|_ \\___ >__|
  538. // \/ \/ \/ \/ \/ \/
  539. // AddTimeManuallyForm form that adds spent time manually.
  540. type AddTimeManuallyForm struct {
  541. Hours int `binding:"Range(0,1000)"`
  542. Minutes int `binding:"Range(0,1000)"`
  543. }
  544. // Validate validates the fields
  545. func (f *AddTimeManuallyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  546. return validate(errs, ctx.Data, f, ctx.Locale)
  547. }
  548. // SaveTopicForm form for save topics for repository
  549. type SaveTopicForm struct {
  550. Topics []string `binding:"topics;Required;"`
  551. }
  552. // DeadlineForm hold the validation rules for deadlines
  553. type DeadlineForm struct {
  554. DateString string `form:"date" binding:"Required;Size(10)"`
  555. }
  556. // Validate validates the fields
  557. func (f *DeadlineForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  558. return validate(errs, ctx.Data, f, ctx.Locale)
  559. }