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 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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. }
  156. // Validate validates the fields
  157. func (f *ProtectBranchForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  158. return validate(errs, ctx.Data, f, ctx.Locale)
  159. }
  160. // __ __ ___. .__ .__ __
  161. // / \ / \ ____\_ |__ | |__ | |__ ____ | | __
  162. // \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
  163. // \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
  164. // \__/\ / \___ >___ /___| /___| /\____/|__|_ \
  165. // \/ \/ \/ \/ \/ \/
  166. // WebhookForm form for changing web hook
  167. type WebhookForm struct {
  168. Events string
  169. Create bool
  170. Delete bool
  171. Fork bool
  172. Issues bool
  173. IssueComment bool
  174. Release bool
  175. Push bool
  176. PullRequest bool
  177. Repository bool
  178. Active bool
  179. BranchFilter string `binding:"GlobPattern"`
  180. }
  181. // PushOnly if the hook will be triggered when push
  182. func (f WebhookForm) PushOnly() bool {
  183. return f.Events == "push_only"
  184. }
  185. // SendEverything if the hook will be triggered any event
  186. func (f WebhookForm) SendEverything() bool {
  187. return f.Events == "send_everything"
  188. }
  189. // ChooseEvents if the hook will be triggered choose events
  190. func (f WebhookForm) ChooseEvents() bool {
  191. return f.Events == "choose_events"
  192. }
  193. // NewWebhookForm form for creating web hook
  194. type NewWebhookForm struct {
  195. PayloadURL string `binding:"Required;ValidUrl"`
  196. HTTPMethod string `binding:"Required;In(POST,GET)"`
  197. ContentType int `binding:"Required"`
  198. Secret string
  199. WebhookForm
  200. }
  201. // Validate validates the fields
  202. func (f *NewWebhookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  203. return validate(errs, ctx.Data, f, ctx.Locale)
  204. }
  205. // NewGogshookForm form for creating gogs hook
  206. type NewGogshookForm struct {
  207. PayloadURL string `binding:"Required;ValidUrl"`
  208. ContentType int `binding:"Required"`
  209. Secret string
  210. WebhookForm
  211. }
  212. // Validate validates the fields
  213. func (f *NewGogshookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  214. return validate(errs, ctx.Data, f, ctx.Locale)
  215. }
  216. // NewSlackHookForm form for creating slack hook
  217. type NewSlackHookForm struct {
  218. PayloadURL string `binding:"Required;ValidUrl"`
  219. Channel string `binding:"Required"`
  220. Username string
  221. IconURL string
  222. Color string
  223. WebhookForm
  224. }
  225. // Validate validates the fields
  226. func (f *NewSlackHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  227. return validate(errs, ctx.Data, f, ctx.Locale)
  228. }
  229. // HasInvalidChannel validates the channel name is in the right format
  230. func (f NewSlackHookForm) HasInvalidChannel() bool {
  231. return !utils.IsValidSlackChannel(f.Channel)
  232. }
  233. // NewDiscordHookForm form for creating discord hook
  234. type NewDiscordHookForm struct {
  235. PayloadURL string `binding:"Required;ValidUrl"`
  236. Username string
  237. IconURL string
  238. WebhookForm
  239. }
  240. // Validate validates the fields
  241. func (f *NewDiscordHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  242. return validate(errs, ctx.Data, f, ctx.Locale)
  243. }
  244. // NewDingtalkHookForm form for creating dingtalk hook
  245. type NewDingtalkHookForm struct {
  246. PayloadURL string `binding:"Required;ValidUrl"`
  247. WebhookForm
  248. }
  249. // Validate validates the fields
  250. func (f *NewDingtalkHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  251. return validate(errs, ctx.Data, f, ctx.Locale)
  252. }
  253. // NewTelegramHookForm form for creating telegram hook
  254. type NewTelegramHookForm struct {
  255. BotToken string `binding:"Required"`
  256. ChatID string `binding:"Required"`
  257. WebhookForm
  258. }
  259. // Validate validates the fields
  260. func (f *NewTelegramHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  261. return validate(errs, ctx.Data, f, ctx.Locale)
  262. }
  263. // NewMSTeamsHookForm form for creating MS Teams hook
  264. type NewMSTeamsHookForm struct {
  265. PayloadURL string `binding:"Required;ValidUrl"`
  266. WebhookForm
  267. }
  268. // Validate validates the fields
  269. func (f *NewMSTeamsHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  270. return validate(errs, ctx.Data, f, ctx.Locale)
  271. }
  272. // .___
  273. // | | ______ ________ __ ____
  274. // | |/ ___// ___/ | \_/ __ \
  275. // | |\___ \ \___ \| | /\ ___/
  276. // |___/____ >____ >____/ \___ >
  277. // \/ \/ \/
  278. // CreateIssueForm form for creating issue
  279. type CreateIssueForm struct {
  280. Title string `binding:"Required;MaxSize(255)"`
  281. LabelIDs string `form:"label_ids"`
  282. AssigneeIDs string `form:"assignee_ids"`
  283. Ref string `form:"ref"`
  284. MilestoneID int64
  285. AssigneeID int64
  286. Content string
  287. Files []string
  288. }
  289. // Validate validates the fields
  290. func (f *CreateIssueForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  291. return validate(errs, ctx.Data, f, ctx.Locale)
  292. }
  293. // CreateCommentForm form for creating comment
  294. type CreateCommentForm struct {
  295. Content string
  296. Status string `binding:"OmitEmpty;In(reopen,close)"`
  297. Files []string
  298. }
  299. // Validate validates the fields
  300. func (f *CreateCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  301. return validate(errs, ctx.Data, f, ctx.Locale)
  302. }
  303. // ReactionForm form for adding and removing reaction
  304. type ReactionForm struct {
  305. Content string `binding:"Required"`
  306. }
  307. // Validate validates the fields
  308. func (f *ReactionForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  309. return validate(errs, ctx.Data, f, ctx.Locale)
  310. }
  311. // IssueLockForm form for locking an issue
  312. type IssueLockForm struct {
  313. Reason string `binding:"Required"`
  314. }
  315. // Validate validates the fields
  316. func (i *IssueLockForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  317. return validate(errs, ctx.Data, i, ctx.Locale)
  318. }
  319. // HasValidReason checks to make sure that the reason submitted in
  320. // the form matches any of the values in the config
  321. func (i IssueLockForm) HasValidReason() bool {
  322. if strings.TrimSpace(i.Reason) == "" {
  323. return true
  324. }
  325. for _, v := range setting.Repository.Issue.LockReasons {
  326. if v == i.Reason {
  327. return true
  328. }
  329. }
  330. return false
  331. }
  332. // _____ .__.__ __
  333. // / \ |__| | ____ _______/ |_ ____ ____ ____
  334. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  335. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  336. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  337. // \/ \/ \/ \/ \/
  338. // CreateMilestoneForm form for creating milestone
  339. type CreateMilestoneForm struct {
  340. Title string `binding:"Required;MaxSize(50)"`
  341. Content string
  342. Deadline string
  343. }
  344. // Validate validates the fields
  345. func (f *CreateMilestoneForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  346. return validate(errs, ctx.Data, f, ctx.Locale)
  347. }
  348. // .____ ___. .__
  349. // | | _____ \_ |__ ____ | |
  350. // | | \__ \ | __ \_/ __ \| |
  351. // | |___ / __ \| \_\ \ ___/| |__
  352. // |_______ (____ /___ /\___ >____/
  353. // \/ \/ \/ \/
  354. // CreateLabelForm form for creating label
  355. type CreateLabelForm struct {
  356. ID int64
  357. Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
  358. Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
  359. Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
  360. }
  361. // Validate validates the fields
  362. func (f *CreateLabelForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  363. return validate(errs, ctx.Data, f, ctx.Locale)
  364. }
  365. // InitializeLabelsForm form for initializing labels
  366. type InitializeLabelsForm struct {
  367. TemplateName string `binding:"Required"`
  368. }
  369. // Validate validates the fields
  370. func (f *InitializeLabelsForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  371. return validate(errs, ctx.Data, f, ctx.Locale)
  372. }
  373. // __________ .__ .__ __________ __
  374. // \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
  375. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  376. // | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
  377. // |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
  378. // \/ \/ |__| \/ \/
  379. // MergePullRequestForm form for merging Pull Request
  380. // swagger:model MergePullRequestOption
  381. type MergePullRequestForm struct {
  382. // required: true
  383. // enum: merge,rebase,rebase-merge,squash
  384. Do string `binding:"Required;In(merge,rebase,rebase-merge,squash)"`
  385. MergeTitleField string
  386. MergeMessageField string
  387. }
  388. // Validate validates the fields
  389. func (f *MergePullRequestForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  390. return validate(errs, ctx.Data, f, ctx.Locale)
  391. }
  392. // CodeCommentForm form for adding code comments for PRs
  393. type CodeCommentForm struct {
  394. Content string `binding:"Required"`
  395. Side string `binding:"Required;In(previous,proposed)"`
  396. Line int64
  397. TreePath string `form:"path" binding:"Required"`
  398. IsReview bool `form:"is_review"`
  399. Reply int64 `form:"reply"`
  400. }
  401. // Validate validates the fields
  402. func (f *CodeCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  403. return validate(errs, ctx.Data, f, ctx.Locale)
  404. }
  405. // SubmitReviewForm for submitting a finished code review
  406. type SubmitReviewForm struct {
  407. Content string
  408. Type string `binding:"Required;In(approve,comment,reject)"`
  409. }
  410. // Validate validates the fields
  411. func (f *SubmitReviewForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  412. return validate(errs, ctx.Data, f, ctx.Locale)
  413. }
  414. // ReviewType will return the corresponding reviewtype for type
  415. func (f SubmitReviewForm) ReviewType() models.ReviewType {
  416. switch f.Type {
  417. case "approve":
  418. return models.ReviewTypeApprove
  419. case "comment":
  420. return models.ReviewTypeComment
  421. case "reject":
  422. return models.ReviewTypeReject
  423. default:
  424. return models.ReviewTypeUnknown
  425. }
  426. }
  427. // HasEmptyContent checks if the content of the review form is empty.
  428. func (f SubmitReviewForm) HasEmptyContent() bool {
  429. reviewType := f.ReviewType()
  430. return (reviewType == models.ReviewTypeComment || reviewType == models.ReviewTypeReject) &&
  431. len(strings.TrimSpace(f.Content)) == 0
  432. }
  433. // __________ .__
  434. // \______ \ ____ | | ____ _____ ______ ____
  435. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  436. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  437. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  438. // \/ \/ \/ \/ \/ \/
  439. // NewReleaseForm form for creating release
  440. type NewReleaseForm struct {
  441. TagName string `binding:"Required;GitRefName;MaxSize(255)"`
  442. Target string `form:"tag_target" binding:"Required;MaxSize(255)"`
  443. Title string `binding:"Required;MaxSize(255)"`
  444. Content string
  445. Draft string
  446. Prerelease bool
  447. Files []string
  448. }
  449. // Validate validates the fields
  450. func (f *NewReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  451. return validate(errs, ctx.Data, f, ctx.Locale)
  452. }
  453. // EditReleaseForm form for changing release
  454. type EditReleaseForm struct {
  455. Title string `form:"title" binding:"Required;MaxSize(255)"`
  456. Content string `form:"content"`
  457. Draft string `form:"draft"`
  458. Prerelease bool `form:"prerelease"`
  459. Files []string
  460. }
  461. // Validate validates the fields
  462. func (f *EditReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  463. return validate(errs, ctx.Data, f, ctx.Locale)
  464. }
  465. // __ __.__ __ .__
  466. // / \ / \__| | _|__|
  467. // \ \/\/ / | |/ / |
  468. // \ /| | <| |
  469. // \__/\ / |__|__|_ \__|
  470. // \/ \/
  471. // NewWikiForm form for creating wiki
  472. type NewWikiForm struct {
  473. Title string `binding:"Required"`
  474. Content string `binding:"Required"`
  475. Message string
  476. }
  477. // Validate validates the fields
  478. // FIXME: use code generation to generate this method.
  479. func (f *NewWikiForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  480. return validate(errs, ctx.Data, f, ctx.Locale)
  481. }
  482. // ___________ .___.__ __
  483. // \_ _____/ __| _/|__|/ |_
  484. // | __)_ / __ | | \ __\
  485. // | \/ /_/ | | || |
  486. // /_______ /\____ | |__||__|
  487. // \/ \/
  488. // EditRepoFileForm form for changing repository file
  489. type EditRepoFileForm struct {
  490. TreePath string `binding:"Required;MaxSize(500)"`
  491. Content string
  492. CommitSummary string `binding:"MaxSize(100)"`
  493. CommitMessage string
  494. CommitChoice string `binding:"Required;MaxSize(50)"`
  495. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  496. LastCommit string
  497. }
  498. // Validate validates the fields
  499. func (f *EditRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  500. return validate(errs, ctx.Data, f, ctx.Locale)
  501. }
  502. // EditPreviewDiffForm form for changing preview diff
  503. type EditPreviewDiffForm struct {
  504. Content string
  505. }
  506. // Validate validates the fields
  507. func (f *EditPreviewDiffForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  508. return validate(errs, ctx.Data, f, ctx.Locale)
  509. }
  510. // ____ ___ .__ .___
  511. // | | \______ | | _________ __| _/
  512. // | | /\____ \| | / _ \__ \ / __ |
  513. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  514. // |______/ | __/|____/\____(____ /\____ |
  515. // |__| \/ \/
  516. //
  517. // UploadRepoFileForm form for uploading repository file
  518. type UploadRepoFileForm struct {
  519. TreePath string `binding:"MaxSize(500)"`
  520. CommitSummary string `binding:"MaxSize(100)"`
  521. CommitMessage string
  522. CommitChoice string `binding:"Required;MaxSize(50)"`
  523. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  524. Files []string
  525. }
  526. // Validate validates the fields
  527. func (f *UploadRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  528. return validate(errs, ctx.Data, f, ctx.Locale)
  529. }
  530. // RemoveUploadFileForm form for removing uploaded file
  531. type RemoveUploadFileForm struct {
  532. File string `binding:"Required;MaxSize(50)"`
  533. }
  534. // Validate validates the fields
  535. func (f *RemoveUploadFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  536. return validate(errs, ctx.Data, f, ctx.Locale)
  537. }
  538. // ________ .__ __
  539. // \______ \ ____ | | _____/ |_ ____
  540. // | | \_/ __ \| | _/ __ \ __\/ __ \
  541. // | ` \ ___/| |_\ ___/| | \ ___/
  542. // /_______ /\___ >____/\___ >__| \___ >
  543. // \/ \/ \/ \/
  544. // DeleteRepoFileForm form for deleting repository file
  545. type DeleteRepoFileForm struct {
  546. CommitSummary string `binding:"MaxSize(100)"`
  547. CommitMessage string
  548. CommitChoice string `binding:"Required;MaxSize(50)"`
  549. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  550. LastCommit string
  551. }
  552. // Validate validates the fields
  553. func (f *DeleteRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  554. return validate(errs, ctx.Data, f, ctx.Locale)
  555. }
  556. // ___________.__ ___________ __
  557. // \__ ___/|__| _____ ____ \__ ___/___________ ____ | | __ ___________
  558. // | | | |/ \_/ __ \ | | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
  559. // | | | | Y Y \ ___/ | | | | \// __ \\ \___| <\ ___/| | \/
  560. // |____| |__|__|_| /\___ > |____| |__| (____ /\___ >__|_ \\___ >__|
  561. // \/ \/ \/ \/ \/ \/
  562. // AddTimeManuallyForm form that adds spent time manually.
  563. type AddTimeManuallyForm struct {
  564. Hours int `binding:"Range(0,1000)"`
  565. Minutes int `binding:"Range(0,1000)"`
  566. }
  567. // Validate validates the fields
  568. func (f *AddTimeManuallyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  569. return validate(errs, ctx.Data, f, ctx.Locale)
  570. }
  571. // SaveTopicForm form for save topics for repository
  572. type SaveTopicForm struct {
  573. Topics []string `binding:"topics;Required;"`
  574. }
  575. // DeadlineForm hold the validation rules for deadlines
  576. type DeadlineForm struct {
  577. DateString string `form:"date" binding:"Required;Size(10)"`
  578. }
  579. // Validate validates the fields
  580. func (f *DeadlineForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
  581. return validate(errs, ctx.Data, f, ctx.Locale)
  582. }