2012-05-02 10:18:07 +01:00
|
|
|
class Projects::CollaboratorsController < Projects::BaseController
|
2012-04-09 18:11:39 +01:00
|
|
|
respond_to :html, :json
|
|
|
|
|
2011-10-30 22:59:03 +00:00
|
|
|
before_filter :authenticate_user!
|
2012-04-19 20:45:50 +01:00
|
|
|
load_resource :project
|
|
|
|
before_filter :authorize_collaborators
|
2011-10-30 22:59:03 +00:00
|
|
|
|
|
|
|
before_filter :find_users
|
|
|
|
before_filter :find_groups
|
|
|
|
|
2012-02-06 15:04:56 +00:00
|
|
|
def index
|
2012-04-09 18:11:39 +01:00
|
|
|
@collaborators = Collaborator.find_by_project(@project)
|
|
|
|
respond_with @collaborators
|
2011-10-30 22:59:03 +00:00
|
|
|
end
|
|
|
|
|
2012-04-12 22:44:53 +01:00
|
|
|
def find
|
|
|
|
users = User.not_member_of(@project)
|
|
|
|
groups = Group.not_member_of(@project)
|
|
|
|
if params[:term].present?
|
|
|
|
users = users.search(params[:term])
|
|
|
|
groups = groups.search(params[:term])
|
|
|
|
end
|
2014-01-21 04:51:49 +00:00
|
|
|
@collaborators = (users | groups).map{|act| Collaborator.new(actor: act, project: @project)}
|
2012-04-12 22:44:53 +01:00
|
|
|
respond_with @collaborators do |format|
|
|
|
|
format.json { render 'index' }
|
2011-11-24 21:46:19 +00:00
|
|
|
end
|
2011-10-30 22:59:03 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2012-04-12 22:44:53 +01:00
|
|
|
@collaborator = Collaborator.new(params[:collaborator])
|
|
|
|
@collaborator.project = @project
|
|
|
|
if @collaborator.save
|
|
|
|
respond_with @collaborator do |format|
|
2014-01-21 04:51:49 +00:00
|
|
|
format.json { render partial: 'collaborator', locals: {collaborator: @collaborator} }
|
2012-02-28 21:01:25 +00:00
|
|
|
end
|
2011-10-30 22:59:03 +00:00
|
|
|
else
|
2012-04-12 22:44:53 +01:00
|
|
|
raise
|
2011-10-30 22:59:03 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2012-04-12 22:44:53 +01:00
|
|
|
@c = Collaborator.find(params[:id])
|
|
|
|
if @c.update_attributes(params[:collaborator])
|
2012-04-09 18:11:39 +01:00
|
|
|
respond_with @c
|
2011-10-30 22:59:03 +00:00
|
|
|
else
|
2012-04-09 18:11:39 +01:00
|
|
|
raise
|
2012-02-28 21:01:25 +00:00
|
|
|
end
|
2011-10-30 22:59:03 +00:00
|
|
|
end
|
|
|
|
|
2012-04-09 18:11:39 +01:00
|
|
|
def destroy
|
2012-04-12 22:44:53 +01:00
|
|
|
@cb = Collaborator.find(params[:id])
|
2012-04-09 18:11:39 +01:00
|
|
|
@cb.destroy if @cb
|
|
|
|
respond_with @cb
|
2011-12-11 23:42:13 +00:00
|
|
|
end
|
|
|
|
|
2011-10-30 22:59:03 +00:00
|
|
|
protected
|
|
|
|
|
2012-04-19 20:45:50 +01:00
|
|
|
def find_users
|
|
|
|
@users = @project.collaborators.order('uname')#User.all
|
|
|
|
@users = @users.without(@project.owner_id) if @project.owner_type == 'User'
|
|
|
|
end
|
2011-10-30 22:59:03 +00:00
|
|
|
|
2012-04-19 20:45:50 +01:00
|
|
|
def find_groups
|
|
|
|
@groups = @project.groups.order('uname')#Group.all
|
|
|
|
@groups = @groups.without(@project.owner_id) if @project.owner_type == 'Group'
|
|
|
|
end
|
2012-02-06 15:04:56 +00:00
|
|
|
|
2012-04-19 20:45:50 +01:00
|
|
|
def authorize_collaborators
|
|
|
|
authorize! :update, @project
|
|
|
|
end
|
2011-10-30 22:59:03 +00:00
|
|
|
end
|