#472: Update Projects::CollaboratorsController

This commit is contained in:
Vokhmin Alexey V 2015-05-22 21:09:22 +03:00
parent b9e2f34239
commit c115c21e53
3 changed files with 16 additions and 5 deletions

View File

@ -24,7 +24,7 @@ class Projects::CollaboratorsController < Projects::BaseController
end end
def create def create
@collaborator = Collaborator.new(params[:collaborator]) @collaborator = Collaborator.new(collaborator_params)
@collaborator.project = @project @collaborator.project = @project
respond_to do |format| respond_to do |format|
if @collaborator.save if @collaborator.save
@ -62,6 +62,10 @@ class Projects::CollaboratorsController < Projects::BaseController
protected protected
def collaborator_params
subject_params(Collaborator)
end
def find_users def find_users
@users = @project.collaborators.order('uname')#User.all @users = @project.collaborators.order('uname')#User.all
@users = @users.without(@project.owner_id) if @project.owner_type == 'User' @users = @users.without(@project.owner_id) if @project.owner_type == 'User'

View File

@ -2,14 +2,11 @@ class Collaborator
include ActiveModel::Conversion include ActiveModel::Conversion
include ActiveModel::Validations include ActiveModel::Validations
include ActiveModel::Serializers::JSON include ActiveModel::Serializers::JSON
# include ActiveModel::MassAssignmentSecurity
extend ActiveModel::Naming extend ActiveModel::Naming
attr_accessor :role, :actor, :project, :relation attr_accessor :role, :actor, :project, :relation
attr_reader :id, :actor_id, :actor_type, :actor_name, :project_id attr_reader :id, :actor_id, :actor_type, :actor_name, :project_id
# attr_accessible :role
delegate :new_record?, to: :relation delegate :new_record?, to: :relation
class << self class << self
@ -56,7 +53,7 @@ class Collaborator
end end
def update_attributes(attributes, options = {}) def update_attributes(attributes, options = {})
sanitize_for_mass_assignment(attributes, options[:as]).each_pair do |k, v| attributes.each_pair do |k, v|
send("#{k}=", v) send("#{k}=", v)
end end
save save

View File

@ -0,0 +1,10 @@
class CollaboratorPolicy < ApplicationPolicy
# Public: Get list of parameters that the user is allowed to alter.
#
# Returns Array
def permitted_attributes
%i(role actor_id actor_type)
end
end