Skip to content

Commit

Permalink
Merge branch 'master' into use-path-not-filepath-in-routers-editor
Browse files Browse the repository at this point in the history
  • Loading branch information
lafriks authored Jan 18, 2021
2 parents f9abbb5 + 6ff63c8 commit 3f3b6c9
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 34 deletions.
10 changes: 5 additions & 5 deletions models/issue_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Label struct {
func GetLabelTemplateFile(name string) ([][3]string, error) {
data, err := GetRepoInitFile("label", name)
if err != nil {
return nil, fmt.Errorf("GetRepoInitFile: %v", err)
return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("GetRepoInitFile: %v", err)}
}

lines := strings.Split(string(data), "\n")
Expand All @@ -62,15 +62,15 @@ func GetLabelTemplateFile(name string) ([][3]string, error) {

fields := strings.SplitN(parts[0], " ", 2)
if len(fields) != 2 {
return nil, fmt.Errorf("line is malformed: %s", line)
return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("line is malformed: %s", line)}
}

color := strings.Trim(fields[0], " ")
if len(color) == 6 {
color = "#" + color
}
if !LabelColorPattern.MatchString(color) {
return nil, fmt.Errorf("bad HTML color code in line: %s", line)
return nil, ErrIssueLabelTemplateLoad{name, fmt.Errorf("bad HTML color code in line: %s", line)}
}

var description string
Expand Down Expand Up @@ -167,7 +167,7 @@ func (label *Label) ForegroundColor() template.CSS {
func loadLabels(labelTemplate string) ([]string, error) {
list, err := GetLabelTemplateFile(labelTemplate)
if err != nil {
return nil, ErrIssueLabelTemplateLoad{labelTemplate, err}
return nil, err
}

labels := make([]string, len(list))
Expand All @@ -186,7 +186,7 @@ func LoadLabelsFormatted(labelTemplate string) (string, error) {
func initializeLabels(e Engine, id int64, labelTemplate string, isOrg bool) error {
list, err := GetLabelTemplateFile(labelTemplate)
if err != nil {
return ErrIssueLabelTemplateLoad{labelTemplate, err}
return err
}

labels := make([]*Label, len(list))
Expand Down
30 changes: 12 additions & 18 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1511,26 +1511,27 @@ func UpdateRepositoryUnits(repo *Repository, units []RepoUnit, deleteUnitTypes [
}

// DeleteRepository deletes a repository for a user or organization.
// make sure if you call this func to close open sessions (sqlite will otherwise get a deadlock)
func DeleteRepository(doer *User, uid, repoID int64) error {
sess := x.NewSession()
defer sess.Close()
if err := sess.Begin(); err != nil {
return err
}

// In case is a organization.
org, err := GetUserByID(uid)
org, err := getUserByID(sess, uid)
if err != nil {
return err
}
if org.IsOrganization() {
if err = org.GetTeams(&SearchTeamOptions{}); err != nil {
if err = org.getTeams(sess); err != nil {
return err
}
}

sess := x.NewSession()
defer sess.Close()
if err = sess.Begin(); err != nil {
return err
}

repo := &Repository{ID: repoID, OwnerID: uid}
has, err := sess.Get(repo)
repo := &Repository{OwnerID: uid}
has, err := sess.ID(repoID).Get(repo)
if err != nil {
return err
} else if !has {
Expand Down Expand Up @@ -1679,14 +1680,7 @@ func DeleteRepository(doer *User, uid, repoID int64) error {
}

if err = sess.Commit(); err != nil {
sess.Close()
if len(deployKeys) > 0 {
// We need to rewrite the public keys because the commit failed
if err2 := RewriteAllPublicKeys(); err2 != nil {
return fmt.Errorf("Commit: %v SSH Keys: %v", err, err2)
}
}
return fmt.Errorf("Commit: %v", err)
return err
}

sess.Close()
Expand Down
29 changes: 21 additions & 8 deletions modules/repository/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
opts.DefaultBranch = setting.Repository.DefaultBranch
}

// Check if label template exist
if len(opts.IssueLabels) > 0 {
if _, err := models.GetLabelTemplateFile(opts.IssueLabels); err != nil {
return nil, err
}
}

repo := &models.Repository{
OwnerID: u.ID,
Owner: u,
Expand All @@ -45,6 +52,8 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
TrustModel: opts.TrustModel,
}

var rollbackRepo *models.Repository

if err := models.WithTx(func(ctx models.DBContext) error {
if err := models.CreateRepository(ctx, doer, u, repo, false); err != nil {
return err
Expand Down Expand Up @@ -76,7 +85,7 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
}
}

if err := initRepository(ctx, repoPath, doer, repo, opts); err != nil {
if err = initRepository(ctx, repoPath, doer, repo, opts); err != nil {
if err2 := util.RemoveAll(repoPath); err2 != nil {
log.Error("initRepository: %v", err)
return fmt.Errorf(
Expand All @@ -87,10 +96,9 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod

// Initialize Issue Labels if selected
if len(opts.IssueLabels) > 0 {
if err := models.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil {
if errDelete := models.DeleteRepository(doer, u.ID, repo.ID); errDelete != nil {
log.Error("Rollback deleteRepository: %v", errDelete)
}
if err = models.InitializeLabels(ctx, repo.ID, opts.IssueLabels, false); err != nil {
rollbackRepo = repo
rollbackRepo.OwnerID = u.ID
return fmt.Errorf("InitializeLabels: %v", err)
}
}
Expand All @@ -99,13 +107,18 @@ func CreateRepository(doer, u *models.User, opts models.CreateRepoOptions) (*mod
SetDescription(fmt.Sprintf("CreateRepository(git update-server-info): %s", repoPath)).
RunInDir(repoPath); err != nil {
log.Error("CreateRepository(git update-server-info) in %v: Stdout: %s\nError: %v", repo, stdout, err)
if errDelete := models.DeleteRepository(doer, u.ID, repo.ID); errDelete != nil {
log.Error("Rollback deleteRepository: %v", errDelete)
}
rollbackRepo = repo
rollbackRepo.OwnerID = u.ID
return fmt.Errorf("CreateRepository(git update-server-info): %v", err)
}
return nil
}); err != nil {
if rollbackRepo != nil {
if errDelete := models.DeleteRepository(doer, rollbackRepo.OwnerID, rollbackRepo.ID); errDelete != nil {
log.Error("Rollback deleteRepository: %v", errDelete)
}
}

return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion modules/structs/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ type CreateRepoOption struct {
Description string `json:"description" binding:"MaxSize(255)"`
// Whether the repository is private
Private bool `json:"private"`
// Issue Label set to use
// Label-Set to use
IssueLabels string `json:"issue_labels"`
// Whether the repository should be auto-intialized?
AutoInit bool `json:"auto_init"`
Expand Down
1 change: 1 addition & 0 deletions options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ or_enter_secret = Or enter the secret: %s
then_enter_passcode = And enter the passcode shown in the application:
passcode_invalid = The passcode is incorrect. Try again.
twofa_enrolled = Your account has been enrolled into two-factor authentication. Store your scratch token (%s) in a safe place as it is only shown once!
twofa_failed_get_secret = Failed to get secret.

u2f_desc = Security keys are hardware devices containing cryptographic keys. They can be used for two-factor authentication. Security keys must support the <a rel="noreferrer" href="https://fidoalliance.org/">FIDO U2F</a> standard.
u2f_require_twofa = Your account must be enrolled in two-factor authentication to use security keys.
Expand Down
9 changes: 8 additions & 1 deletion routers/user/setting/security_twofa.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,14 @@ func EnrollTwoFactorPost(ctx *context.Context, form auth.TwoFactorAuthForm) {
return
}

secret := ctx.Session.Get("twofaSecret").(string)
secretRaw := ctx.Session.Get("twofaSecret")
if secretRaw == nil {
ctx.Flash.Error(ctx.Tr("settings.twofa_failed_get_secret"))
ctx.Redirect(setting.AppSubURL + "/user/settings/security/two_factor/enroll")
return
}

secret := secretRaw.(string)
if !totp.Validate(form.Passcode, secret) {
if !twofaGenerateSecretAndQr(ctx) {
return
Expand Down
2 changes: 1 addition & 1 deletion templates/swagger/v1_json.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -12488,7 +12488,7 @@
"x-go-name": "Gitignores"
},
"issue_labels": {
"description": "Issue Label set to use",
"description": "Label-Set to use",
"type": "string",
"x-go-name": "IssueLabels"
},
Expand Down

0 comments on commit 3f3b6c9

Please sign in to comment.