Skip to content

Hide print cal #759

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions app/models/calEventValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ function makeValidator(input, errors) {
return ((input[field] ?? '') + '').trim();
}
return {
hasValue(field) {
return field in input;
},
requireString(field, msg) {
const str = getString(field);
if (validator.isEmpty(str)) {
Expand Down Expand Up @@ -206,17 +209,24 @@ function validateEvent(input) {
weburl: v.nullString('weburl'), // fix? validate this is a url>
webname: v.nullString('webname'),
audience: v.nullString('audience'),
tinytitle: v.mungeTinyTitle(title),
printdescr: v.nullString('printdescr'),
dates: v.nullString('datestring'), // string field 'dates' needed for legacy admin calendar
datestype: v.optionalChar('datestype', DatesType.OneDay),
area: v.optionalChar('area', Area.Portland),
printemail: v.optionalFlag('printemail'),
printphone: v.optionalFlag('printphone'),
printweburl: v.optionalFlag('printweburl'),
printcontact: v.optionalFlag('printcontact'),
safetyplan: v.optionalFlag('safetyplan'),
};
// print calendar data:
// if the tinytitle exists, assume the rest are valid too
// ( otherwise, we'll keep them however they were )
if (v.hasValue('tinytitle')) {
Object.assign(values, {
tinytitle: v.mungeTinyTitle(title),
printdescr: v.nullString('printdescr'),
printemail: v.optionalFlag('printemail'),
printphone: v.optionalFlag('printphone'),
printweburl: v.optionalFlag('printweburl'),
printcontact: v.optionalFlag('printcontact'),
});
};
const statusList = v.validateStatus(input.datestatuses);
return {
id: input.id,
Expand Down
16 changes: 8 additions & 8 deletions app/test/ical_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ String.raw`BEGIN:VEVENT`,
String.raw`UID:[email protected]`,
String.raw`SUMMARY:ride 2 title`,
String.raw`CONTACT:organizer`,
String.raw`DESCRIPTION:Quis ex cupidatat pariatur cillum pariatur esse id magna sit`,
String.raw` ipsum duis elit.\ntime details\nEnds at location\;`,
String.raw`DESCRIPTION:Quis ex cupidatat pariatur cillum pariatur esse id magna sit `,
String.raw` ipsum duis elit.\ntime details\nEnds at location\; `,
String.raw` end.\nhttp://localhost:3080/calendar/event-201`,
String.raw`LOCATION:location\, name.\n<address>\nlocation && details`,
String.raw`STATUS:CONFIRMED`,
Expand All @@ -176,8 +176,8 @@ String.raw`BEGIN:VEVENT`,
String.raw`UID:[email protected]`,
String.raw`SUMMARY:ride 2 title`,
String.raw`CONTACT:organizer`,
String.raw`DESCRIPTION:Quis ex cupidatat pariatur cillum pariatur esse id magna sit`,
String.raw` ipsum duis elit.\ntime details\nEnds at location\;`,
String.raw`DESCRIPTION:Quis ex cupidatat pariatur cillum pariatur esse id magna sit `,
String.raw` ipsum duis elit.\ntime details\nEnds at location\; `,
String.raw` end.\nhttp://localhost:3080/calendar/event-202`,
String.raw`LOCATION:location\, name.\n<address>\nlocation && details`,
String.raw`STATUS:CONFIRMED`,
Expand Down Expand Up @@ -219,8 +219,8 @@ String.raw`BEGIN:VEVENT`,
String.raw`UID:[email protected]`,
String.raw`SUMMARY:ride 2 title`,
String.raw`CONTACT:organizer`,
String.raw`DESCRIPTION:Quis ex cupidatat pariatur cillum pariatur esse id magna sit`,
String.raw` ipsum duis elit.\ntime details\nEnds at location\;`,
String.raw`DESCRIPTION:Quis ex cupidatat pariatur cillum pariatur esse id magna sit `,
String.raw` ipsum duis elit.\ntime details\nEnds at location\; `,
String.raw` end.\nhttp://localhost:3080/calendar/event-201`,
String.raw`LOCATION:location\, name.\n<address>\nlocation && details`,
String.raw`STATUS:CANCELLED`,
Expand All @@ -235,8 +235,8 @@ String.raw`BEGIN:VEVENT`,
String.raw`UID:[email protected]`,
String.raw`SUMMARY:ride 2 title`,
String.raw`CONTACT:organizer`,
String.raw`DESCRIPTION:Quis ex cupidatat pariatur cillum pariatur esse id magna sit`,
String.raw` ipsum duis elit.\ntime details\nEnds at location\;`,
String.raw`DESCRIPTION:Quis ex cupidatat pariatur cillum pariatur esse id magna sit `,
String.raw` ipsum duis elit.\ntime details\nEnds at location\; `,
String.raw` end.\nhttp://localhost:3080/calendar/event-202`,
String.raw`LOCATION:location\, name.\n<address>\nlocation && details`,
String.raw`STATUS:CONFIRMED`,
Expand Down
45 changes: 24 additions & 21 deletions app/test/manage_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
// x add / cancel dates from a published event
// x raw json ( curl ) vs body json ( forms )
// x multi-part form ( attach image )

const fsp = require('fs').promises;
const fs = require('fs');
const fsp = fs.promises;
const path = require('node:path');
const sinon = require('sinon');
const app = require("../app");
Expand Down Expand Up @@ -232,7 +232,7 @@ describe("managing events", () => {
function getImageTarget(id, imageSource) {
return path.join( config.image.dir, id + path.extname(imageSource) );
};
async function postImage(id, imageSource, imageTarget) {
function postImage(id, imageSource, imageTarget) {
// remove any image from earlier tests:
return fsp.rm(imageTarget, {force:true}).then(_ => {
// act as if we are a client who just created an event
Expand All @@ -251,32 +251,35 @@ describe("managing events", () => {
.field({
json: JSON.stringify(post)
})
.attach('file', imageSource, path.basename(imageSource));
// the tests originally based a filepath here
// but that started generating EPIPE errors for reasons.
.attach('file', fs.readFileSync(imageSource), path.basename(imageSource));
});
});
});
}
it("attaches an image", async function(){
it("attaches an image", function(){
const imageSource = path.join( config.image.dir, "bike.jpg" );
const imageTarget = getImageTarget(3, imageSource);
return postImage(3, imageSource, imageTarget).then(async function (res) {
return postImage(3, imageSource, imageTarget).then(function (res) {
expect(res).to.have.status(200);
//
const evt = await CalEvent.getByID(3);
// event creation is change 1,
// the image post is change 2,
// the event id is 3.
expect(evt.image, "image names should have a sequence number")
.to.equal("3-2.jpg");
//
const imageTarget = getImageTarget(3, imageSource);
return fsp.stat(imageTarget); // rejects if it doesn't exist on disk.
CalEvent.getByID(3).then(evt => {
// event creation is change 1,
// the image post is change 2,
// the event id is 3.
expect(evt.image, "image names should have a sequence number")
.to.equal("3-2.jpg");
//
const imageTarget = getImageTarget(3, imageSource);
return fsp.stat(imageTarget); // rejects if it doesn't exist on disk.
});
});
});
it("fails too large", async function(){
it("fails too large", function(){
const imageSource = path.join( config.image.dir, "bike-big.png" );
const imageTarget = getImageTarget(3, imageSource);
return postImage(3, imageSource, imageTarget).then(async function (res) {
return postImage(3, imageSource, imageTarget).then(function (res) {
testData.expectError(expect, res, 'image');
return fsp.stat(imageTarget)
.then(_ => {
Expand All @@ -287,10 +290,10 @@ describe("managing events", () => {
});
});
});
it("fails bad format", async function(){
it("fails bad format", function(){
const imageSource = path.join( config.image.dir, "bike-bad.tiff" );
const imageTarget = getImageTarget(3, imageSource);
return postImage(3, imageSource, imageTarget).then(async function (res) {
return postImage(3, imageSource, imageTarget).then(function (res) {
testData.expectError(expect, res, 'image');
return fsp.stat(imageTarget)
.then(_ => {
Expand All @@ -311,8 +314,8 @@ describe("managing events", () => {
.field({
json: JSON.stringify(eventData)
})
.attach('file', imageSource, path.basename(imageSource))
.then(function (res) {
.attach('file', fs.readFileSync(imageSource), path.basename(imageSource))
.then(async function (res) {
expect(res).to.have.status(400);
expect(res.body.error.fields).to.have.key('image');
});
Expand Down
5 changes: 5 additions & 0 deletions site/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ disableKinds = ["taxonomy", "term"]
logo = "images/shift-logo-large.jpg"
verificationURL = "https://pdx.social/@shift2bikes"

# Pedalpalooza specific config
[params.pedalp]
# can be enabled between March-June during Pedalpalooza when these fields are required
enablePrintCal = false

# Main page image carousel
[params.carousel]
enable = true
Expand Down
5 changes: 2 additions & 3 deletions site/themes/s2b_hugo_theme/layouts/partials/cal/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,7 @@ <h2>
</div>
</div>

<!-- Commented out here between March-June during Pedalpalooza season when these fields are required -->

{{ if .Site.Params.pedalp.enablePrintCal }}
<div class="panel panel-default">
<div class="panel-heading">
<h2>
Expand Down Expand Up @@ -438,7 +437,7 @@ <h2>
</div>
</div>
</div>

{{ end }}{{/* print cal */}}
<div class="panel panel-default">
<div class="panel-heading">
<h2>
Expand Down