* add drafts.json endpoint, user profile tab with drafts stream * improve drafts stream display in user profile * truncate excerpts in drafts list, better handling for resume draft action * improve draft stream SQL query, add rspec tests * if composer is open, quietly close it when user opens another draft from drafts stream; load PM draft only when user is in /u/username/messages (instead of /u/username) * cleanup * linting fixes * apply prettier styling to modified files * add client tests for drafts, includes a fixture for drafts.json * improvements to code following review * refresh drafts route when user deletes a draft open in the composer while being in the drafts route; minor prettier scss fix * added more spec tests, deleted an acceptance test for removing drafts that was too finicky, formatting and code style fixes, added appEvent for draft:destroyed * prettier, eslint fixes * use "username_lower" from users table, added error handling for rejected promises * adds guardian spec for can_see_drafts, adds improvements following code review * move DraftsController spec to its own file * fix failing drafts qunit test, use getOwner instead of deprecated this.container * limit test fixture for draft.json testing to new_topic request only
90 lines
2.1 KiB
JavaScript
90 lines
2.1 KiB
JavaScript
export default Discourse.Route.extend({
|
|
titleToken() {
|
|
const username = this.modelFor("user").get("username");
|
|
if (username) {
|
|
return [I18n.t("user.profile"), username];
|
|
}
|
|
},
|
|
|
|
actions: {
|
|
willTransition(transition) {
|
|
// will reset the indexStream when transitioning to routes that aren't "indexStream"
|
|
// otherwise the "header" will jump
|
|
const isIndexStream = transition.targetName === "user.summary";
|
|
this.controllerFor("user").set("indexStream", isIndexStream);
|
|
return true;
|
|
},
|
|
|
|
undoRevokeApiKey(key) {
|
|
key.undoRevoke();
|
|
},
|
|
|
|
revokeApiKey(key) {
|
|
key.revoke();
|
|
}
|
|
},
|
|
|
|
beforeModel() {
|
|
if (this.siteSettings.hide_user_profiles_from_public && !this.currentUser) {
|
|
this.replaceWith("discovery");
|
|
}
|
|
},
|
|
|
|
model(params) {
|
|
// If we're viewing the currently logged in user, return that object instead
|
|
const currentUser = this.currentUser;
|
|
if (
|
|
currentUser &&
|
|
params.username.toLowerCase() === currentUser.get("username_lower")
|
|
) {
|
|
return currentUser;
|
|
}
|
|
|
|
return Discourse.User.create({ username: params.username });
|
|
},
|
|
|
|
afterModel() {
|
|
const user = this.modelFor("user");
|
|
const self = this;
|
|
|
|
return user
|
|
.findDetails()
|
|
.then(function() {
|
|
return user.findStaffInfo();
|
|
})
|
|
.catch(function() {
|
|
return self.replaceWith("/404");
|
|
});
|
|
},
|
|
|
|
serialize(model) {
|
|
if (!model) return {};
|
|
return { username: (Em.get(model, "username") || "").toLowerCase() };
|
|
},
|
|
|
|
setupController(controller, user) {
|
|
controller.set("model", user);
|
|
this.searchService.set("searchContext", user.get("searchContext"));
|
|
},
|
|
|
|
activate() {
|
|
this._super();
|
|
const user = this.modelFor("user");
|
|
this.messageBus.subscribe("/u/" + user.get("username_lower"), function(
|
|
data
|
|
) {
|
|
user.loadUserAction(data);
|
|
});
|
|
},
|
|
|
|
deactivate() {
|
|
this._super();
|
|
this.messageBus.unsubscribe(
|
|
"/u/" + this.modelFor("user").get("username_lower")
|
|
);
|
|
|
|
// Remove the search context
|
|
this.searchService.set("searchContext", null);
|
|
}
|
|
});
|