Use lower case group names in URLs
This commit is contained in:
parent
43612e9fde
commit
18e98851e3
|
@ -12,6 +12,10 @@ Discourse.GroupRoute = Discourse.Route.extend({
|
||||||
return Discourse.Group.find(params.name);
|
return Discourse.Group.find(params.name);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
serialize: function(model) {
|
||||||
|
return { name: model.get('name').toLowerCase() };
|
||||||
|
},
|
||||||
|
|
||||||
afterModel: function(model) {
|
afterModel: function(model) {
|
||||||
var self = this;
|
var self = this;
|
||||||
return Discourse.Group.findGroupCounts(model.get('name')).then(function (counts) {
|
return Discourse.Group.findGroupCounts(model.get('name')).then(function (counts) {
|
||||||
|
|
|
@ -1,29 +1,33 @@
|
||||||
class GroupsController < ApplicationController
|
class GroupsController < ApplicationController
|
||||||
|
|
||||||
def show
|
def show
|
||||||
group = Group.where(name: params.require(:id)).first
|
render_serialized(find_group(:id), BasicGroupSerializer)
|
||||||
guardian.ensure_can_see!(group)
|
|
||||||
render_serialized(group, BasicGroupSerializer)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def counts
|
def counts
|
||||||
group = Group.where(name: params.require(:group_id)).first
|
group = find_group(:group_id)
|
||||||
guardian.ensure_can_see!(group)
|
|
||||||
render json: {counts: { posts: group.posts_for(guardian).count,
|
render json: {counts: { posts: group.posts_for(guardian).count,
|
||||||
members: group.users.count } }
|
members: group.users.count } }
|
||||||
end
|
end
|
||||||
|
|
||||||
def posts
|
def posts
|
||||||
group = Group.where(name: params.require(:group_id)).first
|
group = find_group(:group_id)
|
||||||
guardian.ensure_can_see!(group)
|
|
||||||
posts = group.posts_for(guardian, params[:before_post_id]).limit(20)
|
posts = group.posts_for(guardian, params[:before_post_id]).limit(20)
|
||||||
render_serialized posts.to_a, GroupPostSerializer
|
render_serialized posts.to_a, GroupPostSerializer
|
||||||
end
|
end
|
||||||
|
|
||||||
def members
|
def members
|
||||||
group = Group.where(name: params.require(:group_id)).first
|
group = find_group(:group_id)
|
||||||
guardian.ensure_can_see!(group)
|
|
||||||
render_serialized(group.users.order('username_lower asc').limit(200).to_a, GroupUserSerializer)
|
render_serialized(group.users.order('username_lower asc').limit(200).to_a, GroupUserSerializer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def find_group(param_name)
|
||||||
|
name = params.require(param_name)
|
||||||
|
group = Group.where("lower(name) = ?", name.downcase).first
|
||||||
|
guardian.ensure_can_see!(group)
|
||||||
|
group
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,6 +16,13 @@ describe GroupsController do
|
||||||
response.should be_success
|
response.should be_success
|
||||||
::JSON.parse(response.body)['basic_group']['id'].should == group.id
|
::JSON.parse(response.body)['basic_group']['id'].should == group.id
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "works even with an upper case group name" do
|
||||||
|
Guardian.any_instance.expects(:can_see?).with(group).returns(true)
|
||||||
|
xhr :get, :show, id: group.name.upcase
|
||||||
|
response.should be_success
|
||||||
|
::JSON.parse(response.body)['basic_group']['id'].should == group.id
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "counts" do
|
describe "counts" do
|
||||||
|
|
Loading…
Reference in New Issue