Skip to content

Commit

Permalink
Merge branch 'master' into go-signal
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewbenington committed Oct 6, 2023
2 parents 79c160a + 625d5e7 commit 8ccc94d
Show file tree
Hide file tree
Showing 45 changed files with 2,516 additions and 626 deletions.
5 changes: 5 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
defaultSemverRangePrefix: ''

yarnPath: .yarn/releases/yarn-3.6.3.cjs

packageExtensions:
'markdown-it@*':
dependencies:
'punycode': '2.3.0'
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ goalert-client.key: system.ca.pem plugin.ca.key plugin.ca.pem
goalert-client.ca.pem: system.ca.pem plugin.ca.key plugin.ca.pem
go run ./cmd/goalert gen-cert client

cypress: bin/goalert.cover bin/psql-lite bin/pgmocktime $(NODE_DEPS) web/src/schema.d.ts
cypress: bin/goalert.cover bin/psql-lite bin/pgmocktime $(NODE_DEPS) web/src/schema.d.ts $(BIN_DIR)/build/integration/cypress/plugins/index.js
$(MAKE) ensure-yarn
yarn cypress install

Expand Down
5 changes: 1 addition & 4 deletions Makefile.binaries.mk
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ ifeq ($(PUSH),1)
podman manifest push --all $(IMAGE_REPO)/goalert:$(IMAGE_TAG) docker://$(IMAGE_REPO)/goalert:$(IMAGE_TAG)
endif

$(BIN_DIR)/build/integration/cypress.json: web/src/cypress.json
cp web/src/cypress.json $@

$(BIN_DIR)/build/integration/cypress: node_modules $(BIN_DIR)/build/integration/cypress.json web/src/esbuild.cypress.js $(shell find ./web/src/cypress)
$(BIN_DIR)/build/integration/cypress/plugins/index.js: package.json yarn.lock web/src/esbuild.cypress.js $(shell find ./web/src/cypress)
rm -rf $@
yarn run esbuild-cy
mkdir -p $@/plugins
Expand Down
1 change: 1 addition & 0 deletions app/initsmtpsrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func (app *App) initSMTPServer(ctx context.Context) error {
TLSConfig: app.cfg.TLSConfigSMTP,
MaxRecipients: app.cfg.SMTPMaxRecipients,
BackgroundContext: app.LogBackgroundContext,
Logger: app.cfg.Logger,
AuthorizeFunc: func(ctx context.Context, id string) (context.Context, error) {
tok, _, err := authtoken.Parse(id, nil)
if err != nil {
Expand Down
49 changes: 39 additions & 10 deletions calsub/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,58 @@ func (s *Store) ServeICalData(w http.ResponseWriter, req *http.Request) {
return
}

// filter out other users
filtered := shifts[:0]
for _, s := range shifts {
if s.UserID != info.UserID.String() {
continue
}
filtered = append(filtered, s)
}

var subCfg SubscriptionConfig
err = json.Unmarshal(info.Config, &subCfg)
if errutil.HTTPError(ctx, w, err) {
return
}

if !subCfg.FullSchedule {
// filter out other users
filtered := shifts[:0]
for _, s := range shifts {
if s.UserID != info.UserID.String() {
continue
}
filtered = append(filtered, s)
}
shifts = filtered
}

data := renderData{
ApplicationName: cfg.ApplicationName(),
ScheduleID: info.ScheduleID,
ScheduleName: info.ScheduleName,
Shifts: filtered,
Shifts: shifts,
ReminderMinutes: subCfg.ReminderMinutes,
Version: version.GitVersion(),
GeneratedAt: info.Now,
FullSchedule: subCfg.FullSchedule,
}

if subCfg.FullSchedule {
// When rendering the full schedule, we need to fetch the names of all users.
data.UserNames = make(map[string]string)
var uniqueIDs []uuid.UUID
for _, s := range shifts {

// We'll use the map to track which IDs we've already seen.
// That way we don't ask the DB for the same user multiple times.
if _, ok := data.UserNames[s.UserID]; ok {
continue
}
data.UserNames[s.UserID] = "Unknown User"
uniqueIDs = append(uniqueIDs, uuid.MustParse(s.UserID))
}

users, err := gadb.New(s.db).CalSubUserNames(ctx, uniqueIDs)
if errutil.HTTPError(ctx, w, err) {
return
}

for _, u := range users {
data.UserNames[u.ID.String()] = u.Name
}
}

calData, err := data.renderICal()
Expand Down
79 changes: 51 additions & 28 deletions calsub/queries.sql
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
-- name: FindOneCalSub :one
SELECT id,
SELECT
id,
NAME,
user_id,
disabled,
schedule_id,
config,
last_access
FROM user_calendar_subscriptions
WHERE id = $1;
FROM
user_calendar_subscriptions
WHERE
id = $1;

-- name: CalSubUserNames :many
SELECT
id,
name
FROM
users
WHERE
id = ANY ($1::uuid[]);

-- name: CalSubRenderInfo :one
SELECT
Expand All @@ -23,59 +35,70 @@ WHERE
sub.id = $1;

-- name: FindOneCalSubForUpdate :one
SELECT id,
SELECT
id,
NAME,
user_id,
disabled,
schedule_id,
config,
last_access
FROM user_calendar_subscriptions
WHERE id = $1 FOR
UPDATE;
FROM
user_calendar_subscriptions
WHERE
id = $1
FOR UPDATE;

-- name: FindManyCalSubByUser :many
SELECT id,
SELECT
id,
NAME,
user_id,
disabled,
schedule_id,
config,
last_access
FROM user_calendar_subscriptions
WHERE user_id = $1;
FROM
user_calendar_subscriptions
WHERE
user_id = $1;

-- name: DeleteManyCalSub :exec
DELETE FROM user_calendar_subscriptions
WHERE id = ANY($1::uuid [ ])
WHERE id = ANY ($1::uuid[])
AND user_id = $2;

-- name: CreateCalSub :one
INSERT INTO user_calendar_subscriptions (
id,
NAME,
user_id,
disabled,
schedule_id,
config
)
VALUES ($1, $2, $3, $4, $5, $6) RETURNING created_at;
INSERT INTO user_calendar_subscriptions(id, NAME, user_id, disabled, schedule_id, config)
VALUES ($1, $2, $3, $4, $5, $6)
RETURNING
created_at;

-- name: Now :one
SELECT now()::timestamptz;
SELECT
now()::timestamptz;

-- name: CalSubAuthUser :one
UPDATE user_calendar_subscriptions
SET last_access = now()
WHERE NOT disabled
UPDATE
user_calendar_subscriptions
SET
last_access = now()
WHERE
NOT disabled
AND id = $1
AND date_trunc('second', created_at) = $2 RETURNING user_id;
AND date_trunc('second', created_at) = $2
RETURNING
user_id;

-- name: UpdateCalSub :exec
UPDATE user_calendar_subscriptions
SET NAME = $1,
UPDATE
user_calendar_subscriptions
SET
NAME = $1,
disabled = $2,
config = $3,
last_update = now()
WHERE id = $4
WHERE
id = $4
AND user_id = $5;

2 changes: 2 additions & 0 deletions calsub/renderdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ type renderData struct {
ReminderMinutes []int
Version string
GeneratedAt time.Time
FullSchedule bool
UserNames map[string]string
}
2 changes: 1 addition & 1 deletion calsub/renderical.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ METHOD:PUBLISH
{{- range $i, $s := .Shifts}}
BEGIN:VEVENT
UID:{{index $eventUIDs $i}}
SUMMARY:On-Call ({{$.ApplicationName}}: {{$.ScheduleName}}){{if $s.Truncated}} Begins*
SUMMARY:{{if $.FullSchedule}}{{index $.UserNames $s.UserID}} {{end}}On-Call ({{$.ApplicationName}}: {{$.ScheduleName}}){{if $s.Truncated}} Begins*
DESCRIPTION:The end time of this shift is unknown and will continue beyond what is displayed.
{{- end }}
DTSTAMP:{{$genTime.UTC.Format "20060102T150405Z"}}
Expand Down
1 change: 1 addition & 0 deletions calsub/subscriptionconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
// SubscriptionConfig is the configuration for a calendar subscription.
type SubscriptionConfig struct {
ReminderMinutes []int
FullSchedule bool
}

var (
Expand Down
6 changes: 3 additions & 3 deletions cypress.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const { defineConfig } = require('cypress')
const setupNodeEvents = require('./web/src/cypress/plugins/index')

module.exports = defineConfig({
videoUploadOnPasses: false,
waitForAnimations: false,
viewportWidth: 1440,
viewportHeight: 900,
requestTimeout: 15000,
defaultCommandTimeout: 15000,
numTestsKeptInMemory: 1,
video: false,

retries: {
Expand All @@ -23,8 +23,8 @@ module.exports = defineConfig({
setupNodeEvents,
baseUrl: 'http://localhost:3030',
excludeSpecPattern: '*.map',
supportFile: 'web/src/cypress/support/e2e.ts',
specPattern: 'web/src/cypress/e2e/*.cy.{js,ts}',
supportFile: 'bin/build/integration/cypress/support/index.js',
specPattern: 'bin/build/integration/cypress/integration/*.cy.js',
},

component: {
Expand Down
2 changes: 1 addition & 1 deletion devtools/ci/dockerfiles/cypress-env/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker.io/cypress/included:12.16.0
FROM docker.io/cypress/included:13.3.0
ENTRYPOINT []
RUN apt-get update && apt-get install -y --no-install-recommends postgresql postgresql-contrib && rm -rf /var/lib/apt/lists/*
ENV PGDATA=/var/lib/postgresql/data PGUSER=postgres DB_URL=postgresql://postgres@
Expand Down
2 changes: 1 addition & 1 deletion devtools/ci/tasks/test-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ outputs:
- name: debug
image_resource:
type: registry-image
source: { repository: goalert/cypress-env, tag: '12.16.0' }
source: { repository: goalert/cypress-env, tag: '13.3.0' }
run:
path: sh
dir: integration/goalert
Expand Down
5 changes: 1 addition & 4 deletions devtools/genmake/template.mk
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ ifeq ($(PUSH),1)
podman manifest push --all $(IMAGE_REPO)/goalert:$(IMAGE_TAG) docker://$(IMAGE_REPO)/goalert:$(IMAGE_TAG)
endif

$(BIN_DIR)/build/integration/cypress.json: web/src/cypress.json
cp web/src/cypress.json $@

$(BIN_DIR)/build/integration/cypress: node_modules $(BIN_DIR)/build/integration/cypress.json web/src/esbuild.cypress.js $(shell find ./web/src/cypress)
$(BIN_DIR)/build/integration/cypress/plugins/index.js: package.json yarn.lock web/src/esbuild.cypress.js $(shell find ./web/src/cypress)
rm -rf $@
yarn run esbuild-cy
mkdir -p $@/plugins
Expand Down
8 changes: 4 additions & 4 deletions devtools/mocktwilio/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"path"
"strconv"

"github.com/nyaruka/phonenumbers"
"github.com/target/goalert/notification/twilio"
"github.com/ttacon/libphonenumber"
)

func (s *Server) serveLookup(w http.ResponseWriter, req *http.Request) {
Expand All @@ -23,14 +23,14 @@ func (s *Server) serveLookup(w http.ResponseWriter, req *http.Request) {
AddOns *struct{} `json:"add_ons"`
URL string `json:"url"`
}
n, err := libphonenumber.Parse(number, "")
n, err := phonenumbers.Parse(number, "")
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
info.CC = strconv.Itoa(int(n.GetCountryCode()))
info.Fmt = libphonenumber.Format(n, libphonenumber.NATIONAL)
info.Number = libphonenumber.Format(n, libphonenumber.E164)
info.Fmt = phonenumbers.Format(n, phonenumbers.NATIONAL)
info.Number = phonenumbers.Format(n, phonenumbers.E164)
req.URL.Host = req.Host
info.URL = req.URL.String()

Expand Down
Loading

0 comments on commit 8ccc94d

Please sign in to comment.