Skip to content

Commit

Permalink
DEV: rename the "upgrade" route to "update" and change references. (#210
Browse files Browse the repository at this point in the history
)

This PR will rename the route "`/admin/upgrade`" to "`/admin/update`" and it will add a redirect for the old route.

Follow-up to the PR: #208
  • Loading branch information
vinothkannans authored Apr 3, 2024
1 parent 34f204e commit da49177
Show file tree
Hide file tree
Showing 21 changed files with 38 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@ export default class RepoStatus extends Component {

@action
upgrade() {
this.router.transitionTo("upgrade.show", this.args.repo);
this.router.transitionTo("update.show", this.args.repo);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="upgrades-banner">
{{i18n "admin.docker.outdated_notice"}}

<LinkTo @route="upgrade">
<LinkTo @route="update">
{{i18n "admin.docker.perform_update"}}
</LinkTo>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export default class UpgradeIndex extends Controller {

@action
upgradeAllButton() {
this.router.transitionTo("upgrade.show", "all");
this.router.transitionTo("update.show", "all");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default {
resource: "admin",

map() {
this.route("upgrade", { resetNamespace: true }, function () {
this.route("update", { resetNamespace: true }, function () {
this.route("processes");
this.route("show", { path: "/:id" });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
withPluginApi("1.24.0", (api) => {
api.addAdminSidebarSectionLink("root", {
name: "admin_upgrade",
route: "upgrade.index",
route: "update.index",
label: "admin.docker.update_tab",
icon: "rocket",
});
Expand Down
8 changes: 4 additions & 4 deletions admin/assets/javascripts/discourse/models/repo.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ export default class Repo {
}

static upgradeAll() {
return ajax("/admin/docker/upgrade", {
return ajax("/admin/docker/update", {
dataType: "text",
type: "POST",
data: { path: "all" },
});
}

static resetAll(repos) {
return ajax("/admin/docker/upgrade", {
return ajax("/admin/docker/update", {
dataType: "text",
type: "DELETE",
data: { path: "all", version: concatVersions(repos) },
Expand Down Expand Up @@ -172,7 +172,7 @@ export default class Repo {
}

async resetUpgrade() {
await this.repoAjax("/admin/docker/upgrade", {
await this.repoAjax("/admin/docker/update", {
dataType: "text",
type: "DELETE",
});
Expand All @@ -184,7 +184,7 @@ export default class Repo {
this.upgrading = true;

try {
await this.repoAjax("/admin/docker/upgrade", {
await this.repoAjax("/admin/docker/update", {
dataType: "text",
type: "POST",
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import Route from "@ember/routing/route";

export default class UpgradeIndex extends Route {
model() {
return this.modelFor("upgrade");
return this.modelFor("update");
}

async loadRepos(list) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export default class Upgrade extends Route {
}

activate() {
this.messageBus.subscribe("/docker/upgrade", this.onUpgradeMessage);
this.messageBus.subscribe("/docker/update", this.onUpgradeMessage);
}

deactivate() {
this.messageBus.unsubscribe("/docker/upgrade", this.onUpgradeMessage);
this.messageBus.unsubscribe("/docker/update", this.onUpgradeMessage);
}

setupController(controller, model) {
Expand Down Expand Up @@ -46,7 +46,7 @@ export default class Upgrade extends Route {
case "status":
this.upgradeStore.upgradeStatus = msg.value;
// Get the resolved model
const model = this.modelFor("upgrade");
const model = this.modelFor("update");

if (msg.value === "complete") {
for (const repo of model) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{{#if this.currentUser.admin}}
<NavItem @route="upgrade" @label="admin.docker.update_tab" />
<NavItem @route="update" @label="admin.docker.update_tab" />
{{/if}}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<nav>
<ul class="nav nav-pills">
<li>
<LinkTo @route="upgrade.index">
<LinkTo @route="update.index">
{{i18n "admin.docker.navigation.versions"}}
</LinkTo>
</li>

<li>
<LinkTo @route="upgrade.processes">
<LinkTo @route="update.processes">
{{i18n "admin.docker.navigation.processes"}}
</LinkTo>
</li>
Expand Down
10 changes: 6 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@

DockerManager::Engine.routes.draw do
scope "/admin", constraints: AdminConstraint.new do
get "/upgrade" => "admin#index"
get "/upgrade/:id" => "admin#index"
get "/upgrade", to: redirect("/admin/update")
get "/upgrade/:id", to: redirect("/admin/update/%{id}")
get "/update" => "admin#index"
get "/update/:id" => "admin#index"
get "/docker/repos" => "admin#repos"
get "/docker/latest" => "admin#latest"
get "/docker/progress" => "admin#progress"
get "/docker/ps" => "admin#ps"

post "/docker/upgrade" => "admin#upgrade"
delete "/docker/upgrade" => "admin#reset_upgrade"
post "/docker/update" => "admin#upgrade"
delete "/docker/update" => "admin#reset_upgrade"
end
end
4 changes: 2 additions & 2 deletions lib/docker_manager/upgrader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def upgrade

def publish(type, value)
MessageBus.publish(
"/docker/upgrade",
"/docker/update",
{ type: type, value: value, repos: @repos.map(&:name) },
user_ids: [@user_id],
)
Expand Down Expand Up @@ -259,7 +259,7 @@ def status(val)

def log_version_upgrade
StaffActionLogger.new(User.find(@user_id)).log_custom(
"discourse_upgrade",
"discourse_update",
from_version: @from_version,
repository: @repos.map(&:path).join(", "),
)
Expand Down
16 changes: 13 additions & 3 deletions spec/requests/admin_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe DockerManager::AdminController do
describe "anonymous user" do
it "should be a 404" do
get "/admin/upgrade"
get "/admin/update"

expect(response.status).to eq(404)
end
Expand All @@ -13,7 +13,7 @@
it "should 404" do
sign_in(Fabricate(:user))

get "/admin/upgrade"
get "/admin/update"
expect(response.status).to eq(404)
end
end
Expand All @@ -22,9 +22,19 @@
it "should return the right response" do
sign_in(Fabricate(:admin))

get "/admin/upgrade"
get "/admin/update"
expect(response.status).to eq(200)
end

it "should redirect to the new route" do
sign_in(Fabricate(:admin))

get "/admin/upgrade"
expect(response.status).to eq(301)

uri = URI.parse(response.headers["Location"])
expect(uri.path).to eq("/admin/update")
end
end

describe "#repos" do
Expand Down
2 changes: 1 addition & 1 deletion test/javascripts/acceptance/docker-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ acceptance("docker_manager", function (needs) {
});

await click(".upgrades-banner a");
assert.strictEqual(currentURL(), "/admin/upgrade");
assert.strictEqual(currentURL(), "/admin/update");

assert.dom(".docker-manager table#repos tbody tr").exists({ count: 2 });
assert.dom(".new.commit-hash").hasText("v3.1.0.beta2 +241");
Expand Down

0 comments on commit da49177

Please sign in to comment.