Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix incorrect repo url when changed the case of ownername #25733

Merged
merged 15 commits into from
Jul 14, 2023
5 changes: 3 additions & 2 deletions routers/web/org/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func SettingsPost(ctx *context.Context) {
// reset ctx.org.OrgLink with new name
ctx.Org.OrgLink = setting.AppSubURL + "/org/" + url.PathEscape(form.Name)
log.Trace("Organization name changed: %s -> %s", org.Name, form.Name)
nameChanged = false
}

// In case it's just a case change.
Expand Down Expand Up @@ -130,7 +129,9 @@ func SettingsPost(ctx *context.Context) {
return
}
}
} else if nameChanged {
}

if nameChanged {
if err := repo_model.UpdateRepositoryOwnerNames(org.ID, org.Name); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

func RenameOrganization(ctx context.Context, org *org_model.Organization, newName string) error {
return user_service.RenameUser(ctx, org.AsUser(), newName)
}

RenameOrganization call RenameUser, and in RenameUser we will call UpdateRepositoryOwnerNames, so it is no need to call it again here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RenameOrganization -> RenameUser -> UpdateRepositoryOwnerNames, Why call it again?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RenameOrganization -> RenameUser -> UpdateRepositoryOwnerNames, Why call it again?

In L70:
RenameOrganization -> RenameUser -> UpdateRepositoryOwnerNames
UpdateRepositoryOwnerNames will be called for the first time.

In L135, UpdateRepositoryOwnerNames will be called again.

So UpdateRepositoryOwnerNames will be called two times.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeatedly called it

Copy link
Contributor Author

@hiifong hiifong Jul 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the second call it.
default_canvas

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed?

Copy link
Contributor Author

@hiifong hiifong Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now file changed:

diff --git a/routers/web/org/setting.go b/routers/web/org/setting.go
index b5653160a..bd558f78b 100644
--- a/routers/web/org/setting.go
+++ b/routers/web/org/setting.go
@@ -89,7 +89,6 @@ func SettingsPost(ctx *context.Context) {
 		// reset ctx.org.OrgLink with new name
 		ctx.Org.OrgLink = setting.AppSubURL + "/org/" + url.PathEscape(form.Name)
 		log.Trace("Organization name changed: %s -> %s", org.Name, form.Name)
-		nameChanged = false
 	}
 
 	// In case it's just a case change.
@@ -130,11 +129,6 @@ func SettingsPost(ctx *context.Context) {
 				return
 			}
 		}
-	} else if nameChanged {
-		if err := repo_model.UpdateRepositoryOwnerNames(org.ID, org.Name); err != nil {
-			ctx.ServerError("UpdateRepository", err)
-			return
-		}
 	}
 
 	log.Trace("Organization setting updated: %s", org.Name)
diff --git a/services/user/user.go b/services/user/user.go
index e0815bd86..bb3dd002e 100644
--- a/services/user/user.go
+++ b/services/user/user.go
@@ -58,7 +58,7 @@ func RenameUser(ctx context.Context, u *user_model.User, newUserName string) err
 			u.Name = oldUserName
 			return err
 		}
-		return nil
+		return repo_model.UpdateRepositoryOwnerNames(u.ID, newUserName)
 	}
 
 	ctx, committer, err := db.TxContext(ctx)

When only the case of the user name changes and the new user name is consistent with the lowercase user name of the old user name, update the owner name of the repo, and keep the original logic consistent with other conditions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed?

yes

ctx.ServerError("UpdateRepository", err)
hiifong marked this conversation as resolved.
Show resolved Hide resolved
return
Expand Down
4 changes: 2 additions & 2 deletions services/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func RenameUser(ctx context.Context, u *user_model.User, newUserName string) err
u.Name = oldUserName
return err
}
return nil
return repo_model.UpdateRepositoryOwnerNames(u.ID, newUserName)
}

ctx, committer, err := db.TxContext(ctx)
Expand All @@ -77,7 +77,7 @@ func RenameUser(ctx context.Context, u *user_model.User, newUserName string) err
}
}

if err = repo_model.UpdateRepositoryOwnerName(ctx, oldUserName, newUserName); err != nil {
if err = repo_model.UpdateRepositoryOwnerNames(u.ID, newUserName); err != nil {
hiifong marked this conversation as resolved.
Show resolved Hide resolved
return err
}

Expand Down