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

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