models: mirror fix on #964
This commit is contained in:
parent
8d17ff8ce7
commit
d446be9f5f
11
cmd/serve.go
11
cmd/serve.go
|
@ -22,7 +22,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
ACCESS_DENIED_MESSAGE = "Repository does not exist or you do not have access"
|
_ACCESS_DENIED_MESSAGE = "Repository does not exist or you do not have access"
|
||||||
)
|
)
|
||||||
|
|
||||||
var CmdServ = cli.Command{
|
var CmdServ = cli.Command{
|
||||||
|
@ -55,7 +55,6 @@ func setup(logPath string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseCmd(cmd string) (string, string) {
|
func parseCmd(cmd string) (string, string) {
|
||||||
|
|
||||||
ss := strings.SplitN(cmd, " ", 2)
|
ss := strings.SplitN(cmd, " ", 2)
|
||||||
if len(ss) != 2 {
|
if len(ss) != 2 {
|
||||||
return "", ""
|
return "", ""
|
||||||
|
@ -66,8 +65,10 @@ func parseCmd(cmd string) (string, string) {
|
||||||
var (
|
var (
|
||||||
COMMANDS = map[string]models.AccessMode{
|
COMMANDS = map[string]models.AccessMode{
|
||||||
"git-upload-pack": models.ACCESS_MODE_READ,
|
"git-upload-pack": models.ACCESS_MODE_READ,
|
||||||
|
"git upload-pack": models.ACCESS_MODE_READ,
|
||||||
"git-upload-archive": models.ACCESS_MODE_READ,
|
"git-upload-archive": models.ACCESS_MODE_READ,
|
||||||
"git-receive-pack": models.ACCESS_MODE_WRITE,
|
"git-receive-pack": models.ACCESS_MODE_WRITE,
|
||||||
|
"git receive-pack": models.ACCESS_MODE_WRITE,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -133,7 +134,7 @@ func runServ(c *cli.Context) {
|
||||||
if user.Id == repoUser.Id || repoUser.IsOwnedBy(user.Id) {
|
if user.Id == repoUser.Id || repoUser.IsOwnedBy(user.Id) {
|
||||||
fail("Repository does not exist", "Repository does not exist: %s/%s", repoUser.Name, repoName)
|
fail("Repository does not exist", "Repository does not exist: %s/%s", repoUser.Name, repoName)
|
||||||
} else {
|
} else {
|
||||||
fail(ACCESS_DENIED_MESSAGE, "Repository does not exist: %s/%s", repoUser.Name, repoName)
|
fail(_ACCESS_DENIED_MESSAGE, "Repository does not exist: %s/%s", repoUser.Name, repoName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fail("Internal error", "Fail to get repository: %v", err)
|
fail("Internal error", "Fail to get repository: %v", err)
|
||||||
|
@ -146,9 +147,9 @@ func runServ(c *cli.Context) {
|
||||||
|
|
||||||
mode, err := models.AccessLevel(user, repo)
|
mode, err := models.AccessLevel(user, repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fail("Internal error", "HasAccess fail: %v", err)
|
fail("Internal error", "Fail to check access: %v", err)
|
||||||
} else if mode < requestedMode {
|
} else if mode < requestedMode {
|
||||||
clientMessage := ACCESS_DENIED_MESSAGE
|
clientMessage := _ACCESS_DENIED_MESSAGE
|
||||||
if mode >= models.ACCESS_MODE_READ {
|
if mode >= models.ACCESS_MODE_READ {
|
||||||
clientMessage = "You do not have sufficient authorization for this action"
|
clientMessage = "You do not have sufficient authorization for this action"
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,7 +149,7 @@ repo_name_been_taken = Repository name has been already taken.
|
||||||
org_name_been_taken = Organization name has been already taken.
|
org_name_been_taken = Organization name has been already taken.
|
||||||
team_name_been_taken = Team name has been already taken.
|
team_name_been_taken = Team name has been already taken.
|
||||||
email_been_used = E-mail address has been already used.
|
email_been_used = E-mail address has been already used.
|
||||||
ssh_key_been_used = Public key name has been used.
|
ssh_key_been_used = Public key name or content has been used.
|
||||||
illegal_username = Your username contains illegal characters.
|
illegal_username = Your username contains illegal characters.
|
||||||
illegal_repo_name = Repository name contains illegal characters.
|
illegal_repo_name = Repository name contains illegal characters.
|
||||||
illegal_org_name = Organization name contains illegal characters.
|
illegal_org_name = Organization name contains illegal characters.
|
||||||
|
|
|
@ -130,7 +130,6 @@ func extractTypeFromBase64Key(key string) (string, error) {
|
||||||
|
|
||||||
// Parse any key string in openssh or ssh2 format to clean openssh string (rfc4253)
|
// Parse any key string in openssh or ssh2 format to clean openssh string (rfc4253)
|
||||||
func ParseKeyString(content string) (string, error) {
|
func ParseKeyString(content string) (string, error) {
|
||||||
|
|
||||||
// Transform all legal line endings to a single "\n"
|
// Transform all legal line endings to a single "\n"
|
||||||
s := strings.Replace(strings.Replace(strings.TrimSpace(content), "\r\n", "\n", -1), "\r", "\n", -1)
|
s := strings.Replace(strings.Replace(strings.TrimSpace(content), "\r\n", "\n", -1), "\r", "\n", -1)
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ var (
|
||||||
ErrUserHasOrgs = errors.New("User still have membership of organization")
|
ErrUserHasOrgs = errors.New("User still have membership of organization")
|
||||||
ErrUserAlreadyExist = errors.New("User already exist")
|
ErrUserAlreadyExist = errors.New("User already exist")
|
||||||
ErrUserNotExist = errors.New("User does not exist")
|
ErrUserNotExist = errors.New("User does not exist")
|
||||||
ErrPublicKeyNotExist = errors.New("Public key does not exist")
|
ErrUserNotKeyOwner = errors.New("User does not the owner of public key")
|
||||||
ErrEmailAlreadyUsed = errors.New("E-mail already used")
|
ErrEmailAlreadyUsed = errors.New("E-mail already used")
|
||||||
ErrEmailNotExist = errors.New("E-mail does not exist")
|
ErrEmailNotExist = errors.New("E-mail does not exist")
|
||||||
ErrEmailNotActivated = errors.New("E-mail address has not been activated")
|
ErrEmailNotActivated = errors.New("E-mail address has not been activated")
|
||||||
|
@ -518,7 +518,7 @@ func GetUserByKeyId(keyId int64) (*User, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
} else if !has {
|
} else if !has {
|
||||||
return nil, ErrPublicKeyNotExist
|
return nil, ErrUserNotKeyOwner
|
||||||
}
|
}
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue