And others

This commit is contained in:
Sandro Santilli 2016-11-07 17:53:22 +01:00
parent b3828e38a5
commit aadd7dcdc3
12 changed files with 34 additions and 34 deletions

View File

@ -213,7 +213,7 @@ func runServ(c *cli.Context) error {
keyID = key.ID keyID = key.ID
// Check deploy key or user key. // Check deploy key or user key.
if key.Type == models.KEY_TYPE_DEPLOY { if key.Type == models.KeyTypeDeploy {
if key.Mode < requestedMode { if key.Mode < requestedMode {
fail("Key permission denied", "Cannot push with deployment key: %d", key.ID) fail("Key permission denied", "Cannot push with deployment key: %d", key.ID)
} }

View File

@ -170,7 +170,7 @@ func GetOrgByName(name string) (*User, error) {
} }
u := &User{ u := &User{
LowerName: strings.ToLower(name), LowerName: strings.ToLower(name),
Type: USER_TYPE_ORGANIZATION, Type: UserTypeOrganization,
} }
has, err := x.Get(u) has, err := x.Get(u)
if err != nil { if err != nil {

View File

@ -29,7 +29,7 @@ import (
) )
const ( const (
_TPL_PUBLICK_KEY = `command="%s serv key-%d --config='%s'",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s` + "\n" tplPublicKey = `command="%s serv key-%d --config='%s'",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s` + "\n"
) )
var sshOpLocker sync.Mutex var sshOpLocker sync.Mutex
@ -37,8 +37,8 @@ var sshOpLocker sync.Mutex
type KeyType int type KeyType int
const ( const (
KEY_TYPE_USER = iota + 1 KeyTypeUser = iota + 1
KEY_TYPE_DEPLOY KeyTypeDeploy
) )
// PublicKey represents a user or deploy SSH public key. // PublicKey represents a user or deploy SSH public key.
@ -85,7 +85,7 @@ func (k *PublicKey) OmitEmail() string {
// AuthorizedString returns formatted public key string for authorized_keys file. // AuthorizedString returns formatted public key string for authorized_keys file.
func (key *PublicKey) AuthorizedString() string { func (key *PublicKey) AuthorizedString() string {
return fmt.Sprintf(_TPL_PUBLICK_KEY, setting.AppPath, key.ID, setting.CustomConf, key.Content) return fmt.Sprintf(tplPublicKey, setting.AppPath, key.ID, setting.CustomConf, key.Content)
} }
func extractTypeFromBase64Key(key string) (string, error) { func extractTypeFromBase64Key(key string) (string, error) {
@ -352,7 +352,7 @@ func appendAuthorizedKeysToFile(keys ...*PublicKey) error {
func checkKeyContent(content string) error { func checkKeyContent(content string) error {
has, err := x.Get(&PublicKey{ has, err := x.Get(&PublicKey{
Content: content, Content: content,
Type: KEY_TYPE_USER, Type: KeyTypeUser,
}) })
if err != nil { if err != nil {
return err return err
@ -416,7 +416,7 @@ func AddPublicKey(ownerID int64, name, content string) (*PublicKey, error) {
Name: name, Name: name,
Content: content, Content: content,
Mode: AccessModeWrite, Mode: AccessModeWrite,
Type: KEY_TYPE_USER, Type: KeyTypeUser,
} }
if err = addKey(sess, key); err != nil { if err = addKey(sess, key); err != nil {
return nil, fmt.Errorf("addKey: %v", err) return nil, fmt.Errorf("addKey: %v", err)
@ -643,7 +643,7 @@ func AddDeployKey(repoID int64, name, content string) (*DeployKey, error) {
pkey := &PublicKey{ pkey := &PublicKey{
Content: content, Content: content,
Mode: AccessModeRead, Mode: AccessModeRead,
Type: KEY_TYPE_DEPLOY, Type: KeyTypeDeploy,
} }
has, err := x.Get(pkey) has, err := x.Get(pkey)
if err != nil { if err != nil {

View File

@ -37,8 +37,8 @@ import (
type UserType int type UserType int
const ( const (
USER_TYPE_INDIVIDUAL UserType = iota // Historic reason to make it starts at 0. UserTypeIndividual UserType = iota // Historic reason to make it starts at 0.
USER_TYPE_ORGANIZATION UserTypeOrganization
) )
var ( var (
@ -393,7 +393,7 @@ func (u *User) IsWriterOfRepo(repo *Repository) bool {
// IsOrganization returns true if user is actually a organization. // IsOrganization returns true if user is actually a organization.
func (u *User) IsOrganization() bool { func (u *User) IsOrganization() bool {
return u.Type == USER_TYPE_ORGANIZATION return u.Type == UserTypeOrganization
} }
// IsUserOrgOwner returns true if user is in the owner team of given organization. // IsUserOrgOwner returns true if user is in the owner team of given organization.

View File

@ -28,13 +28,13 @@ var HookQueue = sync.NewUniqueQueue(setting.Webhook.QueueLength)
type HookContentType int type HookContentType int
const ( const (
JSON HookContentType = iota + 1 ContentTypeJson HookContentType = iota + 1
FORM ContentTypeForm
) )
var hookContentTypes = map[string]HookContentType{ var hookContentTypes = map[string]HookContentType{
"json": JSON, "json": ContentTypeJson,
"form": FORM, "form": ContentTypeForm,
} }
// ToHookContentType returns HookContentType by given name. // ToHookContentType returns HookContentType by given name.
@ -44,9 +44,9 @@ func ToHookContentType(name string) HookContentType {
func (t HookContentType) Name() string { func (t HookContentType) Name() string {
switch t { switch t {
case JSON: case ContentTypeJson:
return "json" return "json"
case FORM: case ContentTypeForm:
return "form" return "form"
} }
return "" return ""
@ -511,9 +511,9 @@ func (t *HookTask) deliver() {
SetTLSClientConfig(&tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify}) SetTLSClientConfig(&tls.Config{InsecureSkipVerify: setting.Webhook.SkipTLSVerify})
switch t.ContentType { switch t.ContentType {
case JSON: case ContentTypeJson:
req = req.Header("Content-Type", "application/json").Body(t.PayloadContent) req = req.Header("Content-Type", "application/json").Body(t.PayloadContent)
case FORM: case ContentTypeForm:
req.Param("payload", t.PayloadContent) req.Param("payload", t.PayloadContent)
} }

View File

@ -22,7 +22,7 @@ func Organizations(ctx *context.Context) {
ctx.Data["PageIsAdminOrganizations"] = true ctx.Data["PageIsAdminOrganizations"] = true
routers.RenderUserSearch(ctx, &routers.UserSearchOptions{ routers.RenderUserSearch(ctx, &routers.UserSearchOptions{
Type: models.USER_TYPE_ORGANIZATION, Type: models.UserTypeOrganization,
Counter: models.CountOrganizations, Counter: models.CountOrganizations,
Ranger: models.Organizations, Ranger: models.Organizations,
PageSize: setting.UI.Admin.OrgPagingNum, PageSize: setting.UI.Admin.OrgPagingNum,

View File

@ -30,7 +30,7 @@ func Users(ctx *context.Context) {
ctx.Data["PageIsAdminUsers"] = true ctx.Data["PageIsAdminUsers"] = true
routers.RenderUserSearch(ctx, &routers.UserSearchOptions{ routers.RenderUserSearch(ctx, &routers.UserSearchOptions{
Type: models.USER_TYPE_INDIVIDUAL, Type: models.UserTypeIndividual,
Counter: models.CountUsers, Counter: models.CountUsers,
Ranger: models.Users, Ranger: models.Users,
PageSize: setting.UI.Admin.UserPagingNum, PageSize: setting.UI.Admin.UserPagingNum,

View File

@ -27,7 +27,7 @@ func CreateOrg(ctx *context.APIContext, form api.CreateOrgOption) {
Website: form.Website, Website: form.Website,
Location: form.Location, Location: form.Location,
IsActive: true, IsActive: true,
Type: models.USER_TYPE_ORGANIZATION, Type: models.UserTypeOrganization,
} }
if err := models.CreateOrganization(org, u); err != nil { if err := models.CreateOrganization(org, u); err != nil {
if models.IsErrUserAlreadyExist(err) || if models.IsErrUserAlreadyExist(err) ||

View File

@ -16,7 +16,7 @@ import (
func Search(ctx *context.APIContext) { func Search(ctx *context.APIContext) {
opts := &models.SearchUserOptions{ opts := &models.SearchUserOptions{
Keyword: ctx.Query("q"), Keyword: ctx.Query("q"),
Type: models.USER_TYPE_INDIVIDUAL, Type: models.UserTypeIndividual,
PageSize: com.StrTo(ctx.Query("limit")).MustInt(), PageSize: com.StrTo(ctx.Query("limit")).MustInt(),
} }
if opts.PageSize == 0 { if opts.PageSize == 0 {

View File

@ -172,7 +172,7 @@ func ExploreUsers(ctx *context.Context) {
ctx.Data["PageIsExploreUsers"] = true ctx.Data["PageIsExploreUsers"] = true
RenderUserSearch(ctx, &UserSearchOptions{ RenderUserSearch(ctx, &UserSearchOptions{
Type: models.USER_TYPE_INDIVIDUAL, Type: models.UserTypeIndividual,
Counter: models.CountUsers, Counter: models.CountUsers,
Ranger: models.Users, Ranger: models.Users,
PageSize: setting.UI.ExplorePagingNum, PageSize: setting.UI.ExplorePagingNum,
@ -187,7 +187,7 @@ func ExploreOrganizations(ctx *context.Context) {
ctx.Data["PageIsExploreOrganizations"] = true ctx.Data["PageIsExploreOrganizations"] = true
RenderUserSearch(ctx, &UserSearchOptions{ RenderUserSearch(ctx, &UserSearchOptions{
Type: models.USER_TYPE_ORGANIZATION, Type: models.UserTypeOrganization,
Counter: models.CountOrganizations, Counter: models.CountOrganizations,
Ranger: models.Organizations, Ranger: models.Organizations,
PageSize: setting.UI.ExplorePagingNum, PageSize: setting.UI.ExplorePagingNum,

View File

@ -33,7 +33,7 @@ func CreatePost(ctx *context.Context, form auth.CreateOrgForm) {
org := &models.User{ org := &models.User{
Name: form.OrgName, Name: form.OrgName,
IsActive: true, IsActive: true,
Type: models.USER_TYPE_ORGANIZATION, Type: models.UserTypeOrganization,
} }
if err := models.CreateOrganization(org, ctx.User); err != nil { if err := models.CreateOrganization(org, ctx.User); err != nil {

View File

@ -134,9 +134,9 @@ func WebHooksNewPost(ctx *context.Context, form auth.NewWebhookForm) {
return return
} }
contentType := models.JSON contentType := models.ContentTypeJson
if models.HookContentType(form.ContentType) == models.FORM { if models.HookContentType(form.ContentType) == models.ContentTypeForm {
contentType = models.FORM contentType = models.ContentTypeForm
} }
w := &models.Webhook{ w := &models.Webhook{
@ -192,7 +192,7 @@ func SlackHooksNewPost(ctx *context.Context, form auth.NewSlackHookForm) {
w := &models.Webhook{ w := &models.Webhook{
RepoID: orCtx.RepoID, RepoID: orCtx.RepoID,
URL: form.PayloadURL, URL: form.PayloadURL,
ContentType: models.JSON, ContentType: models.ContentTypeJson,
HookEvent: ParseHookEvent(form.WebhookForm), HookEvent: ParseHookEvent(form.WebhookForm),
IsActive: form.Active, IsActive: form.Active,
HookTaskType: models.SLACK, HookTaskType: models.SLACK,
@ -281,9 +281,9 @@ func WebHooksEditPost(ctx *context.Context, form auth.NewWebhookForm) {
return return
} }
contentType := models.JSON contentType := models.ContentTypeJson
if models.HookContentType(form.ContentType) == models.FORM { if models.HookContentType(form.ContentType) == models.ContentTypeForm {
contentType = models.FORM contentType = models.ContentTypeForm
} }
w.URL = form.PayloadURL w.URL = form.PayloadURL