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

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