Permalink
Browse files

Merge pull request #1382 from leider/master

removal of startUnix and endUnix
  • Loading branch information...
NicoleRauch committed Dec 7, 2018
2 parents 29f50e7 + 17ab069 commit e36e6c75c93a75bf61526615612f5b172a1d0b6c
@@ -69,6 +69,11 @@ EOF
-- show all collection entries at once, without iterating:
db.collection.find().toArray()
-- finally delete the old *Unix fields in activities
db.activitystore.update({}, {$unset: {startUnix:"", endUnix:""}}, {multi:true})
-- enable pretty printing by default:
In
$HOME/.mongorc.js
@@ -19,11 +19,6 @@ class Activity {
this.state.resources = {};
this.state.resources[standardName] = {_registeredMembers: [], _registrationOpen: true};
}
const start = (this.state.startUnix && !isNaN(this.state.startUnix)) ? DateTime.fromMillis(this.state.startUnix * 1000) : DateTime.local();
this.state.startDate = start.set({milliseconds: 0, seconds: 0}).setZone(fieldHelpers.defaultTimezone()).toJSDate();
const end = (this.state.endUnix && !isNaN(this.state.endUnix)) ? DateTime.fromMillis(this.state.endUnix * 1000) : DateTime.local();
this.state.startDate = end.set({milliseconds: 0, seconds: 0}).setZone(fieldHelpers.defaultTimezone()).toJSDate();
}
id() {
@@ -54,14 +49,6 @@ class Activity {
return this.state.direction;
}
startUnix() {
return this.state.startUnix || Date.now() / 1000; // we have secinds persisted
}
endUnix() {
return this.state.endUnix || (Date.now() + 7200000) / 1000; // 2 hours and we have secinds persisted
}
assignedGroup() {
return this.state.assignedGroup;
}
@@ -93,14 +80,16 @@ class Activity {
this.state.location = object.location;
this.state.direction = object.direction;
// currently we only support MEZ/MESZ for events
this.state.startUnix = fieldHelpers.parseToUnixUsingDefaultTimezone(object.startDate, object.startTime);
this.state.endUnix = fieldHelpers.parseToUnixUsingDefaultTimezone(object.endDate, object.endTime);
const startDateTime = fieldHelpers.parseToDateTimeUsingDefaultTimezone(object.startDate, object.startTime);
this.state.startDate = startDateTime && startDateTime.toJSDate();
const endDateTime = fieldHelpers.parseToDateTimeUsingDefaultTimezone(object.endDate, object.endTime);
this.state.endDate = endDateTime && endDateTime.toJSDate();
this.state.clonedFromMeetup = object.clonedFromMeetup;
this.state.meetupRSVPCount = object.meetupRSVPCount;
if (!this.id() || this.id() === 'undefined') {
this.state.id = fieldHelpers.createLinkFrom([this.assignedGroup(), this.title(), new Date(this.state.startUnix * 1000).toLocaleString('de-DE', {timeZone: fieldHelpers.defaultTimezone()})]);
this.state.id = fieldHelpers.createLinkFrom([this.assignedGroup(), this.title(), this.startDateTime().toFormat('dd.MM.yyyy HH:mm:ss')]);
}
// these are the resource definitions in the edit page:
@@ -121,8 +110,8 @@ class Activity {
result.state.assignedGroup = this.assignedGroup();
result.state.location = this.location();
result.state.direction = this.direction();
result.state.startUnix = this.startUnix();
result.state.endUnix = this.endUnix();
result.state.startDate = this.state.startDate;
result.state.endDate = this.state.endDate;
result.state.resources = {};
result.resources().copyFrom(this.resources());
@@ -228,11 +217,11 @@ class Activity {
}
startDateTime() {
return DateTime.fromMillis(this.startUnix() * 1000).setZone(fieldHelpers.defaultTimezone());
return DateTime.fromJSDate(this.state.startDate).setZone(fieldHelpers.defaultTimezone());
}
endDateTime() {
return DateTime.fromMillis(this.endUnix() * 1000).setZone(fieldHelpers.defaultTimezone());
return DateTime.fromJSDate(this.state.endDate).setZone(fieldHelpers.defaultTimezone());
}
month() {
@@ -26,27 +26,27 @@ function toActivityList(callback, err, jsobjects) {
function allActivitiesByDateRange(rangeFrom, rangeTo, sortOrder, callback) {
persistence.listByField({
$and: [
{endUnix: {$gt: rangeFrom / 1000}},
{startUnix: {$lt: rangeTo / 1000}}
{endDate: {$gt: new Date(rangeFrom)}},
{startDate: {$lt: new Date(rangeTo)}}
]
}, sortOrder, R.partial(toActivityList, [callback]));
}
function allActivitiesByDateRangeInAscendingOrder(rangeFrom, rangeTo, callback) {
allActivitiesByDateRange(rangeFrom, rangeTo, {startUnix: 1}, callback);
allActivitiesByDateRange(rangeFrom, rangeTo, {startDate: 1}, callback);
}
function allActivitiesByDateRangeInDescendingOrder(rangeFrom, rangeTo, callback) {
allActivitiesByDateRange(rangeFrom, rangeTo, {startUnix: -1}, callback);
allActivitiesByDateRange(rangeFrom, rangeTo, {startDate: -1}, callback);
}
function flattenAndSortMongoResultCollection(collection) {
return R.sortBy(R.prop('startUnix'), R.flatten(collection[0].value));
return R.sortBy(R.prop('startDate'), R.flatten(collection[0].value));
}
module.exports = {
allActivities: function allActivities(callback) {
persistence.list({startUnix: 1}, R.partial(toActivityList, [callback]));
persistence.list({startDate: 1}, R.partial(toActivityList, [callback]));
},
allActivitiesByDateRangeInAscendingOrder,
@@ -83,25 +83,25 @@ module.exports = {
},
upcomingActivitiesForGroupIds: function upcomingActivitiesForGroupIds(groupIds, callback) {
const start = Date.now();
const start = new Date();
persistence.listByField({
$and: [
{endUnix: {$gt: start / 1000}},
{endDate: {$gt: start}},
{assignedGroup: {$in: groupIds}}
]
}, {startUnix: 1}, R.partial(toActivityList, [callback]));
}, {startDate: 1}, R.partial(toActivityList, [callback]));
},
pastActivitiesForGroupIds: function pastActivitiesForGroupIds(groupIds, callback) {
const start = Date.now();
const start = new Date();
persistence.listByField({
$and: [
{endUnix: {$lt: start / 1000}},
{endDate: {$lt: start}},
{assignedGroup: {$in: groupIds}}
]
}, {startUnix: -1}, R.partial(toActivityList, [callback]));
}, {startDate: -1}, R.partial(toActivityList, [callback]));
},
organizedOrEditedActivitiesForMemberId: function organizedOrEditedActivitiesForMemberId(memberId, callback) {
@@ -110,7 +110,7 @@ module.exports = {
{owner: memberId},
{editorIds: memberId} // matches when the field equals the value or when the field is an array that contains the value
]
}, {startUnix: -1}, R.partial(toActivityList, [callback]));
}, {startDate: -1}, R.partial(toActivityList, [callback]));
},
activitiesForGroupIdsAndRegisteredMemberId: function activitiesForGroupIdsAndRegisteredMemberId(groupIds, memberId, upcoming, callback) {
@@ -142,8 +142,8 @@ module.exports = {
return values;
}
const now = Date.now() / 1000;
const query = upcoming ? {endUnix: {$gt: now}} : {endUnix: {$lt: now}};
const now = new Date();
const query = upcoming ? {endDate: {$gt: now}} : {endDate: {$lt: now}};
const parameters = {out: {inline: 1}, scope: {memberId, groupIds}, query, jsMode: true};
persistence.mapReduce(map, reduce, parameters, (err, collection) => {
@@ -21,8 +21,8 @@ describe('Activity store', () => {
location: 'Right next door',
url: 'socrates-url',
isSoCraTes: true,
startUnix: fieldHelpers.parseToUnixUsingDefaultTimezone('01.02.2014'),
endUnix: fieldHelpers.parseToUnixUsingDefaultTimezone('15.02.2014'),
startDate: fieldHelpers.parseToDateTimeUsingDefaultTimezone('01.02.2014').toJSDate(),
endDate: fieldHelpers.parseToDateTimeUsingDefaultTimezone('15.02.2014').toJSDate(),
owner: {nickname: 'ownerNick'},
assignedGroup: 'assignedGroup',
group: {groupLongName: 'longName'}
@@ -194,18 +194,18 @@ describe('Activity store', () => {
value: [
[
[
{startUnix: 3}, {startUnix: 7}, {startUnix: 2}
{startDate: new Date(3)}, {startDate: new Date(7)}, {startDate: new Date(2)}
],
{startUnix: 1}, {startUnix: 6}, {startUnix: 5}
{startDate: new Date(1)}, {startDate: new Date(6)}, {startDate: new Date(5)}
],
{startUnix: 4}, {startUnix: 9}, {startUnix: 8}
{startDate: new Date(4)}, {startDate: new Date(9)}, {startDate: new Date(8)}
]
}];
const result = store.flattenAndSortMongoResultCollection(nestedMongoResult);
expect(result).to.eql([
{startUnix: 1}, {startUnix: 2}, {startUnix: 3},
{startUnix: 4}, {startUnix: 5}, {startUnix: 6},
{startUnix: 7}, {startUnix: 8}, {startUnix: 9}
{startDate: new Date(1)}, {startDate: new Date(2)}, {startDate: new Date(3)},
{startDate: new Date(4)}, {startDate: new Date(5)}, {startDate: new Date(6)},
{startDate: new Date(7)}, {startDate: new Date(8)}, {startDate: new Date(9)}
]);
});
@@ -58,7 +58,7 @@ const activityWithParticipants = new Activity({
assignedGroup: 'groupname',
location: 'location2',
direction: 'direction2',
startUnix: fieldHelpers.parseToUnixUsingDefaultTimezone('01.01.2013'),
startDate: fieldHelpers.parseToDateTimeUsingDefaultTimezone('01.01.2013').toJSDate(),
url: 'urlForInteresting',
resources: {
Veranstaltung: {
@@ -80,7 +80,7 @@ const activityWithEditors = new Activity({
assignedGroup: 'groupname5',
location: 'location5',
direction: 'direction5',
startUnix: fieldHelpers.parseToUnixUsingDefaultTimezone('01.01.2013'),
startDate: fieldHelpers.parseToDateTimeUsingDefaultTimezone('01.01.2013').toJSDate(),
url: 'urlForEditors',
owner: 'memberId4',
editorIds: ['memberId1', 'memberId3'],
@@ -169,7 +169,7 @@ describe('Activity application', () => {
it('shows the list of activities with "webcal:" link', done => {
emptyActivity.colorRGB = '#123456';
emptyActivity.group = group;
emptyActivity.state.startUnix = fieldHelpers.parseToUnixUsingDefaultTimezone('01.01.2013');
emptyActivity.state.startDate = fieldHelpers.parseToDateTimeUsingDefaultTimezone('01.01.2013').toJSDate();
request(createApp())
.get('/')
.expect(200)
@@ -185,7 +185,7 @@ describe('Activity application', () => {
it('shows the details of an activity without participants', done => {
emptyActivity.participants = [];
emptyActivity.state.startUnix = fieldHelpers.parseToUnixUsingDefaultTimezone('01.01.2013');
emptyActivity.state.startDate = fieldHelpers.parseToDateTimeUsingDefaultTimezone('01.01.2013').toJSDate();
emptyActivity.state.direction = 'direction1';
emptyActivity.state.location = 'location1';
emptyActivity.state.description = 'description1';
@@ -147,7 +147,7 @@ describe('Activity (when filled from UI)', () => {
startTime: '20:15'
});
expect(activity.id()).to.equal('My_Group_My_Title_1.2.2013__20_15_00');
expect(activity.id()).to.equal('My_Group_My_Title_01.02.2013_20_15_00');
});
it('with several resources where only one has open registration', () => {
@@ -2,7 +2,9 @@
const expect = require('must-dist');
const Activity = require('../../testutil/configureForTest').get('beans').get('activity');
const beans = require('../../testutil/configureForTest').get('beans');
const Activity = beans.get('activity');
const fieldHelpers = beans.get('fieldHelpers');
// TODO Activity.fillFromUI with null/undefined in startDate, startTime, endDate, endTime
@@ -64,11 +66,12 @@ describe('Activity', () => {
});
describe('blogEntryUrl', () => {
const nov20 = fieldHelpers.parseToDateTimeUsingDefaultTimezone('20.11.2017').toJSDate();
it('uses group id, date, and title to compose url', () => {
const activity = new Activity({
assignedGroup: 'mygroup',
title: 'my-activity',
startUnix: 1511132400 // 20.11.2017
startDate: nov20
});
expect(activity.blogEntryUrl()).to.equal('mygroup/blog_2017-11-20_my-activity');
@@ -79,7 +82,7 @@ describe('Activity', () => {
const activity = new Activity({
assignedGroup: 'mygroup',
title: 'Myactivity',
startUnix: 1511132400 // 20.11.2017
startDate: nov20
});
expect(activity.blogEntryUrl()).to.equal('mygroup/blog_2017-11-20_myactivity');
@@ -89,7 +92,7 @@ describe('Activity', () => {
const activity = new Activity({
assignedGroup: 'mygroup',
title: '74. my activityÄÖÜ',
startUnix: 1511132400 // 20.11.2017
startDate: nov20
});
expect(activity.blogEntryUrl()).to.equal('mygroup/blog_2017-11-20_74-my-activityaou');
@@ -15,8 +15,8 @@ describe('Calendar Service', () => {
const end = fieldHelpers.parseToDateTimeUsingDefaultTimezone('01.05.2013');
const activity = new Activity({
title: 'Title',
startUnix: fieldHelpers.parseToUnixUsingDefaultTimezone('04.04.2013'),
endUnix: fieldHelpers.parseToUnixUsingDefaultTimezone('05.04.2013'),
startDate: fieldHelpers.parseToDateTimeUsingDefaultTimezone('04.04.2013').toJSDate(),
endDate: fieldHelpers.parseToDateTimeUsingDefaultTimezone('05.04.2013').toJSDate(),
url: 'myURL'
});
@@ -27,7 +27,7 @@ describe('Administration application', () => {
const emptyActivity = new Activity({
title: 'Title of the Activity', description: 'description1', assignedGroup: 'groupname',
location: 'location1', direction: 'direction1', startUnix: fieldHelpers.parseToUnixUsingDefaultTimezone('01.01.2013'),
location: 'location1', direction: 'direction1', startDate: fieldHelpers.parseToDateTimeUsingDefaultTimezone('01.01.2013').toJSDate(),
url: 'urlOfTheActivity', owner: 'owner'
});
@@ -180,15 +180,15 @@ describe('Groups application', () => {
});
it('displays the group\'s upcoming activities', done => {
const date1 = fieldHelpers.parseToUnixUsingDefaultTimezone('01.01.2013');
const date2 = fieldHelpers.parseToUnixUsingDefaultTimezone('01.05.2013');
const date1 = fieldHelpers.parseToDateTimeUsingDefaultTimezone('01.01.2013').toJSDate();
const date2 = fieldHelpers.parseToDateTimeUsingDefaultTimezone('01.05.2013').toJSDate();
sinon.stub(activitystore, 'upcomingActivitiesForGroupIds').callsFake((list, callback) => callback(null, [new Activity({
title: 'Erste Aktivität',
startUnix: date1
startDate: date1
}), new Activity({
title: 'Zweite Aktivität',
startUnix: date2
startDate: date2
})]));
request(createApp())
@@ -37,7 +37,7 @@ describe('MailsenderService', () => {
assignedGroup: 'assignedGroup',
location: 'location1',
direction: 'direction1',
startUnix: fieldHelpers.parseToUnixUsingDefaultTimezone('01.01.2013'),
startDate: fieldHelpers.parseToDateTimeUsingDefaultTimezone('01.01.2013').toJSDate(),
url: 'urlOfTheActivity'
});
sinon.stub(groupsService, 'getAllAvailableGroups').callsFake(callback => { callback(null, availableGroups); });
@@ -65,22 +65,22 @@ describe('Accessrights for Activities', () => {
expect(standardMember({id: 'id'}).canEditActivity(activity)).to.be(false);
});
const nextWeek = (Date.now() + 604800000) / 1000; // + 1 week as seconds
const lastWeek = (Date.now() - 604800000) / 1000; // + 1 week as seconds
const nextWeek = new Date((Date.now() + 604800000)); // + 1 week
const lastWeek = new Date((Date.now() - 604800000)); // + 1 week
it('allows deletion of any activity for superusers', () => {
const activity = new Activity({owner: 'someOtherId', startUnix: lastWeek});
const activity = new Activity({owner: 'someOtherId', startDate: lastWeek});
expect(superuser().canDeleteActivity(activity)).to.be(true);
});
it('allows deletion of future activity for owner', () => {
const activity = new Activity({owner: 'someOtherId', startUnix: nextWeek});
const activity = new Activity({owner: 'someOtherId', startDate: nextWeek});
expect(standardMember({id: 'someOtherId'}).canDeleteActivity(activity)).to.be(true);
});
it('disallows deletion of past activity even for owner', () => {
const activity = new Activity({owner: 'someOtherId', startUnix: lastWeek});
const activity = new Activity({owner: 'someOtherId', startDate: lastWeek});
expect(standardMember({id: 'someOtherId'}).canDeleteActivity(activity)).to.be(false);
});
Oops, something went wrong.

0 comments on commit e36e6c7

Please sign in to comment.