本站源代码
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

673 rindas
22KB

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