diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-06-03 10:40:32 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2012-06-03 10:40:32 +0000 |
commit | dd9c2cafa795ec00875981dcedd3287d2d005457 (patch) | |
tree | 4d540a76dc06fb4d530bb5804d3676fa366489d7 /app | |
parent | 3142183b3052b520126645eaec01526810e2afff (diff) | |
download | redmine-dd9c2cafa795ec00875981dcedd3287d2d005457.tar.gz redmine-dd9c2cafa795ec00875981dcedd3287d2d005457.zip |
REST Api for Groups (#8981).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@9758 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/groups_controller.rb | 26 | ||||
-rw-r--r-- | app/models/group.rb | 1 | ||||
-rw-r--r-- | app/views/groups/index.api.rsb | 10 | ||||
-rw-r--r-- | app/views/groups/show.api.rsb | 30 | ||||
-rw-r--r-- | app/views/users/show.api.rsb | 6 |
5 files changed, 59 insertions, 14 deletions
diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 6053bcc0e..e1c13969d 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -19,7 +19,8 @@ class GroupsController < ApplicationController layout 'admin' before_filter :require_admin - before_filter :find_group, :only => [:show, :edit, :update, :destroy, :add_users, :remove_user, :autocomplete_for_user, :edit_membership, :destroy_membership] + before_filter :find_group, :except => [:index, :new, :create] + accept_api_auth :index, :show, :create, :update, :destroy, :add_users, :remove_user helper :custom_fields @@ -28,24 +29,19 @@ class GroupsController < ApplicationController respond_to do |format| format.html - format.xml { render :xml => @groups } + format.api end end def show respond_to do |format| format.html - format.xml { render :xml => @group } + format.api end end def new @group = Group.new - - respond_to do |format| - format.html - format.xml { render :xml => @group } - end end def create @@ -58,10 +54,10 @@ class GroupsController < ApplicationController flash[:notice] = l(:notice_successful_create) redirect_to(params[:continue] ? new_group_path : groups_path) } - format.xml { render :xml => @group, :status => :created, :location => @group } + format.api { render :action => 'show', :status => :created, :location => group_url(@group) } else format.html { render :action => "new" } - format.xml { render :xml => @group.errors, :status => :unprocessable_entity } + format.api { render_validation_errors(@group) } end end end @@ -76,10 +72,10 @@ class GroupsController < ApplicationController if @group.save flash[:notice] = l(:notice_successful_update) format.html { redirect_to(groups_path) } - format.xml { head :ok } + format.api { head :ok } else format.html { render :action => "edit" } - format.xml { render :xml => @group.errors, :status => :unprocessable_entity } + format.api { render_validation_errors(@group) } end end end @@ -89,12 +85,12 @@ class GroupsController < ApplicationController respond_to do |format| format.html { redirect_to(groups_url) } - format.xml { head :ok } + format.api { head :ok } end end def add_users - users = User.find_all_by_id(params[:user_ids]) + users = User.find_all_by_id(params[:user_id] || params[:user_ids]) @group.users << users if request.post? respond_to do |format| format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } @@ -104,6 +100,7 @@ class GroupsController < ApplicationController users.each {|user| page.visual_effect(:highlight, "user-#{user.id}") } } } + format.api { head :ok } end end @@ -112,6 +109,7 @@ class GroupsController < ApplicationController respond_to do |format| format.html { redirect_to :controller => 'groups', :action => 'edit', :id => @group, :tab => 'users' } format.js { render(:update) {|page| page.replace_html "tab-content-users", :partial => 'groups/users'} } + format.api { head :ok } end end diff --git a/app/models/group.rb b/app/models/group.rb index a269c5c16..61266d97a 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -30,6 +30,7 @@ class Group < Principal before_destroy :remove_references_before_destroy safe_attributes 'name', + 'user_ids', 'custom_field_values', 'custom_fields', :if => lambda {|group, user| user.admin?} diff --git a/app/views/groups/index.api.rsb b/app/views/groups/index.api.rsb new file mode 100644 index 000000000..6a4efeaf7 --- /dev/null +++ b/app/views/groups/index.api.rsb @@ -0,0 +1,10 @@ +api.array :groups do + @groups.each do |group| + api.group do + api.id group.id + api.name group.lastname + + render_api_custom_values group.visible_custom_field_values, api + end + end +end diff --git a/app/views/groups/show.api.rsb b/app/views/groups/show.api.rsb new file mode 100644 index 000000000..764bdceda --- /dev/null +++ b/app/views/groups/show.api.rsb @@ -0,0 +1,30 @@ +api.group do + api.id @group.id + api.name @group.lastname + + render_api_custom_values @group.visible_custom_field_values, api + + api.array :users do + @group.users.each do |user| + api.user :id => user.id, :name => user.name + end + end + + api.array :memberships do + @group.memberships.each do |membership| + api.membership do + api.id membership.id + api.project :id => membership.project.id, :name => membership.project.name + api.array :roles do + membership.member_roles.each do |member_role| + if member_role.role + attrs = {:id => member_role.role.id, :name => member_role.role.name} + attrs.merge!(:inherited => true) if member_role.inherited_from.present? + api.role attrs + end + end + end + end if membership.project + end + end if include_in_api_response?('memberships') +end diff --git a/app/views/users/show.api.rsb b/app/views/users/show.api.rsb index b7d23ca97..ec7e5030f 100644 --- a/app/views/users/show.api.rsb +++ b/app/views/users/show.api.rsb @@ -9,6 +9,12 @@ api.user do render_api_custom_values @user.visible_custom_field_values, api + api.array :groups do |groups| + @user.groups.each do |group| + api.group :id => group.id, :name => group.name + end + end if User.current.admin? && include_in_api_response?('groups') + api.array :memberships do @memberships.each do |membership| api.membership do |