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

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