context

package
v1.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2018 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIContexter

func APIContexter() macaron.Handler

APIContexter returns apicontext as macaron middleware

func CheckAnyUnit added in v1.2.1

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

CheckAnyUnit will check whether any of the unit types are enabled

func CheckUnit added in v1.2.0

func CheckUnit(unitType models.UnitType) macaron.Handler

CheckUnit will check whether unit type is enabled

func ComposeGoGetImport added in v1.2.0

func ComposeGoGetImport(owner, repo string) string

ComposeGoGetImport returns go-get-import meta content.

func Contexter

func Contexter() macaron.Handler

Contexter initializes a classic context for a request.

func EarlyResponseForGoGetMeta added in v1.2.0

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

func GitHookService() macaron.Handler

GitHookService checks if repository Git hooks service has been enabled.

func HandleOrgAssignment

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

HandleOrgAssignment handles organization assignment

func LoadRepoUnits added in v1.2.0

func LoadRepoUnits() macaron.Handler

LoadRepoUnits loads repsitory's units, it should be called after repository and user loaded

func OrgAssignment

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

OrgAssignment returns a macaron middleware to handle organization assignment

func RedirectToRepo added in v1.1.0

func RedirectToRepo(ctx *Context, redirectRepoID int64)

RedirectToRepo redirect to a differently-named repository

func ReferencesGitRepo added in v1.0.0

func ReferencesGitRepo() macaron.Handler

ReferencesGitRepo injects the GitRepo into the Context

func RepoAssignment

func RepoAssignment() macaron.Handler

RepoAssignment returns a macaron to handle repository assignment

func RepoIDAssignment added in v1.2.0

func RepoIDAssignment() macaron.Handler

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

func RepoRef

func RepoRef() macaron.Handler

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

func RepoRefByType added in v1.3.0

func RepoRefByType(refType RepoRefType) macaron.Handler

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

func RequireRepoAdmin

func RequireRepoAdmin() macaron.Handler

RequireRepoAdmin returns a macaron middleware for requiring repository admin permission

func RequireRepoWriter

func RequireRepoWriter() macaron.Handler

RequireRepoWriter returns a macaron middleware for requiring repository write permission

func RetrieveBaseRepo

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

RetrieveBaseRepo retrieves base repository

func Toggle

func Toggle(options *ToggleOptions) macaron.Handler

Toggle returns toggle options as middleware

func UnitTypes added in v1.1.0

func UnitTypes() macaron.Handler

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

Types

type APIContext

type APIContext struct {
	*Context
	Org *APIOrganization
}

APIContext is a specific macaron context for API service

func (*APIContext) Error

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) SetLinkHeader

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

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

type APIEmpty added in v1.2.0

type APIEmpty struct{}

APIEmpty is an empty response swagger:response empty

type APIError added in v1.2.0

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

APIError is error format response swagger:response error

type APIForbiddenError added in v1.2.0

type APIForbiddenError struct {
	APIError
}

APIForbiddenError is a forbidden error response swagger:response forbidden

type APINotFound added in v1.2.0

type APINotFound struct{}

APINotFound is a not found empty response swagger:response notFound

type APIOrganization

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

APIOrganization contains organization and team

type APIRedirect added in v1.2.0

type APIRedirect struct{}

APIRedirect is a redirect response swagger:response redirect

type APIValidationError added in v1.2.0

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

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

func (ctx *Context) GetErrMsg() string

GetErrMsg returns error message

func (*Context) HTML

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

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

func (*Context) HandleText

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

HandleText handles HTTP status code

func (*Context) HasAPIError added in v1.0.0

func (ctx *Context) HasAPIError() bool

HasAPIError returns true if error occurs in form validation.

func (*Context) HasError

func (ctx *Context) HasError() bool

HasError returns true if error occurs in form validation.

func (*Context) HasValue

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

HasValue returns true if value of given name exists.

func (*Context) NotFound added in v1.4.0

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

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 added in v1.4.0

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

RedirectToFirst redirects to first not empty URL

func (*Context) RenderWithErr

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

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

ServeContent serves content to http request

func (*Context) ServerError added in v1.4.0

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

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 PullRequest

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

PullRequest contains informations to make a pull request

type RepoRefType added in v1.3.0

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
)

type Repository

type Repository struct {
	AccessMode   models.AccessMode
	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 added in v1.3.0

func (r *Repository) BranchNameSubURL() string

BranchNameSubURL sub-URL for the BranchName field

func (*Repository) CanCommitToBranch added in v1.2.0

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 added in v1.3.0

func (r *Repository) CanCreateBranch() bool

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

func (*Repository) CanEnableEditor

func (r *Repository) CanEnableEditor() bool

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

func (*Repository) CanUseTimetracker added in v1.3.0

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

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

func (*Repository) GetCommitsCount added in v1.3.0

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

GetCommitsCount returns cached commit count for current view

func (*Repository) GetEditorconfig

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

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

func (*Repository) HasAccess

func (r *Repository) HasAccess() bool

HasAccess returns true if the current user has at least read access for this repository

func (*Repository) IsAdmin

func (r *Repository) IsAdmin() bool

IsAdmin returns true if current user has admin or higher access of repository.

func (*Repository) IsOwner

func (r *Repository) IsOwner() bool

IsOwner returns true if current user is the owner of repository.

func (*Repository) IsWriter

func (r *Repository) IsWriter() bool

IsWriter returns true if current user has write or higher access of repository.

type ToggleOptions

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

ToggleOptions contains required or check options

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL