Skip to content

Instantly share code, notes, and snippets.

@chandeeland
Created September 24, 2018 16:09
Show Gist options
  • Save chandeeland/df02d855930dc9493b701104ab21d978 to your computer and use it in GitHub Desktop.
Save chandeeland/df02d855930dc9493b701104ab21d978 to your computer and use it in GitHub Desktop.

Rachel Rosen in CX will fill out this spreadsheet

https://docs.google.com/spreadsheets/d/1dbiMZwc7AnucdxR-KouxCZjx05D2xCnsR6VMVmEVtfk/edit#gid=1218567288

Run these commands In Geoffrey REPL

heroku -a ss-geoffrey-sbx rails c

create a location matching the location group from gandalf.

LOCATION_ID = "bson id from spreadsheet"
Location.where(LOCATION_ID).first_or_create!(mongo_location_id: LOCATION_ID)

note the location id, we will need it later.

run these commands in gandalf repl

heroku -run -a ss-gandalf-sbx rails c

cut and paste the contents of the oop.rb file containing the class OOP

prepare the parameters from the spreadsheet.

nomad_params = ['Brandibble (Direct Guest Platform)', 'Num Pang'] + %w[5626a569ada0cd000a000001 5626a575ada0cd000a000003 NoMad 5703efe850dc7d000a00002a 5ba14fde0e64d80065709c4d 5aeb8cf6541574003687cce8]

this array is created from the following columns in the spreadsheets

"SALIDO Integration Partner"	"SALIDO Customer Org Name"	Org ID	Brand ID	Location Name	Location ID	Location's Rev Center ID	"Online Ordering Employee ID (1 per org)"

you can then create an instance of OOP, and confirm the param settings.

oop = OOP.new(*nomad_params)
pp oop.config

once you are satisfied with the config, run the setup

oop.run
pp oop.output

copy the output back into the spreadsheet

note the password may be empty if the user is not newly created. That's okay it probably means the parter/org employee already exists.

verification step

pp oop.acl

If you are setting up non-production online ordering integrations, there is an extra platform step.

Run these commands in platform REPL

heroku -a ss-platform-sbx rails c

create day parts in advance

locs = Platform::Location.where(:id.in => [])
365.times do |d|
  day = d.days.from_now.beginning_of_day + 1.minute  
  locs.each { |l| l.business_day_for(day) }
end
class OOP < Struct.new(:partner, :org_name, :org_id, :brand_id, :loc_name, :loc_id, :rc_id, :emp_id)
def geoffrey_location_id=(value)
@geoffrey_location_id = value
end
OOPS = {
'Brandibble (Direct Guest Platform)' => ['Brandibble', 'brandibble.com'],
'Bite (Kiosks)' => ['Bite', 'bitekiosk.com'],
'Checkmate (Seamless/Grubhub)' => ['Checkmate', 'itsacheckmate.com'],
'LevelUp OLO' => ['LevelUp', 'thelevelup.com'],
}
def config
{
partner: partner,
org_name: org_name,
org_id: org_id,
brand_id: brand_id,
loc_name: loc_name,
loc_id: loc_id,
rc_id: rc_id,
emp_id: emp_id,
domain: domain,
oop_name: oop_name
}
end
def run
{
org: org,
brand: brand,
location: location,
client: client,
employee: user,
role: role,
position: position
}
end
def output
[
user.email,
@pass,
client.uid,
client.secret
]
end
def acl
user.groups.reload
AclCalculator.new(user: user, client: client).run.to_h
end
private
def geoffrey_location_id
@geoffrey_location_id || fail('missing geoffrey location id')
end
def oop_name
"#{OOPS.fetch(partner).first} OOP"
end
def domain
OOPS.fetch(partner).last
end
def gandalf
@gandalf ||= Group.find('00000000-0000-0000-0000-000000000000')
end
def org
@org ||= Organization
.where(platform_id: org_id)
.first_or_create!(
name: org_name,
platform_id: org_id,
owner: gandalf
)
end
def brand
@brand ||= Brand
.where(platform_id: brand_id)
.first_or_create!(
name: org_name,
owner: org,
platform_id: brand_id
)
end
def create_pass
@pass = SecureRandom.base64(20)
end
def user
@user ||= User
.where(platform_id: emp_id)
.first_or_create!(
password: create_pass,
email: "support@#{domain}",
first_name: oop_name,
last_name: 'OOP',
platform_id: emp_id
)
end
def client
@client ||= ClientApplication
.where(name: oop_name)
.first_or_create!(
name: oop_name,
redirect_uri: "https://#{domain}/salido"
).tap { |app|
app.privileges += Privilege.all
app.save!
}
end
def role
@role ||= Role.where(
name: "#{oop_name} OOP",
owner: brand
).first_or_create!(
name: "#{oop_name} OOP",
owner: brand
).tap { |r|
r.privileges += Privilege.all
r.save!
}
end
def location
@location ||= Location
.where(platform_id: loc_id)
.first_or_create!(
id: geoffrey_location_id,
name: loc_name,
owner: brand,
platform_id: loc_id
)
end
def position
@position ||= begin
name = "#{role.name} @ #{location.name}"
Position
.where(
owner: location,
name: name
)
.first_or_create!(
owner:location,
groups:[role, location],
name: name
).tap { |pos|
pos.members << user.group
}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment