rosa-build/app/controllers/projects/collaborators_controller.rb

82 lines
1.8 KiB
Ruby
Raw Normal View History

2012-01-30 20:39:34 +00:00
# -*- encoding : utf-8 -*-
class Projects::CollaboratorsController < Projects::BaseController
respond_to :html, :json
2011-10-30 22:59:03 +00:00
before_filter :authenticate_user!
load_resource :project
before_filter :authorize_collaborators
2011-10-30 22:59:03 +00:00
before_filter :find_users
before_filter :find_groups
def index
@collaborators = Collaborator.find_by_project(@project)
respond_with @collaborators
2011-10-30 22:59:03 +00:00
end
def show
end
def new
end
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
@collaborators = (users | groups).map{|act| Collaborator.new(:actor => act, :project => @project)}
respond_with @collaborators do |format|
format.json { render 'index' }
end
2011-10-30 22:59:03 +00:00
end
def edit
2011-10-30 22:59:03 +00:00
end
def create
@collaborator = Collaborator.new(params[:collaborator])
@collaborator.project = @project
if @collaborator.save
respond_with @collaborator do |format|
format.json { render :partial => 'collaborator', :locals => {:collaborator => @collaborator} }
end
2011-10-30 22:59:03 +00:00
else
raise
2011-10-30 22:59:03 +00:00
end
end
def update
@c = Collaborator.find(params[:id])
if @c.update_attributes(params[:collaborator])
respond_with @c
2011-10-30 22:59:03 +00:00
else
raise
end
2011-10-30 22:59:03 +00:00
end
def destroy
@cb = Collaborator.find(params[:id])
@cb.destroy if @cb
respond_with @cb
end
2011-10-30 22:59:03 +00:00
protected
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
def find_groups
@groups = @project.groups.order('uname')#Group.all
@groups = @groups.without(@project.owner_id) if @project.owner_type == 'Group'
end
def authorize_collaborators
authorize! :update, @project
end
2011-10-30 22:59:03 +00:00
end