Redirect to Summary when viewing yourself

This commit is contained in:
Robin Ward 2016-08-02 13:21:06 -04:00
parent d38727efb7
commit 857d54162b
9 changed files with 78 additions and 39 deletions

View file

@ -2,12 +2,22 @@ import DiscourseURL from 'discourse/lib/url';
export default {
name: 'url-redirects',
initialize: function() {
after: 'inject-objects',
initialize(container) {
const currentUser = container.lookup('current-user:main');
// URL rewrites (usually due to refactoring)
DiscourseURL.rewrite(/^\/category\//, "/c/");
DiscourseURL.rewrite(/^\/group\//, "/groups/");
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");
}
};

View file

@ -245,7 +245,7 @@ const User = RestModel.extend({
@computed("groups.[]")
displayGroups() {
const groups = this.get('groups');
const groups = this.get('groups') || [];
const filtered = groups.filter(group => {
return !group.automatic || group.name === "moderators";
});

View file

@ -1,13 +1,18 @@
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
// 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.
if (this.site.mobileView) {
this.replaceWith('userActivity');
this.replaceWith(destination);
} else {
this.transitionTo('userActivity');
this.transitionTo(destination);
}
}

View file

@ -1,5 +1,5 @@
export default Discourse.Route.extend({
model() {
return this.modelFor("User").summary();
return this.modelFor("user").summary();
}
});

View file

@ -1,5 +1,3 @@
import ScrollTop from 'discourse/mixins/scroll-top';
export default Ember.View.extend(ScrollTop, {
templateName: 'user/user',
});
export default Ember.View.extend(ScrollTop);

View file

@ -8,29 +8,35 @@ export function hasStream() {
});
}
// function hasTopicList() {
// andThen(() => {
// equal(count('.user-stream .item'), 0, "has no stream displayed");
// ok(count('.topic-list tr') > 0, 'it has a topic list');
// });
// }
function hasTopicList() {
andThen(() => {
equal(count('.user-stream .item'), 0, "has no stream displayed");
ok(count('.topic-list tr') > 0, 'it has a topic list');
});
}
// test("Filters", () => {
// visit("/users/eviltrout");
// hasStream();
//
// visit("/users/eviltrout/activity/topics");
// hasTopicList();
//
// visit("/users/eviltrout/activity/posts");
// hasStream();
//
// });
//
// test("Restricted Routes", () => {
// visit("/users/eviltrout/preferences");
//
// andThen(() => {
// equal(currentURL(), '/users/eviltrout/activity', "it redirects from preferences");
// });
// });
test("Root URL", () => {
visit("/users/eviltrout");
andThen(() => {
equal(currentPath(), 'user.userActivity.index', "it defaults to activity");
});
});
test("Filters", () => {
visit("/users/eviltrout/activity");
hasStream();
visit("/users/eviltrout/activity/topics");
hasTopicList();
visit("/users/eviltrout/activity/replies");
hasStream();
});
test("Restricted Routes", () => {
visit("/users/eviltrout/preferences");
andThen(() => {
equal(currentURL(), '/users/eviltrout/activity', "it redirects from preferences");
});
});

View file

@ -1,9 +1,17 @@
import { acceptance } from "helpers/qunit-helpers";
// import { hasStream } from 'acceptance/user-anonymous-test';
import { hasStream } from 'acceptance/user-anonymous-test';
acceptance("User", {loggedIn: true});
// test("Pending", () => {
// visit("/users/eviltrout/activity/pending");
// hasStream();
// });
test("Pending", () => {
visit("/users/eviltrout/activity/pending");
hasStream();
});
test("Root URL - Viewing Self", () => {
visit("/users/eviltrout");
andThen(() => {
equal(currentPath(), 'user.summary', "it defaults to summary");
});
});

View file

@ -64,6 +64,18 @@ export default function() {
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.put('/users/eviltrout', () => response({ user: {} }));