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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806
  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 forms
  6. import (
  7. "net/http"
  8. "net/url"
  9. "strings"
  10. "code.gitea.io/gitea/models"
  11. "code.gitea.io/gitea/modules/context"
  12. "code.gitea.io/gitea/modules/setting"
  13. "code.gitea.io/gitea/modules/structs"
  14. "code.gitea.io/gitea/modules/web/middleware"
  15. "code.gitea.io/gitea/routers/utils"
  16. "gitea.com/go-chi/binding"
  17. )
  18. // _______________________________________ _________.______________________ _______________.___.
  19. // \______ \_ _____/\______ \_____ \ / _____/| \__ ___/\_____ \\______ \__ | |
  20. // | _/| __)_ | ___// | \ \_____ \ | | | | / | \| _// | |
  21. // | | \| \ | | / | \/ \| | | | / | \ | \\____ |
  22. // |____|_ /_______ / |____| \_______ /_______ /|___| |____| \_______ /____|_ // ______|
  23. // \/ \/ \/ \/ \/ \/ \/
  24. // CreateRepoForm form for creating repository
  25. type CreateRepoForm struct {
  26. UID int64 `binding:"Required"`
  27. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  28. Private bool
  29. Description string `binding:"MaxSize(255)"`
  30. DefaultBranch string `binding:"GitRefName;MaxSize(100)"`
  31. AutoInit bool
  32. Gitignores string
  33. IssueLabels string
  34. License string
  35. Readme string
  36. Template bool
  37. RepoTemplate int64
  38. GitContent bool
  39. Topics bool
  40. GitHooks bool
  41. Webhooks bool
  42. Avatar bool
  43. Labels bool
  44. TrustModel string
  45. }
  46. // Validate validates the fields
  47. func (f *CreateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  48. ctx := context.GetContext(req)
  49. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  50. }
  51. // MigrateRepoForm form for migrating repository
  52. // this is used to interact with web ui
  53. type MigrateRepoForm struct {
  54. // required: true
  55. CloneAddr string `json:"clone_addr" binding:"Required"`
  56. Service structs.GitServiceType `json:"service"`
  57. AuthUsername string `json:"auth_username"`
  58. AuthPassword string `json:"auth_password"`
  59. AuthToken string `json:"auth_token"`
  60. // required: true
  61. UID int64 `json:"uid" binding:"Required"`
  62. // required: true
  63. RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
  64. Mirror bool `json:"mirror"`
  65. Private bool `json:"private"`
  66. Description string `json:"description" binding:"MaxSize(255)"`
  67. Wiki bool `json:"wiki"`
  68. Milestones bool `json:"milestones"`
  69. Labels bool `json:"labels"`
  70. Issues bool `json:"issues"`
  71. PullRequests bool `json:"pull_requests"`
  72. Releases bool `json:"releases"`
  73. MirrorInterval string `json:"mirror_interval"`
  74. }
  75. // Validate validates the fields
  76. func (f *MigrateRepoForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  77. ctx := context.GetContext(req)
  78. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  79. }
  80. // ParseRemoteAddr checks if given remote address is valid,
  81. // and returns composed URL with needed username and password.
  82. func ParseRemoteAddr(remoteAddr, authUsername, authPassword string) (string, error) {
  83. remoteAddr = strings.TrimSpace(remoteAddr)
  84. // Remote address can be HTTP/HTTPS/Git URL or local path.
  85. if strings.HasPrefix(remoteAddr, "http://") ||
  86. strings.HasPrefix(remoteAddr, "https://") ||
  87. strings.HasPrefix(remoteAddr, "git://") {
  88. u, err := url.Parse(remoteAddr)
  89. if err != nil {
  90. return "", &models.ErrInvalidCloneAddr{IsURLError: true}
  91. }
  92. if len(authUsername)+len(authPassword) > 0 {
  93. u.User = url.UserPassword(authUsername, authPassword)
  94. }
  95. remoteAddr = u.String()
  96. }
  97. return remoteAddr, nil
  98. }
  99. // RepoSettingForm form for changing repository settings
  100. type RepoSettingForm struct {
  101. RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
  102. Description string `binding:"MaxSize(255)"`
  103. Website string `binding:"ValidUrl;MaxSize(255)"`
  104. Interval string
  105. MirrorAddress string
  106. MirrorUsername string
  107. MirrorPassword string
  108. Private bool
  109. Template bool
  110. EnablePrune bool
  111. // Advanced settings
  112. EnableWiki bool
  113. EnableExternalWiki bool
  114. ExternalWikiURL string
  115. EnableIssues bool
  116. EnableExternalTracker bool
  117. ExternalTrackerURL string
  118. TrackerURLFormat string
  119. TrackerIssueStyle string
  120. EnableProjects bool
  121. EnablePulls bool
  122. PullsIgnoreWhitespace bool
  123. PullsAllowMerge bool
  124. PullsAllowRebase bool
  125. PullsAllowRebaseMerge bool
  126. PullsAllowSquash bool
  127. PullsAllowManualMerge bool
  128. EnableAutodetectManualMerge bool
  129. EnableTimetracker bool
  130. AllowOnlyContributorsToTrackTime bool
  131. EnableIssueDependencies bool
  132. IsArchived bool
  133. // Signing Settings
  134. TrustModel string
  135. // Admin settings
  136. EnableHealthCheck bool
  137. EnableCloseIssuesViaCommitInAnyBranch bool
  138. }
  139. // Validate validates the fields
  140. func (f *RepoSettingForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  141. ctx := context.GetContext(req)
  142. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  143. }
  144. // __________ .__
  145. // \______ \____________ ____ ____ | |__
  146. // | | _/\_ __ \__ \ / \_/ ___\| | \
  147. // | | \ | | \// __ \| | \ \___| Y \
  148. // |______ / |__| (____ /___| /\___ >___| /
  149. // \/ \/ \/ \/ \/
  150. // ProtectBranchForm form for changing protected branch settings
  151. type ProtectBranchForm struct {
  152. Protected bool
  153. EnablePush string
  154. WhitelistUsers string
  155. WhitelistTeams string
  156. WhitelistDeployKeys bool
  157. EnableMergeWhitelist bool
  158. MergeWhitelistUsers string
  159. MergeWhitelistTeams string
  160. EnableStatusCheck bool
  161. StatusCheckContexts []string
  162. RequiredApprovals int64
  163. EnableApprovalsWhitelist bool
  164. ApprovalsWhitelistUsers string
  165. ApprovalsWhitelistTeams string
  166. BlockOnRejectedReviews bool
  167. BlockOnOfficialReviewRequests bool
  168. BlockOnOutdatedBranch bool
  169. DismissStaleApprovals bool
  170. RequireSignedCommits bool
  171. ProtectedFilePatterns string
  172. }
  173. // Validate validates the fields
  174. func (f *ProtectBranchForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  175. ctx := context.GetContext(req)
  176. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  177. }
  178. // __ __ ___. .__ .__ __
  179. // / \ / \ ____\_ |__ | |__ | |__ ____ | | __
  180. // \ \/\/ // __ \| __ \| | \| | \ / _ \| |/ /
  181. // \ /\ ___/| \_\ \ Y \ Y ( <_> ) <
  182. // \__/\ / \___ >___ /___| /___| /\____/|__|_ \
  183. // \/ \/ \/ \/ \/ \/
  184. // WebhookForm form for changing web hook
  185. type WebhookForm struct {
  186. Events string
  187. Create bool
  188. Delete bool
  189. Fork bool
  190. Issues bool
  191. IssueAssign bool
  192. IssueLabel bool
  193. IssueMilestone bool
  194. IssueComment bool
  195. Release bool
  196. Push bool
  197. PullRequest bool
  198. PullRequestAssign bool
  199. PullRequestLabel bool
  200. PullRequestMilestone bool
  201. PullRequestComment bool
  202. PullRequestReview bool
  203. PullRequestSync bool
  204. Repository bool
  205. Active bool
  206. BranchFilter string `binding:"GlobPattern"`
  207. }
  208. // PushOnly if the hook will be triggered when push
  209. func (f WebhookForm) PushOnly() bool {
  210. return f.Events == "push_only"
  211. }
  212. // SendEverything if the hook will be triggered any event
  213. func (f WebhookForm) SendEverything() bool {
  214. return f.Events == "send_everything"
  215. }
  216. // ChooseEvents if the hook will be triggered choose events
  217. func (f WebhookForm) ChooseEvents() bool {
  218. return f.Events == "choose_events"
  219. }
  220. // NewWebhookForm form for creating web hook
  221. type NewWebhookForm struct {
  222. PayloadURL string `binding:"Required;ValidUrl"`
  223. HTTPMethod string `binding:"Required;In(POST,GET)"`
  224. ContentType int `binding:"Required"`
  225. Secret string
  226. WebhookForm
  227. }
  228. // Validate validates the fields
  229. func (f *NewWebhookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  230. ctx := context.GetContext(req)
  231. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  232. }
  233. // NewGogshookForm form for creating gogs hook
  234. type NewGogshookForm struct {
  235. PayloadURL string `binding:"Required;ValidUrl"`
  236. ContentType int `binding:"Required"`
  237. Secret string
  238. WebhookForm
  239. }
  240. // Validate validates the fields
  241. func (f *NewGogshookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  242. ctx := context.GetContext(req)
  243. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  244. }
  245. // NewSlackHookForm form for creating slack hook
  246. type NewSlackHookForm struct {
  247. PayloadURL string `binding:"Required;ValidUrl"`
  248. Channel string `binding:"Required"`
  249. Username string
  250. IconURL string
  251. Color string
  252. WebhookForm
  253. }
  254. // Validate validates the fields
  255. func (f *NewSlackHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  256. ctx := context.GetContext(req)
  257. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  258. }
  259. // HasInvalidChannel validates the channel name is in the right format
  260. func (f NewSlackHookForm) HasInvalidChannel() bool {
  261. return !utils.IsValidSlackChannel(f.Channel)
  262. }
  263. // NewDiscordHookForm form for creating discord hook
  264. type NewDiscordHookForm struct {
  265. PayloadURL string `binding:"Required;ValidUrl"`
  266. Username string
  267. IconURL string
  268. WebhookForm
  269. }
  270. // Validate validates the fields
  271. func (f *NewDiscordHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  272. ctx := context.GetContext(req)
  273. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  274. }
  275. // NewDingtalkHookForm form for creating dingtalk hook
  276. type NewDingtalkHookForm struct {
  277. PayloadURL string `binding:"Required;ValidUrl"`
  278. WebhookForm
  279. }
  280. // Validate validates the fields
  281. func (f *NewDingtalkHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  282. ctx := context.GetContext(req)
  283. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  284. }
  285. // NewTelegramHookForm form for creating telegram hook
  286. type NewTelegramHookForm struct {
  287. BotToken string `binding:"Required"`
  288. ChatID string `binding:"Required"`
  289. WebhookForm
  290. }
  291. // Validate validates the fields
  292. func (f *NewTelegramHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  293. ctx := context.GetContext(req)
  294. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  295. }
  296. // NewMatrixHookForm form for creating Matrix hook
  297. type NewMatrixHookForm struct {
  298. HomeserverURL string `binding:"Required;ValidUrl"`
  299. RoomID string `binding:"Required"`
  300. AccessToken string `binding:"Required"`
  301. MessageType int
  302. WebhookForm
  303. }
  304. // Validate validates the fields
  305. func (f *NewMatrixHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  306. ctx := context.GetContext(req)
  307. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  308. }
  309. // NewMSTeamsHookForm form for creating MS Teams hook
  310. type NewMSTeamsHookForm struct {
  311. PayloadURL string `binding:"Required;ValidUrl"`
  312. WebhookForm
  313. }
  314. // Validate validates the fields
  315. func (f *NewMSTeamsHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  316. ctx := context.GetContext(req)
  317. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  318. }
  319. // NewFeishuHookForm form for creating feishu hook
  320. type NewFeishuHookForm struct {
  321. PayloadURL string `binding:"Required;ValidUrl"`
  322. WebhookForm
  323. }
  324. // Validate validates the fields
  325. func (f *NewFeishuHookForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  326. ctx := context.GetContext(req)
  327. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  328. }
  329. // .___
  330. // | | ______ ________ __ ____
  331. // | |/ ___// ___/ | \_/ __ \
  332. // | |\___ \ \___ \| | /\ ___/
  333. // |___/____ >____ >____/ \___ >
  334. // \/ \/ \/
  335. // CreateIssueForm form for creating issue
  336. type CreateIssueForm struct {
  337. Title string `binding:"Required;MaxSize(255)"`
  338. LabelIDs string `form:"label_ids"`
  339. AssigneeIDs string `form:"assignee_ids"`
  340. Ref string `form:"ref"`
  341. MilestoneID int64
  342. ProjectID int64
  343. AssigneeID int64
  344. Content string
  345. Files []string
  346. }
  347. // Validate validates the fields
  348. func (f *CreateIssueForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  349. ctx := context.GetContext(req)
  350. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  351. }
  352. // CreateCommentForm form for creating comment
  353. type CreateCommentForm struct {
  354. Content string
  355. Status string `binding:"OmitEmpty;In(reopen,close)"`
  356. Files []string
  357. }
  358. // Validate validates the fields
  359. func (f *CreateCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  360. ctx := context.GetContext(req)
  361. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  362. }
  363. // ReactionForm form for adding and removing reaction
  364. type ReactionForm struct {
  365. Content string `binding:"Required"`
  366. }
  367. // Validate validates the fields
  368. func (f *ReactionForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  369. ctx := context.GetContext(req)
  370. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  371. }
  372. // IssueLockForm form for locking an issue
  373. type IssueLockForm struct {
  374. Reason string `binding:"Required"`
  375. }
  376. // Validate validates the fields
  377. func (i *IssueLockForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  378. ctx := context.GetContext(req)
  379. return middleware.Validate(errs, ctx.Data, i, ctx.Locale)
  380. }
  381. // HasValidReason checks to make sure that the reason submitted in
  382. // the form matches any of the values in the config
  383. func (i IssueLockForm) HasValidReason() bool {
  384. if strings.TrimSpace(i.Reason) == "" {
  385. return true
  386. }
  387. for _, v := range setting.Repository.Issue.LockReasons {
  388. if v == i.Reason {
  389. return true
  390. }
  391. }
  392. return false
  393. }
  394. // __________ __ __
  395. // \______ \_______ ____ |__| ____ _____/ |_ ______
  396. // | ___/\_ __ \/ _ \ | |/ __ \_/ ___\ __\/ ___/
  397. // | | | | \( <_> ) | \ ___/\ \___| | \___ \
  398. // |____| |__| \____/\__| |\___ >\___ >__| /____ >
  399. // \______| \/ \/ \/
  400. // CreateProjectForm form for creating a project
  401. type CreateProjectForm struct {
  402. Title string `binding:"Required;MaxSize(100)"`
  403. Content string
  404. BoardType models.ProjectBoardType
  405. }
  406. // UserCreateProjectForm is a from for creating an individual or organization
  407. // form.
  408. type UserCreateProjectForm struct {
  409. Title string `binding:"Required;MaxSize(100)"`
  410. Content string
  411. BoardType models.ProjectBoardType
  412. UID int64 `binding:"Required"`
  413. }
  414. // EditProjectBoardForm is a form for editing a project board
  415. type EditProjectBoardForm struct {
  416. Title string `binding:"Required;MaxSize(100)"`
  417. Sorting int8
  418. }
  419. // _____ .__.__ __
  420. // / \ |__| | ____ _______/ |_ ____ ____ ____
  421. // / \ / \| | | _/ __ \ / ___/\ __\/ _ \ / \_/ __ \
  422. // / Y \ | |_\ ___/ \___ \ | | ( <_> ) | \ ___/
  423. // \____|__ /__|____/\___ >____ > |__| \____/|___| /\___ >
  424. // \/ \/ \/ \/ \/
  425. // CreateMilestoneForm form for creating milestone
  426. type CreateMilestoneForm struct {
  427. Title string `binding:"Required;MaxSize(50)"`
  428. Content string
  429. Deadline string
  430. }
  431. // Validate validates the fields
  432. func (f *CreateMilestoneForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  433. ctx := context.GetContext(req)
  434. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  435. }
  436. // .____ ___. .__
  437. // | | _____ \_ |__ ____ | |
  438. // | | \__ \ | __ \_/ __ \| |
  439. // | |___ / __ \| \_\ \ ___/| |__
  440. // |_______ (____ /___ /\___ >____/
  441. // \/ \/ \/ \/
  442. // CreateLabelForm form for creating label
  443. type CreateLabelForm struct {
  444. ID int64
  445. Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
  446. Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
  447. Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
  448. }
  449. // Validate validates the fields
  450. func (f *CreateLabelForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  451. ctx := context.GetContext(req)
  452. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  453. }
  454. // InitializeLabelsForm form for initializing labels
  455. type InitializeLabelsForm struct {
  456. TemplateName string `binding:"Required"`
  457. }
  458. // Validate validates the fields
  459. func (f *InitializeLabelsForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  460. ctx := context.GetContext(req)
  461. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  462. }
  463. // __________ .__ .__ __________ __
  464. // \______ \__ __| | | | \______ \ ____ ________ __ ____ _______/ |_
  465. // | ___/ | \ | | | | _// __ \/ ____/ | \_/ __ \ / ___/\ __\
  466. // | | | | / |_| |__ | | \ ___< <_| | | /\ ___/ \___ \ | |
  467. // |____| |____/|____/____/ |____|_ /\___ >__ |____/ \___ >____ > |__|
  468. // \/ \/ |__| \/ \/
  469. // MergePullRequestForm form for merging Pull Request
  470. // swagger:model MergePullRequestOption
  471. type MergePullRequestForm struct {
  472. // required: true
  473. // enum: merge,rebase,rebase-merge,squash,manually-merged
  474. Do string `binding:"Required;In(merge,rebase,rebase-merge,squash,manually-merged)"`
  475. MergeTitleField string
  476. MergeMessageField string
  477. MergeCommitID string // only used for manually-merged
  478. ForceMerge *bool `json:"force_merge,omitempty"`
  479. }
  480. // Validate validates the fields
  481. func (f *MergePullRequestForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  482. ctx := context.GetContext(req)
  483. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  484. }
  485. // CodeCommentForm form for adding code comments for PRs
  486. type CodeCommentForm struct {
  487. Origin string `binding:"Required;In(timeline,diff)"`
  488. Content string `binding:"Required"`
  489. Side string `binding:"Required;In(previous,proposed)"`
  490. Line int64
  491. TreePath string `form:"path" binding:"Required"`
  492. IsReview bool `form:"is_review"`
  493. Reply int64 `form:"reply"`
  494. LatestCommitID string
  495. }
  496. // Validate validates the fields
  497. func (f *CodeCommentForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  498. ctx := context.GetContext(req)
  499. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  500. }
  501. // SubmitReviewForm for submitting a finished code review
  502. type SubmitReviewForm struct {
  503. Content string
  504. Type string `binding:"Required;In(approve,comment,reject)"`
  505. CommitID string
  506. }
  507. // Validate validates the fields
  508. func (f *SubmitReviewForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  509. ctx := context.GetContext(req)
  510. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  511. }
  512. // ReviewType will return the corresponding reviewtype for type
  513. func (f SubmitReviewForm) ReviewType() models.ReviewType {
  514. switch f.Type {
  515. case "approve":
  516. return models.ReviewTypeApprove
  517. case "comment":
  518. return models.ReviewTypeComment
  519. case "reject":
  520. return models.ReviewTypeReject
  521. default:
  522. return models.ReviewTypeUnknown
  523. }
  524. }
  525. // HasEmptyContent checks if the content of the review form is empty.
  526. func (f SubmitReviewForm) HasEmptyContent() bool {
  527. reviewType := f.ReviewType()
  528. return (reviewType == models.ReviewTypeComment || reviewType == models.ReviewTypeReject) &&
  529. len(strings.TrimSpace(f.Content)) == 0
  530. }
  531. // DismissReviewForm for dismissing stale review by repo admin
  532. type DismissReviewForm struct {
  533. ReviewID int64 `binding:"Required"`
  534. Message string
  535. }
  536. // __________ .__
  537. // \______ \ ____ | | ____ _____ ______ ____
  538. // | _// __ \| | _/ __ \\__ \ / ___// __ \
  539. // | | \ ___/| |_\ ___/ / __ \_\___ \\ ___/
  540. // |____|_ /\___ >____/\___ >____ /____ >\___ >
  541. // \/ \/ \/ \/ \/ \/
  542. // NewReleaseForm form for creating release
  543. type NewReleaseForm struct {
  544. TagName string `binding:"Required;GitRefName;MaxSize(255)"`
  545. Target string `form:"tag_target" binding:"Required;MaxSize(255)"`
  546. Title string `binding:"Required;MaxSize(255)"`
  547. Content string
  548. Draft string
  549. TagOnly string
  550. Prerelease bool
  551. AddTagMsg bool
  552. Files []string
  553. }
  554. // Validate validates the fields
  555. func (f *NewReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  556. ctx := context.GetContext(req)
  557. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  558. }
  559. // EditReleaseForm form for changing release
  560. type EditReleaseForm struct {
  561. Title string `form:"title" binding:"Required;MaxSize(255)"`
  562. Content string `form:"content"`
  563. Draft string `form:"draft"`
  564. Prerelease bool `form:"prerelease"`
  565. Files []string
  566. }
  567. // Validate validates the fields
  568. func (f *EditReleaseForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  569. ctx := context.GetContext(req)
  570. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  571. }
  572. // __ __.__ __ .__
  573. // / \ / \__| | _|__|
  574. // \ \/\/ / | |/ / |
  575. // \ /| | <| |
  576. // \__/\ / |__|__|_ \__|
  577. // \/ \/
  578. // NewWikiForm form for creating wiki
  579. type NewWikiForm struct {
  580. Title string `binding:"Required"`
  581. Content string `binding:"Required"`
  582. Message string
  583. }
  584. // Validate validates the fields
  585. // FIXME: use code generation to generate this method.
  586. func (f *NewWikiForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  587. ctx := context.GetContext(req)
  588. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  589. }
  590. // ___________ .___.__ __
  591. // \_ _____/ __| _/|__|/ |_
  592. // | __)_ / __ | | \ __\
  593. // | \/ /_/ | | || |
  594. // /_______ /\____ | |__||__|
  595. // \/ \/
  596. // EditRepoFileForm form for changing repository file
  597. type EditRepoFileForm struct {
  598. TreePath string `binding:"Required;MaxSize(500)"`
  599. Content string
  600. CommitSummary string `binding:"MaxSize(100)"`
  601. CommitMessage string
  602. CommitChoice string `binding:"Required;MaxSize(50)"`
  603. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  604. LastCommit string
  605. Signoff bool
  606. }
  607. // Validate validates the fields
  608. func (f *EditRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  609. ctx := context.GetContext(req)
  610. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  611. }
  612. // EditPreviewDiffForm form for changing preview diff
  613. type EditPreviewDiffForm struct {
  614. Content string
  615. }
  616. // Validate validates the fields
  617. func (f *EditPreviewDiffForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  618. ctx := context.GetContext(req)
  619. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  620. }
  621. // ____ ___ .__ .___
  622. // | | \______ | | _________ __| _/
  623. // | | /\____ \| | / _ \__ \ / __ |
  624. // | | / | |_> > |_( <_> ) __ \_/ /_/ |
  625. // |______/ | __/|____/\____(____ /\____ |
  626. // |__| \/ \/
  627. //
  628. // UploadRepoFileForm form for uploading repository file
  629. type UploadRepoFileForm struct {
  630. TreePath string `binding:"MaxSize(500)"`
  631. CommitSummary string `binding:"MaxSize(100)"`
  632. CommitMessage string
  633. CommitChoice string `binding:"Required;MaxSize(50)"`
  634. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  635. Files []string
  636. Signoff bool
  637. }
  638. // Validate validates the fields
  639. func (f *UploadRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  640. ctx := context.GetContext(req)
  641. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  642. }
  643. // RemoveUploadFileForm form for removing uploaded file
  644. type RemoveUploadFileForm struct {
  645. File string `binding:"Required;MaxSize(50)"`
  646. }
  647. // Validate validates the fields
  648. func (f *RemoveUploadFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  649. ctx := context.GetContext(req)
  650. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  651. }
  652. // ________ .__ __
  653. // \______ \ ____ | | _____/ |_ ____
  654. // | | \_/ __ \| | _/ __ \ __\/ __ \
  655. // | ` \ ___/| |_\ ___/| | \ ___/
  656. // /_______ /\___ >____/\___ >__| \___ >
  657. // \/ \/ \/ \/
  658. // DeleteRepoFileForm form for deleting repository file
  659. type DeleteRepoFileForm struct {
  660. CommitSummary string `binding:"MaxSize(100)"`
  661. CommitMessage string
  662. CommitChoice string `binding:"Required;MaxSize(50)"`
  663. NewBranchName string `binding:"GitRefName;MaxSize(100)"`
  664. LastCommit string
  665. Signoff bool
  666. }
  667. // Validate validates the fields
  668. func (f *DeleteRepoFileForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  669. ctx := context.GetContext(req)
  670. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  671. }
  672. // ___________.__ ___________ __
  673. // \__ ___/|__| _____ ____ \__ ___/___________ ____ | | __ ___________
  674. // | | | |/ \_/ __ \ | | \_ __ \__ \ _/ ___\| |/ // __ \_ __ \
  675. // | | | | Y Y \ ___/ | | | | \// __ \\ \___| <\ ___/| | \/
  676. // |____| |__|__|_| /\___ > |____| |__| (____ /\___ >__|_ \\___ >__|
  677. // \/ \/ \/ \/ \/ \/
  678. // AddTimeManuallyForm form that adds spent time manually.
  679. type AddTimeManuallyForm struct {
  680. Hours int `binding:"Range(0,1000)"`
  681. Minutes int `binding:"Range(0,1000)"`
  682. }
  683. // Validate validates the fields
  684. func (f *AddTimeManuallyForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  685. ctx := context.GetContext(req)
  686. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  687. }
  688. // SaveTopicForm form for save topics for repository
  689. type SaveTopicForm struct {
  690. Topics []string `binding:"topics;Required;"`
  691. }
  692. // DeadlineForm hold the validation rules for deadlines
  693. type DeadlineForm struct {
  694. DateString string `form:"date" binding:"Required;Size(10)"`
  695. }
  696. // Validate validates the fields
  697. func (f *DeadlineForm) Validate(req *http.Request, errs binding.Errors) binding.Errors {
  698. ctx := context.GetContext(req)
  699. return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
  700. }