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.

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