mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
Redirect to Summary when viewing yourself
This commit is contained in:
parent
d38727efb7
commit
857d54162b
9 changed files with 78 additions and 39 deletions
|
@ -2,12 +2,22 @@ import DiscourseURL from 'discourse/lib/url';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'url-redirects',
|
name: 'url-redirects',
|
||||||
initialize: function() {
|
after: 'inject-objects',
|
||||||
|
|
||||||
|
initialize(container) {
|
||||||
|
|
||||||
|
const currentUser = container.lookup('current-user:main');
|
||||||
|
|
||||||
// URL rewrites (usually due to refactoring)
|
// URL rewrites (usually due to refactoring)
|
||||||
DiscourseURL.rewrite(/^\/category\//, "/c/");
|
DiscourseURL.rewrite(/^\/category\//, "/c/");
|
||||||
DiscourseURL.rewrite(/^\/group\//, "/groups/");
|
DiscourseURL.rewrite(/^\/group\//, "/groups/");
|
||||||
DiscourseURL.rewrite(/\/private-messages\/$/, "/messages/");
|
DiscourseURL.rewrite(/\/private-messages\/$/, "/messages/");
|
||||||
|
|
||||||
|
if (currentUser) {
|
||||||
|
const username = currentUser.get('username');
|
||||||
|
DiscourseURL.rewrite(new RegExp(`^/users/${username}/?$`, "i"), `/users/${username}/summary`);
|
||||||
|
}
|
||||||
|
|
||||||
DiscourseURL.rewrite(/^\/users\/([^\/]+)\/?$/, "/users/$1/activity");
|
DiscourseURL.rewrite(/^\/users\/([^\/]+)\/?$/, "/users/$1/activity");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -245,7 +245,7 @@ const User = RestModel.extend({
|
||||||
|
|
||||||
@computed("groups.[]")
|
@computed("groups.[]")
|
||||||
displayGroups() {
|
displayGroups() {
|
||||||
const groups = this.get('groups');
|
const groups = this.get('groups') || [];
|
||||||
const filtered = groups.filter(group => {
|
const filtered = groups.filter(group => {
|
||||||
return !group.automatic || group.name === "moderators";
|
return !group.automatic || group.name === "moderators";
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,13 +1,18 @@
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
|
|
||||||
beforeModel: function() {
|
beforeModel() {
|
||||||
|
|
||||||
|
const { currentUser } = this;
|
||||||
|
const viewingMe = (currentUser && currentUser.get('username') === this.modelFor('user').get('username'));
|
||||||
|
const destination = viewingMe ? 'user.summary' : 'userActivity';
|
||||||
|
|
||||||
// HACK: Something with the way the user card intercepts clicks seems to break how the
|
// HACK: Something with the way the user card intercepts clicks seems to break how the
|
||||||
// transition into a user's activity works. This makes the back button work on mobile
|
// transition into a user's activity works. This makes the back button work on mobile
|
||||||
// where there is no user card as well as desktop where there is.
|
// where there is no user card as well as desktop where there is.
|
||||||
if (this.site.mobileView) {
|
if (this.site.mobileView) {
|
||||||
this.replaceWith('userActivity');
|
this.replaceWith(destination);
|
||||||
} else {
|
} else {
|
||||||
this.transitionTo('userActivity');
|
this.transitionTo(destination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
export default Discourse.Route.extend({
|
export default Discourse.Route.extend({
|
||||||
model() {
|
model() {
|
||||||
return this.modelFor("User").summary();
|
return this.modelFor("user").summary();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
import ScrollTop from 'discourse/mixins/scroll-top';
|
import ScrollTop from 'discourse/mixins/scroll-top';
|
||||||
|
|
||||||
export default Ember.View.extend(ScrollTop, {
|
export default Ember.View.extend(ScrollTop);
|
||||||
templateName: 'user/user',
|
|
||||||
});
|
|
||||||
|
|
|
@ -8,29 +8,35 @@ export function hasStream() {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// function hasTopicList() {
|
function hasTopicList() {
|
||||||
// andThen(() => {
|
andThen(() => {
|
||||||
// equal(count('.user-stream .item'), 0, "has no stream displayed");
|
equal(count('.user-stream .item'), 0, "has no stream displayed");
|
||||||
// ok(count('.topic-list tr') > 0, 'it has a topic list');
|
ok(count('.topic-list tr') > 0, 'it has a topic list');
|
||||||
// });
|
});
|
||||||
// }
|
}
|
||||||
|
|
||||||
// test("Filters", () => {
|
test("Root URL", () => {
|
||||||
// visit("/users/eviltrout");
|
visit("/users/eviltrout");
|
||||||
// hasStream();
|
andThen(() => {
|
||||||
//
|
equal(currentPath(), 'user.userActivity.index', "it defaults to activity");
|
||||||
// visit("/users/eviltrout/activity/topics");
|
});
|
||||||
// hasTopicList();
|
});
|
||||||
//
|
|
||||||
// visit("/users/eviltrout/activity/posts");
|
test("Filters", () => {
|
||||||
// hasStream();
|
visit("/users/eviltrout/activity");
|
||||||
//
|
hasStream();
|
||||||
// });
|
|
||||||
//
|
visit("/users/eviltrout/activity/topics");
|
||||||
// test("Restricted Routes", () => {
|
hasTopicList();
|
||||||
// visit("/users/eviltrout/preferences");
|
|
||||||
//
|
visit("/users/eviltrout/activity/replies");
|
||||||
// andThen(() => {
|
hasStream();
|
||||||
// equal(currentURL(), '/users/eviltrout/activity', "it redirects from preferences");
|
});
|
||||||
// });
|
|
||||||
// });
|
test("Restricted Routes", () => {
|
||||||
|
visit("/users/eviltrout/preferences");
|
||||||
|
|
||||||
|
andThen(() => {
|
||||||
|
equal(currentURL(), '/users/eviltrout/activity', "it redirects from preferences");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -1,9 +1,17 @@
|
||||||
import { acceptance } from "helpers/qunit-helpers";
|
import { acceptance } from "helpers/qunit-helpers";
|
||||||
// import { hasStream } from 'acceptance/user-anonymous-test';
|
import { hasStream } from 'acceptance/user-anonymous-test';
|
||||||
|
|
||||||
acceptance("User", {loggedIn: true});
|
acceptance("User", {loggedIn: true});
|
||||||
|
|
||||||
// test("Pending", () => {
|
test("Pending", () => {
|
||||||
// visit("/users/eviltrout/activity/pending");
|
visit("/users/eviltrout/activity/pending");
|
||||||
// hasStream();
|
hasStream();
|
||||||
// });
|
});
|
||||||
|
|
||||||
|
test("Root URL - Viewing Self", () => {
|
||||||
|
visit("/users/eviltrout");
|
||||||
|
andThen(() => {
|
||||||
|
equal(currentPath(), 'user.summary', "it defaults to summary");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,18 @@ export default function() {
|
||||||
return response(json);
|
return response(json);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.get('/users/eviltrout/summary.json', () => {
|
||||||
|
return response({
|
||||||
|
user_summary: {
|
||||||
|
topics: [],
|
||||||
|
topic_ids: [],
|
||||||
|
replies: [],
|
||||||
|
links: []
|
||||||
|
},
|
||||||
|
topics: [],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
this.get('/clicks/track', success);
|
this.get('/clicks/track', success);
|
||||||
|
|
||||||
this.put('/users/eviltrout', () => response({ user: {} }));
|
this.put('/users/eviltrout', () => response({ user: {} }));
|
||||||
|
|
Loading…
Reference in a new issue