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
EVENTS_BATCH_SIZE =
100
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:



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

def initialize
  @authorizations_to_add = []
  @affected_project_ids = Set.new
  @removed_user_ids = Set.new
  @added_user_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_remove_in_projectObject (readonly)

Returns the value of attribute users_to_remove_in_project.



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

def users_to_remove_in_project
  @users_to_remove_in_project
end

Instance Method Details

#add(authorizations_to_add) ⇒ Object



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

def add(authorizations_to_add)
  @authorizations_to_add += authorizations_to_add
end

#apply!Object



40
41
42
43
44
45
46
# File 'app/models/project_authorizations/changes.rb', line 40

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



36
37
38
# File 'app/models/project_authorizations/changes.rb', line 36

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



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

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