gitea: code.gitea.io/gitea/modules/context Index | Files

package context

import "code.gitea.io/gitea/modules/context"

Index

Package Files

api.go api_org.go auth.go context.go org.go pagination.go panic.go permission.go repo.go

func APIContexter Uses

func APIContexter() macaron.Handler

APIContexter returns apicontext as macaron middleware

func ComposeGoGetImport Uses

func ComposeGoGetImport(owner, repo string) string

ComposeGoGetImport returns go-get-import meta content.

func Contexter Uses

func Contexter() macaron.Handler

Contexter initializes a classic context for a request.

func EarlyResponseForGoGetMeta Uses

func EarlyResponseForGoGetMeta(ctx *Context)

EarlyResponseForGoGetMeta responses appropriate go-get meta with status 200 if user does not have actual access to the requested repository, or the owner or repository does not exist at all. This is particular a workaround for "go get" command which does not respect .netrc file.

func GitHookService Uses

func GitHookService() macaron.Handler

GitHookService checks if repository Git hooks service has been enabled.

func HandleOrgAssignment Uses

func HandleOrgAssignment(ctx *Context, args ...bool)

HandleOrgAssignment handles organization assignment

func OrgAssignment Uses

func OrgAssignment(args ...bool) macaron.Handler

OrgAssignment returns a macaron middleware to handle organization assignment

func Recovery Uses

func Recovery() macaron.Handler

Recovery returns a middleware that recovers from any panics and writes a 500 and a log if so. Although similar to macaron.Recovery() the main difference is that this error will be created with the gitea 500 page.

func RedirectToRepo Uses

func RedirectToRepo(ctx *Context, redirectRepoID int64)

RedirectToRepo redirect to a differently-named repository

func ReferencesGitRepo Uses

func ReferencesGitRepo(allowEmpty bool) macaron.Handler

ReferencesGitRepo injects the GitRepo into the Context

func RepoAssignment Uses

func RepoAssignment() macaron.Handler

RepoAssignment returns a macaron to handle repository assignment

func RepoIDAssignment Uses

func RepoIDAssignment() macaron.Handler

RepoIDAssignment returns a macaron handler which assigns the repo to the context.

func RepoMustNotBeArchived Uses

func RepoMustNotBeArchived() macaron.Handler

RepoMustNotBeArchived checks if a repo is archived

func RepoRef Uses

func RepoRef() macaron.Handler

RepoRef handles repository reference names when the ref name is not explicitly given

func RepoRefByType Uses

func RepoRefByType(refType RepoRefType) macaron.Handler

RepoRefByType handles repository reference name for a specific type of repository reference

func RequireRepoAdmin Uses

func RequireRepoAdmin() macaron.Handler

RequireRepoAdmin returns a macaron middleware for requiring repository admin permission

func RequireRepoReader Uses

func RequireRepoReader(unitType models.UnitType) macaron.Handler

RequireRepoReader returns a macaron middleware for requiring repository read to the specify unitType

func RequireRepoReaderOr Uses

func RequireRepoReaderOr(unitTypes ...models.UnitType) macaron.Handler

RequireRepoReaderOr returns a macaron middleware for requiring repository write to one of the unit permission

func RequireRepoWriter Uses

func RequireRepoWriter(unitType models.UnitType) macaron.Handler

RequireRepoWriter returns a macaron middleware for requiring repository write to the specify unitType

func RequireRepoWriterOr Uses

func RequireRepoWriterOr(unitTypes ...models.UnitType) macaron.Handler

RequireRepoWriterOr returns a macaron middleware for requiring repository write to one of the unit permission

func RetrieveBaseRepo Uses

func RetrieveBaseRepo(ctx *Context, repo *models.Repository)

RetrieveBaseRepo retrieves base repository

func RetrieveTemplateRepo Uses

func RetrieveTemplateRepo(ctx *Context, repo *models.Repository)

RetrieveTemplateRepo retrieves template repository used to generate this repository

func Toggle Uses

func Toggle(options *ToggleOptions) macaron.Handler

Toggle returns toggle options as middleware

func UnitTypes Uses

func UnitTypes() macaron.Handler

UnitTypes returns a macaron middleware to set unit types to context variables.

type APIContext Uses

type APIContext struct {
    *Context
    Org *APIOrganization
}

APIContext is a specific macaron context for API service

func (*APIContext) CheckForOTP Uses

func (ctx *APIContext) CheckForOTP()

CheckForOTP validateds OTP

func (*APIContext) Error Uses

func (ctx *APIContext) Error(status int, title string, obj interface{})

Error responses error message to client with given message. If status is 500, also it prints error to log.

func (*APIContext) NotFound Uses

func (ctx *APIContext) NotFound(objs ...interface{})

NotFound handles 404s for APIContext String will replace message, errors will be added to a slice

