mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 21:43:45 +08:00
Merge pull request #3822 from fantasticfears/routes
FIX: Add user id in the admin user routes
This commit is contained in:
commit
f3ec2ac61e
|
@ -402,7 +402,7 @@ const AdminUser = Discourse.User.extend({
|
|||
}
|
||||
}
|
||||
}).catch(function() {
|
||||
AdminUser.find( user.get('username') ).then(function(u){ user.setProperties(u); });
|
||||
AdminUser.find(user.get('id')).then(u => user.setProperties(u));
|
||||
bootbox.alert(I18n.t("admin.user.delete_failed"));
|
||||
});
|
||||
};
|
||||
|
@ -475,7 +475,7 @@ const AdminUser = Discourse.User.extend({
|
|||
|
||||
if (user.get('loadedDetails')) { return Ember.RSVP.resolve(user); }
|
||||
|
||||
return AdminUser.find(user.get('username_lower')).then(function (result) {
|
||||
return AdminUser.find(user.get('id')).then(result => {
|
||||
user.setProperties(result);
|
||||
user.set('loadedDetails', true);
|
||||
});
|
||||
|
@ -533,8 +533,8 @@ AdminUser.reopenClass({
|
|||
});
|
||||
},
|
||||
|
||||
find(username) {
|
||||
return Discourse.ajax("/admin/users/" + username + ".json").then(function (result) {
|
||||
find(user_id) {
|
||||
return Discourse.ajax("/admin/users/" + user_id + ".json").then(result => {
|
||||
result.loadedDetails = true;
|
||||
return AdminUser.create(result);
|
||||
});
|
||||
|
|
|
@ -62,7 +62,7 @@ export default {
|
|||
});
|
||||
|
||||
this.resource('adminUsers', { path: '/users' }, function() {
|
||||
this.resource('adminUser', { path: '/:username' }, function() {
|
||||
this.resource('adminUser', { path: '/:user_id/:username' }, function() {
|
||||
this.route('badges');
|
||||
this.route('tl3Requirements', { path: '/tl3_requirements' });
|
||||
});
|
||||
|
|
|
@ -2,11 +2,11 @@ import AdminUser from 'admin/models/admin-user';
|
|||
|
||||
export default Discourse.Route.extend({
|
||||
serialize(model) {
|
||||
return { username: model.get('username').toLowerCase() };
|
||||
return { user_id: model.get('id'), username: model.get('username').toLowerCase() };
|
||||
},
|
||||
|
||||
model(params) {
|
||||
return AdminUser.find(Em.get(params, 'username').toLowerCase());
|
||||
return AdminUser.find(Em.get(params, 'user_id'));
|
||||
},
|
||||
|
||||
renderTemplate() {
|
||||
|
|
|
@ -141,8 +141,7 @@ export default Ember.Controller.extend(ModalFunctionality, {
|
|||
fetchUserDetails() {
|
||||
if (Discourse.User.currentProp('staff') && this.get('model.username')) {
|
||||
const AdminUser = require('admin/models/admin-user').default;
|
||||
AdminUser.find(this.get('model.username').toLowerCase())
|
||||
.then(user => this.set('userDetails', user));
|
||||
AdminUser.find(this.get('model.id')).then(user => this.set('userDetails', user));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -84,8 +84,7 @@ export default Ember.Controller.extend(CanCheckEmails, {
|
|||
adminDelete() {
|
||||
// I really want this deferred, don't want to bring in all this code till used
|
||||
const AdminUser = require('admin/models/admin-user').default;
|
||||
AdminUser.find(this.get('model.username').toLowerCase())
|
||||
.then(user => user.destroy({deletePosts: true}));
|
||||
AdminUser.find(this.get('model.id')).then(user => user.destroy({deletePosts: true}));
|
||||
},
|
||||
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ const User = RestModel.extend({
|
|||
|
||||
},
|
||||
|
||||
adminPath: url('username_lower', "/admin/users/%@"),
|
||||
adminPath: url('id', 'username_lower', "/admin/users/%@1/%@2"),
|
||||
|
||||
mutedTopicsPath: url('/latest?state=muted'),
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ class Admin::UsersController < Admin::AdminController
|
|||
end
|
||||
|
||||
def show
|
||||
@user = User.find_by(username_lower: params[:id])
|
||||
@user = User.find_by(id: params[:id])
|
||||
raise Discourse::NotFound unless @user
|
||||
render_serialized(@user, AdminDetailedUserSerializer, root: false)
|
||||
end
|
||||
|
|
|
@ -73,8 +73,7 @@ Discourse::Application.routes.draw do
|
|||
get "groups/:type" => "groups#show", constraints: AdminConstraint.new
|
||||
get "groups/:type/:id" => "groups#show", constraints: AdminConstraint.new
|
||||
|
||||
get "users/:id.json" => 'users#show' , id: USERNAME_ROUTE_FORMAT, defaults: {format: 'json'}
|
||||
resources :users, id: USERNAME_ROUTE_FORMAT do
|
||||
resources :users, id: USERNAME_ROUTE_FORMAT, except: [:show] do
|
||||
collection do
|
||||
get "list/:query" => "users#index"
|
||||
get "ip-info" => "users#ip_info"
|
||||
|
@ -109,6 +108,8 @@ Discourse::Application.routes.draw do
|
|||
get "tl3_requirements"
|
||||
put "anonymize"
|
||||
end
|
||||
get "users/:id.json" => 'users#show', defaults: {format: 'json'}
|
||||
get 'users/:id/:username' => 'users#show'
|
||||
|
||||
|
||||
post "users/sync_sso" => "users#sync_sso", constraints: AdminConstraint.new
|
||||
|
|
|
@ -47,14 +47,14 @@ describe Admin::UsersController do
|
|||
describe '.show' do
|
||||
context 'an existing user' do
|
||||
it 'returns success' do
|
||||
xhr :get, :show, id: @user.username
|
||||
xhr :get, :show, id: @user.id
|
||||
expect(response).to be_success
|
||||
end
|
||||
end
|
||||
|
||||
context 'an existing user' do
|
||||
it 'returns success' do
|
||||
xhr :get, :show, id: 'foobar'
|
||||
xhr :get, :show, id: 0
|
||||
expect(response).not_to be_success
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue
Block a user