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

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