func (*APIContext) RequireCSRF Uses

func (ctx *APIContext) RequireCSRF()

RequireCSRF requires a validated a CSRF token

func (*APIContext) SetLinkHeader Uses

func (ctx *APIContext) SetLinkHeader(total, pageSize int)

SetLinkHeader sets pagination link header by given total number and page size.

type APIEmpty Uses

type APIEmpty struct{}

APIEmpty is an empty response swagger:response empty

type APIError Uses

type APIError struct {
    Message string `json:"message"`
    URL     string `json:"url"`
}

APIError is error format response swagger:response error

type APIForbiddenError Uses

type APIForbiddenError struct {
    APIError
}

APIForbiddenError is a forbidden error response swagger:response forbidden

type APINotFound Uses

type APINotFound struct{}

APINotFound is a not found empty response swagger:response notFound

type APIOrganization Uses

type APIOrganization struct {
    Organization *models.User
    Team         *models.Team
}

APIOrganization contains organization and team

type APIRedirect Uses

type APIRedirect struct{}

APIRedirect is a redirect response swagger:response redirect

type APIValidationError Uses

type APIValidationError struct {
    Message string `json:"message"`
    URL     string `json:"url"`
}

APIValidationError is error format response related to input validation swagger:response validationError

type Context Uses

type Context struct {
    *macaron.Context
    Cache cache.Cache

    Flash   *session.Flash
    Session session.Store

    Link        string // current request URL
    EscapedLink string
    User        *models.User
    IsSigned    bool
    IsBasicAuth bool

    Repo *Repository
    Org  *Organization
    // contains filtered or unexported fields
}

Context represents context of a request.

func (*Context) GetErrMsg Uses

func (ctx *Context) GetErrMsg() string

GetErrMsg returns error message

func (*Context) HTML Uses

func (ctx *Context) HTML(status int, name base.TplName)

HTML calls Context.HTML and converts template name to string.

func (*Context) HandleText Uses

func (ctx *Context) HandleText(status int, title string)

HandleText handles HTTP status code

func (*Context) HasAPIError Uses

func (ctx *Context) HasAPIError() bool

HasAPIError returns true if error occurs in form validation.

func (*Context) HasError Uses

func (ctx *Context) HasError() bool

HasError returns true if error occurs in form validation.

func (*Context) HasValue Uses

func (ctx *Context) HasValue(name string) bool

HasValue returns true if value of given name exists.

func (*Context) IsUserRepoAdmin Uses

func (ctx *Context) IsUserRepoAdmin() bool

IsUserRepoAdmin returns true if current user is admin in current repo

func (*Context) IsUserRepoOwner Uses

func (ctx *Context) IsUserRepoOwner() bool

IsUserRepoOwner returns true if current user owns current repo

func (*Context) IsUserRepoReaderAny Uses

func (ctx *Context) IsUserRepoReaderAny() bool

IsUserRepoReaderAny returns true if current user can read any part of current repo

func (*Context) IsUserRepoReaderSpecific Uses

func (ctx *Context) IsUserRepoReaderSpecific(unitType models.UnitType) bool

IsUserRepoReaderSpecific returns true if current user can read current repo's specific part

func (*Context) IsUserRepoWriter Uses

func (ctx *Context) IsUserRepoWriter(unitTypes []models.UnitType) bool

IsUserRepoWriter returns true if current user has write privilege in current repo

func (*Context) IsUserSiteAdmin Uses

func (ctx *Context) IsUserSiteAdmin() bool

IsUserSiteAdmin returns true if current user is a site admin

func (*Context) NotFound Uses

func (ctx *Context) NotFound(title string, err error)

NotFound displays a 404 (Not Found) page and prints the given error, if any.

func (*Context) NotFoundOrServerError Uses

func (ctx *Context) NotFoundOrServerError(title string, errck func(error) bool, err error)

NotFoundOrServerError use error check function to determine if the error is about not found. It responses with 404 status code for not found error, or error context description for logging purpose of 500 server error.

func (*Context) RedirectToFirst Uses

func (ctx *Context) RedirectToFirst(location ...string)

RedirectToFirst redirects to first not empty URL

func (*Context) RenderWithErr Uses

func (ctx *Context) RenderWithErr(msg string, tpl base.TplName, form interface{})

RenderWithErr used for page has form validation but need to prompt error to users.

func (*Context) ServeContent Uses

func (ctx *Context) ServeContent(name string, r io.ReadSeeker, params ...interface{})

ServeContent serves content to http request

func (*Context) ServerError Uses

func (ctx *Context) ServerError(title string, err error)

ServerError displays a 500 (Internal Server Error) page and prints the given error, if any.

type Organization Uses

