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);
|
||||
},
|
||||
|
||||
serialize: function(model) {
|
||||
return { name: model.get('name').toLowerCase() };
|
||||
},
|
||||
|
||||
afterModel: function(model) {
|
||||
var self = this;
|
||||
return Discourse.Group.findGroupCounts(model.get('name')).then(function (counts) {
|
||||
|
|
|
@ -1,29 +1,33 @@
|
|||
class GroupsController < ApplicationController
|
||||
|
||||
def show
|
||||
group = Group.where(name: params.require(:id)).first
|
||||
guardian.ensure_can_see!(group)
|
||||
render_serialized(group, BasicGroupSerializer)
|
||||
render_serialized(find_group(:id), BasicGroupSerializer)
|
||||
end
|
||||
|
||||
def counts
|
||||
group = Group.where(name: params.require(:group_id)).first
|
||||
guardian.ensure_can_see!(group)
|
||||
group = find_group(:group_id)
|
||||
render json: {counts: { posts: group.posts_for(guardian).count,
|
||||
members: group.users.count } }
|
||||
end
|
||||
|
||||
def posts
|
||||
group = Group.where(name: params.require(:group_id)).first
|
||||
guardian.ensure_can_see!(group)
|
||||
group = find_group(:group_id)
|
||||
posts = group.posts_for(guardian, params[:before_post_id]).limit(20)
|
||||
render_serialized posts.to_a, GroupPostSerializer
|
||||
end
|
||||
|
||||
def members
|
||||
group = Group.where(name: params.require(:group_id)).first
|
||||
guardian.ensure_can_see!(group)
|
||||
group = find_group(:group_id)
|
||||
render_serialized(group.users.order('username_lower asc').limit(200).to_a, GroupUserSerializer)
|
||||
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
|
||||
|
|
|
@ -16,6 +16,13 @@ describe GroupsController do
|
|||
response.should be_success
|
||||
::JSON.parse(response.body)['basic_group']['id'].should == group.id
|
||||
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
|
||||
|
||||
describe "counts" do
|
||||
|
|
Loading…
Reference in New Issue