Class: ProjectAuthorizations::Changes

Inherits:
Object
  • Object
show all
Defined in:
app/models/project_authorizations/changes.rb

Overview

How to use this class authorizations_to_add: Rows to insert in the form ‘[{ user_id: user_id, project_id: project_id, access_level: access_level}, …]

ProjectAuthorizations::Changes.new do |changes|

changes.add(authorizations_to_add)
changes.remove_users_in_project(project, user_ids)
changes.remove_projects_for_user(user, project_ids)

end.apply!

Constant Summary collapse

BATCH_SIZE =
1000
SLEEP_DELAY =
0.1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Changes

Returns a new instance of Changes.

Yields:

  • (_self)

Yield Parameters:



19
20
21
22
23
# File 'app/models/project_authorizations/changes.rb', line 19

def initialize
  @authorizations_to_add = []
  @affected_project_ids = Set.new
  yield self
end

Instance Attribute Details

#authorizations_to_addObject (readonly)

Returns the value of attribute authorizations_to_add.



14
15
16
# File 'app/models/project_authorizations/changes.rb', line 14

def authorizations_to_add
  @authorizations_to_add
end

#projects_to_removeObject (readonly)

Returns the value of attribute projects_to_remove.



14
15
16
# File 'app/models/project_authorizations/changes.rb', line 14

def projects_to_remove
  @projects_to_remove
end

#users_to_removeObject (readonly)

Returns the value of attribute users_to_remove.



14
15
16
# File 'app/models/project_authorizations/changes.rb', line 14

def users_to_remove
  @users_to_remove
end

Instance Method Details

#add(authorizations_to_add) ⇒ Object



25
26
27
# File 'app/models/project_authorizations/changes.rb', line 25

def add(authorizations_to_add)
  @authorizations_to_add += authorizations_to_add
end

#apply!Object



37
38
39
40
41
42
43
# File 'app/models/project_authorizations/changes.rb', line 37

def apply!
  delete_authorizations_for_user if should_delete_authorizations_for_user?
  delete_authorizations_for_project if should_delete_authorizations_for_project?
  add_authorizations if should_add_authorization?

  publish_events
end

#remove_projects_for_user(user, project_ids) ⇒ Object



33
34
35
# File 'app/models/project_authorizations/changes.rb', line 33

def remove_projects_for_user(user, project_ids)
  @projects_to_remove = { project_ids: project_ids, scope: user }
end

#remove_users_in_project(project, user_ids) ⇒ Object



29
30
31
# File 'app/models/project_authorizations/changes.rb', line 29

def remove_users_in_project(project, user_ids)
  @users_to_remove = { user_ids: user_ids, scope: project }
end