type Organization struct {
    IsOwner      bool
    IsMember     bool
    IsTeamMember bool // Is member of team.
    IsTeamAdmin  bool // In owner team or team that has admin permission level.
    Organization *models.User
    OrgLink      string

    Team *models.Team
}

Organization contains organization context

type Pagination Uses

type Pagination struct {
    Paginater *paginater.Paginater
    // contains filtered or unexported fields
}

Pagination provides a pagination via Paginater and additional configurations for the link params used in rendering

func NewPagination Uses

func NewPagination(total int, page int, issueNum int, numPages int) *Pagination

NewPagination creates a new instance of the Pagination struct

func (*Pagination) AddParam Uses

func (p *Pagination) AddParam(ctx *Context, paramKey string, ctxKey string)

AddParam adds a value from context identified by ctxKey as link param under a given paramKey

func (*Pagination) GetParams Uses

func (p *Pagination) GetParams() template.URL

GetParams returns the configured URL params

func (*Pagination) SetDefaultParams Uses

func (p *Pagination) SetDefaultParams(ctx *Context)

SetDefaultParams sets common pagination params that are often used

type PullRequest Uses

type PullRequest struct {
    BaseRepo *models.Repository
    Allowed  bool
    SameRepo bool
    HeadInfo string // [<user>:]<branch>
}

PullRequest contains informations to make a pull request

type RepoRefType Uses

type RepoRefType int

RepoRefType type of repo reference

const (
    // RepoRefLegacy unknown type, make educated guess and redirect.
    // for backward compatibility with previous URL scheme
    RepoRefLegacy RepoRefType = iota
    // RepoRefAny is for usage where educated guess is needed
    // but redirect can not be made
    RepoRefAny
    // RepoRefBranch branch
    RepoRefBranch
    // RepoRefTag tag
    RepoRefTag
    // RepoRefCommit commit
    RepoRefCommit
    // RepoRefBlob blob
    RepoRefBlob
)

func (RepoRefType) RefTypeIncludesBranches Uses

func (rt RepoRefType) RefTypeIncludesBranches() bool

RefTypeIncludesBranches returns true if ref type can be a branch

func (RepoRefType) RefTypeIncludesTags Uses

func (rt RepoRefType) RefTypeIncludesTags() bool

RefTypeIncludesTags returns true if ref type can be a tag

type Repository Uses

type Repository struct {
    models.Permission
    IsWatching   bool
    IsViewBranch bool
    IsViewTag    bool
    IsViewCommit bool
    Repository   *models.Repository
    Owner        *models.User
    Commit       *git.Commit
    Tag          *git.Tag
    GitRepo      *git.Repository
    BranchName   string
    TagName      string
    TreePath     string
    CommitID     string
    RepoLink     string
    CloneLink    models.CloneLink
    CommitsCount int64
    Mirror       *models.Mirror

    PullRequest *PullRequest
}

Repository contains information to operate a repository

func (*Repository) BranchNameSubURL Uses

func (r *Repository) BranchNameSubURL() string

BranchNameSubURL sub-URL for the BranchName field

func (*Repository) CanCommitToBranch Uses

func (r *Repository) CanCommitToBranch(doer *models.User) (bool, error)

CanCommitToBranch returns true if repository is editable and user has proper access level

and branch is not protected for push

func (*Repository) CanCreateBranch Uses

func (r *Repository) CanCreateBranch() bool

CanCreateBranch returns true if repository is editable and user has proper access level.

func (*Repository) CanCreateIssueDependencies Uses

func (r *Repository) CanCreateIssueDependencies(user *models.User) bool

CanCreateIssueDependencies returns whether or not a user can create dependencies.

func (*Repository) CanEnableEditor Uses

func (r *Repository) CanEnableEditor() bool

CanEnableEditor returns true if repository is editable and user has proper access level.

func (*Repository) CanUseTimetracker Uses

func (r *Repository) CanUseTimetracker(issue *models.Issue, user *models.User) bool

CanUseTimetracker returns whether or not a user can use the timetracker.

func (*Repository) FileExists Uses

func (r *Repository) FileExists(path string, branch string) (bool, error)

FileExists returns true if a file exists in the given repo branch

func (*Repository) GetCommitsCount Uses

func (r *Repository) GetCommitsCount() (int64, error)

GetCommitsCount returns cached commit count for current view

func (*Repository) GetEditorconfig Uses

func (r *Repository) GetEditorconfig() (*editorconfig.Editorconfig, error)

GetEditorconfig returns the .editorconfig definition if found in the HEAD of the default repo branch.

type ToggleOptions Uses

type ToggleOptions struct {
    SignInRequired  bool
    SignOutRequired bool
    AdminRequired   bool
    DisableCSRF     bool
}

ToggleOptions contains required or check options

Package context imports 26 packages (graph) and is imported by 69 packages. Updated 2019-11-13. Refresh now. Tools for package owners.