Skip to content

Commit

Permalink
REFACTOR: old patterns and deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
jjaffeux authored and danielwaterworth committed Jul 26, 2019
1 parent a36ebf8 commit b7f7251
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 28 deletions.
1 change: 1 addition & 0 deletions assets/javascripts/discourse/activity-route-map.js.es6
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default {
resource: "user.userActivity",

map() {
this.route("approval-given");
this.route("approval-pending");
Expand Down
30 changes: 12 additions & 18 deletions assets/javascripts/discourse/initializers/init-code-review.js.es6
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import DiscourseURL from "discourse/lib/url";
import { findAll } from "discourse/models/login-method";

function actOnCommit(topic, action) {
const topicId = topic.get("id");
return ajax(`/code-review/${action}.json`, {
type: "POST",
data: { topic_id: topicId }
data: { topic_id: topic.id }
})
.then(result => {
if (result.next_topic_url) {
Expand All @@ -31,18 +30,14 @@ function initialize(api) {
// note there are slightly cleaner ways of doing this but we would need
// to amend core for the plugin which is not feeling right
api.modifyClass("controller:preferences/account", {
canUpdateAssociatedAccounts: function() {
canUpdateAssociatedAccounts: Ember.computed("authProviders", function() {
return (
findAll(this.siteSettings, this.capabilities, this.site.isMobileDevice)
.length > 0
);
}.property("authProviders")
})
});

function allowUser(currentUser) {
return currentUser && currentUser.get("staff");
}

function allowApprove(currentUser, topic, siteSettings) {
if (!currentUser) {
return false;
Expand All @@ -52,11 +47,10 @@ function initialize(api) {
const approvedTag = siteSettings.code_review_approved_tag;
const pendingTag = siteSettings.code_review_pending_tag;
const followupTag = siteSettings.code_review_followup_tag;

const tags = topic.get("tags") || [];
const tags = topic.tags || [];

return (
(allowSelfApprove || currentUser.get("id") !== topic.get("user_id")) &&
(allowSelfApprove || currentUser.id !== topic.user_id) &&
!tags.includes(approvedTag) &&
(tags.includes(pendingTag) || tags.includes(followupTag))
);
Expand All @@ -67,7 +61,7 @@ function initialize(api) {
const pendingTag = siteSettings.code_review_pending_tag;
const followupTag = siteSettings.code_review_followup_tag;

const tags = topic.get("tags") || [];
const tags = topic.tags || [];

return (
!tags.includes(followupTag) &&
Expand All @@ -82,7 +76,7 @@ function initialize(api) {
label: "code_review.approve.label",
title: "code_review.approve.title",
action() {
actOnCommit(this.get("topic"), "approve");
actOnCommit(this.topic, "approve");
},
dropdown() {
return this.site.mobileView;
Expand All @@ -91,8 +85,8 @@ function initialize(api) {
dependentKeys: ["topic.tags"],
displayed() {
return (
allowUser(this.currentUser) &&
allowApprove(this.currentUser, this.get("topic"), this.siteSettings)
this.get("currentUser.staff") &&
allowApprove(this.currentUser, this.topic, this.siteSettings)
);
}
});
Expand All @@ -104,7 +98,7 @@ function initialize(api) {
label: "code_review.followup.label",
title: "code_review.followup.title",
action() {
actOnCommit(this.get("topic"), "followup");
actOnCommit(this.topic, "followup");
},
dropdown() {
return this.site.mobileView;
Expand All @@ -113,8 +107,8 @@ function initialize(api) {
dependentKeys: ["topic.tags"],
displayed() {
return (
allowUser(this.currentUser) &&
allowFollowup(this.get("topic"), this.siteSettings)
this.get("currentUser.staff") &&
allowFollowup(this.topic, this.siteSettings)
);
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import UserTopicListRoute from "discourse/routes/user-topic-list";

export default UserTopicListRoute.extend({
model: function() {
model() {
const username = this.modelFor("user").username_lower;
return this.store.findFiltered("topicList", {
filter: `topics/approval-given/${this.modelFor("user").get(
"username_lower"
)}`
filter: `topics/approval-given/${username}`
});
}
});
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import UserTopicListRoute from "discourse/routes/user-topic-list";

export default UserTopicListRoute.extend({
model: function() {
model() {
const username = this.modelFor("user").username_lower;
return this.store.findFiltered("topicList", {
filter: `topics/approval-pending/${this.modelFor("user").get(
"username_lower"
)}`
filter: `topics/approval-pending/${username}`
});
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ acceptance("review desktop", {
});

QUnit.test("shows approve button by default", async assert => {
const json = $.extend(true, {}, Fixtures["/t/280/1.json"]);
const json = Object.assign({}, Fixtures["/t/280/1.json"]);

json.tags = ["pending"];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ acceptance("review mobile", {
});

QUnit.test("shows approve button by default", async assert => {
const json = $.extend(true, {}, Fixtures["/t/280/1.json"]);
const json = Object.assign({}, Fixtures["/t/280/1.json"]);

json.tags = ["pending"];

Expand Down

0 comments on commit b7f7251

Please sign in to comment.