|
-
-
-
-
-
- package auth
-
- import (
- "net/url"
- "strings"
-
- "code.gitea.io/gitea/models"
- "code.gitea.io/gitea/modules/setting"
- "code.gitea.io/gitea/routers/utils"
-
- "gitea.com/macaron/binding"
- "gitea.com/macaron/macaron"
- "github.com/unknwon/com"
- )
-
-
-
-
-
-
-
-
-
- type CreateRepoForm struct {
- UID int64 `binding:"Required"`
- RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
- Private bool
- Description string `binding:"MaxSize(255)"`
- AutoInit bool
- Gitignores string
- IssueLabels string
- License string
- Readme string
- }
-
-
- func (f *CreateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type MigrateRepoForm struct {
-
- CloneAddr string `json:"clone_addr" binding:"Required"`
- AuthUsername string `json:"auth_username"`
- AuthPassword string `json:"auth_password"`
-
- UID int64 `json:"uid" binding:"Required"`
-
- RepoName string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
- Mirror bool `json:"mirror"`
- Private bool `json:"private"`
- Description string `json:"description" binding:"MaxSize(255)"`
- Wiki bool `json:"wiki"`
- Milestones bool `json:"milestones"`
- Labels bool `json:"labels"`
- Issues bool `json:"issues"`
- PullRequests bool `json:"pull_requests"`
- Releases bool `json:"releases"`
- }
-
-
- func (f *MigrateRepoForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
-
-
-
- func (f MigrateRepoForm) ParseRemoteAddr(user *models.User) (string, error) {
- remoteAddr := strings.TrimSpace(f.CloneAddr)
-
-
- if strings.HasPrefix(remoteAddr, "http://") ||
- strings.HasPrefix(remoteAddr, "https://") ||
- strings.HasPrefix(remoteAddr, "git://") {
- u, err := url.Parse(remoteAddr)
- if err != nil {
- return "", models.ErrInvalidCloneAddr{IsURLError: true}
- }
- if len(f.AuthUsername)+len(f.AuthPassword) > 0 {
- u.User = url.UserPassword(f.AuthUsername, f.AuthPassword)
- }
- remoteAddr = u.String()
- } else if !user.CanImportLocal() {
- return "", models.ErrInvalidCloneAddr{IsPermissionDenied: true}
- } else if !com.IsDir(remoteAddr) {
- return "", models.ErrInvalidCloneAddr{IsInvalidPath: true}
- }
-
- return remoteAddr, nil
- }
-
-
- type RepoSettingForm struct {
- RepoName string `binding:"Required;AlphaDashDot;MaxSize(100)"`
- Description string `binding:"MaxSize(255)"`
- Website string `binding:"ValidUrl;MaxSize(255)"`
- Percent int64
- Point int64
- FundingToCollaboration int64
- Interval string
- MirrorAddress string
- MirrorUsername string
- MirrorPassword string
- Private bool
- EnablePrune bool
-
-
- EnableWiki bool
- EnableExternalWiki bool
- ExternalWikiURL string
- EnableIssues bool
- EnableExternalTracker bool
- ExternalTrackerURL string
- TrackerURLFormat string
- TrackerIssueStyle string
- EnablePulls bool
- PullsIgnoreWhitespace bool
- PullsAllowMerge bool
- PullsAllowRebase bool
- PullsAllowRebaseMerge bool
- PullsAllowSquash bool
- EnableTimetracker bool
- AllowOnlyContributorsToTrackTime bool
- EnableIssueDependencies bool
- IsArchived bool
-
-
- EnableHealthCheck bool
- EnableCloseIssuesViaCommitInAnyBranch bool
- }
-
-
- func (f *RepoSettingForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
-
-
-
-
-
-
-
- type ProtectBranchForm struct {
- Protected bool
- EnableWhitelist bool
- WhitelistUsers string
- WhitelistTeams string
- WhitelistDeployKeys bool
- EnableMergeWhitelist bool
- MergeWhitelistUsers string
- MergeWhitelistTeams string
- EnableStatusCheck bool `xorm:"NOT NULL DEFAULT false"`
- StatusCheckContexts []string
- RequiredApprovals int64
- ApprovalsWhitelistUsers string
- ApprovalsWhitelistTeams string
- }
-
-
- func (f *ProtectBranchForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
-
-
-
-
-
-
-
- type WebhookForm struct {
- Events string
- Create bool
- Delete bool
- Fork bool
- Issues bool
- IssueComment bool
- Release bool
- Push bool
- PullRequest bool
- Repository bool
- Active bool
- BranchFilter string `binding:"GlobPattern"`
- }
-
-
- func (f WebhookForm) PushOnly() bool {
- return f.Events == "push_only"
- }
-
-
- func (f WebhookForm) SendEverything() bool {
- return f.Events == "send_everything"
- }
-
-
- func (f WebhookForm) ChooseEvents() bool {
- return f.Events == "choose_events"
- }
-
-
- type NewWebhookForm struct {
- PayloadURL string `binding:"Required;ValidUrl"`
- HTTPMethod string `binding:"Required;In(POST,GET)"`
- ContentType int `binding:"Required"`
- Secret string
- WebhookForm
- }
-
-
- func (f *NewWebhookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type NewGogshookForm struct {
- PayloadURL string `binding:"Required;ValidUrl"`
- ContentType int `binding:"Required"`
- Secret string
- WebhookForm
- }
-
-
- func (f *NewGogshookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type NewSlackHookForm struct {
- PayloadURL string `binding:"Required;ValidUrl"`
- Channel string `binding:"Required"`
- Username string
- IconURL string
- Color string
- WebhookForm
- }
-
-
- func (f *NewSlackHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- func (f NewSlackHookForm) HasInvalidChannel() bool {
- return !utils.IsValidSlackChannel(f.Channel)
- }
-
-
- type NewDiscordHookForm struct {
- PayloadURL string `binding:"Required;ValidUrl"`
- Username string
- IconURL string
- WebhookForm
- }
-
-
- func (f *NewDiscordHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type NewDingtalkHookForm struct {
- PayloadURL string `binding:"Required;ValidUrl"`
- WebhookForm
- }
-
-
- func (f *NewDingtalkHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type NewTelegramHookForm struct {
- BotToken string `binding:"Required"`
- ChatID string `binding:"Required"`
- WebhookForm
- }
-
-
- func (f *NewTelegramHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type NewMSTeamsHookForm struct {
- PayloadURL string `binding:"Required;ValidUrl"`
- WebhookForm
- }
-
-
- func (f *NewMSTeamsHookForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
-
-
-
-
-
-
-
- type CreateIssueForm struct {
- Title string `binding:"Required;MaxSize(255)"`
- LabelIDs string `form:"label_ids"`
- AssigneeIDs string `form:"assignee_ids"`
- Ref string `form:"ref"`
- MilestoneID int64
- AssigneeID int64
- Content string
- Files []string
- }
-
-
- func (f *CreateIssueForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type CreateCommentForm struct {
- Content string
- Status string `binding:"OmitEmpty;In(reopen,close)"`
- Files []string
- }
-
-
- func (f *CreateCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type ReactionForm struct {
- Content string `binding:"Required;In(+1,-1,laugh,confused,heart,hooray)"`
- }
-
-
- func (f *ReactionForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type IssueLockForm struct {
- Reason string `binding:"Required"`
- }
-
-
- func (i *IssueLockForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, i, ctx.Locale)
- }
-
-
-
- func (i IssueLockForm) HasValidReason() bool {
- if strings.TrimSpace(i.Reason) == "" {
- return true
- }
-
- for _, v := range setting.Repository.Issue.LockReasons {
- if v == i.Reason {
- return true
- }
- }
-
- return false
- }
-
-
-
-
-
-
-
-
-
- type CreateMilestoneForm struct {
- Title string `binding:"Required;MaxSize(50)"`
- Content string
- Deadline string
- }
-
-
- func (f *CreateMilestoneForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
-
-
-
-
-
-
-
- type CreateLabelForm struct {
- ID int64
- Title string `binding:"Required;MaxSize(50)" locale:"repo.issues.label_title"`
- Description string `binding:"MaxSize(200)" locale:"repo.issues.label_description"`
- Color string `binding:"Required;Size(7)" locale:"repo.issues.label_color"`
- }
-
-
- func (f *CreateLabelForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type InitializeLabelsForm struct {
- TemplateName string `binding:"Required"`
- }
-
-
- func (f *InitializeLabelsForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
-
-
-
-
-
-
-
-
- type MergePullRequestForm struct {
-
-
- Do string `binding:"Required;In(merge,rebase,rebase-merge,squash)"`
- MergeTitleField string
- MergeMessageField string
- }
-
-
- func (f *MergePullRequestForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type CodeCommentForm struct {
- Content string `binding:"Required"`
- Side string `binding:"Required;In(previous,proposed)"`
- Line int64
- TreePath string `form:"path" binding:"Required"`
- IsReview bool `form:"is_review"`
- Reply int64 `form:"reply"`
- }
-
-
- func (f *CodeCommentForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type SubmitReviewForm struct {
- Content string
- Type string `binding:"Required;In(approve,comment,reject)"`
- }
-
-
- func (f *SubmitReviewForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- func (f SubmitReviewForm) ReviewType() models.ReviewType {
- switch f.Type {
- case "approve":
- return models.ReviewTypeApprove
- case "comment":
- return models.ReviewTypeComment
- case "reject":
- return models.ReviewTypeReject
- default:
- return models.ReviewTypeUnknown
- }
- }
-
-
- func (f SubmitReviewForm) HasEmptyContent() bool {
- reviewType := f.ReviewType()
-
- return (reviewType == models.ReviewTypeComment || reviewType == models.ReviewTypeReject) &&
- len(strings.TrimSpace(f.Content)) == 0
- }
-
-
-
-
-
-
-
-
-
- type NewReleaseForm struct {
- TagName string `binding:"Required;GitRefName"`
- Target string `form:"tag_target" binding:"Required"`
- Title string `binding:"Required"`
- Content string
- Draft string
- Prerelease bool
- Files []string
- }
-
-
- func (f *NewReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type EditReleaseForm struct {
- Title string `form:"title" binding:"Required"`
- Content string `form:"content"`
- Draft string `form:"draft"`
- Prerelease bool `form:"prerelease"`
- Files []string
- }
-
-
- func (f *EditReleaseForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
-
-
-
-
-
-
-
- type NewWikiForm struct {
- Title string `binding:"Required"`
- Content string `binding:"Required"`
- Message string
- }
-
-
-
- func (f *NewWikiForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
-
-
-
-
-
-
-
- type EditRepoFileForm struct {
- TreePath string `binding:"Required;MaxSize(500)"`
- Content string
- CommitSummary string `binding:"MaxSize(100)"`
- CommitMessage string
- CommitChoice string `binding:"Required;MaxSize(50)"`
- NewBranchName string `binding:"GitRefName;MaxSize(100)"`
- LastCommit string
- }
-
-
- func (f *EditRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type EditPreviewDiffForm struct {
- Content string
- }
-
-
- func (f *EditPreviewDiffForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
-
-
-
-
-
-
-
-
- type UploadRepoFileForm struct {
- TreePath string `binding:"MaxSize(500)"`
- CommitSummary string `binding:"MaxSize(100)"`
- CommitMessage string
- CommitChoice string `binding:"Required;MaxSize(50)"`
- NewBranchName string `binding:"GitRefName;MaxSize(100)"`
- Files []string
- }
-
-
- func (f *UploadRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type RemoveUploadFileForm struct {
- File string `binding:"Required;MaxSize(50)"`
- }
-
-
- func (f *RemoveUploadFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
-
-
-
-
-
-
-
- type DeleteRepoFileForm struct {
- CommitSummary string `binding:"MaxSize(100)"`
- CommitMessage string
- CommitChoice string `binding:"Required;MaxSize(50)"`
- NewBranchName string `binding:"GitRefName;MaxSize(100)"`
- LastCommit string
- }
-
-
- func (f *DeleteRepoFileForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
-
-
-
-
-
-
-
- type AddTimeManuallyForm struct {
- Hours int `binding:"Range(0,1000)"`
- Minutes int `binding:"Range(0,1000)"`
- }
-
-
- func (f *AddTimeManuallyForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
-
-
- type SaveTopicForm struct {
- Topics []string `binding:"topics;Required;"`
- }
-
-
- type DeadlineForm struct {
- DateString string `form:"date" binding:"Required;Size(10)"`
- }
-
-
- func (f *DeadlineForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
- return validate(errs, ctx.Data, f, ctx.Locale)
- }
|