Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

repo_form.go 22KB

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