2
0
Fork 0
mirror of https://github.com/discourse/discourse.git synced 2025-09-07 12:02:53 +08:00

FEATURE: Allow group owners to edit group name and avatar flair.

This commit is contained in:
Guo Xiang Tan 2016-11-29 16:25:02 +08:00
parent b45fd21ed9
commit 31acd311e5
26 changed files with 453 additions and 209 deletions

View file

@ -1,12 +1,28 @@
class GroupsController < ApplicationController
before_filter :ensure_logged_in, only: [:set_notifications, :mentionable]
before_filter :ensure_logged_in, only: [
:set_notifications,
:mentionable,
:update
]
skip_before_filter :preload_json, :check_xhr, only: [:posts_feed, :mentions_feed]
def show
render_serialized(find_group(:id), GroupShowSerializer, root: 'basic_group')
end
def update
group = Group.find(params[:id])
guardian.ensure_can_edit!(group)
if group.update_attributes(group_params)
render json: success_json
else
render_json_error(group)
end
end
def posts
group = find_group(:group_id)
posts = group.posts_for(guardian, params[:before_post_id]).limit(20)
@ -152,11 +168,15 @@ class GroupsController < ApplicationController
private
def find_group(param_name)
name = params.require(param_name)
group = Group.find_by("lower(name) = ?", name.downcase)
guardian.ensure_can_see!(group)
group
end
def group_params
params.require(:group).permit(:flair_url, :flair_bg_color, :flair_color)
end
def find_group(param_name)
name = params.require(param_name)
group = Group.find_by("lower(name) = ?", name.downcase)
guardian.ensure_can_see!(group)
group
end
end