diff --git a/client/app/setup/setup.coffee b/client/app/setup/setup.coffee
index 9115e982..2959e6de 100644
--- a/client/app/setup/setup.coffee
+++ b/client/app/setup/setup.coffee
@@ -79,10 +79,14 @@ setupItems = [
name: 'externalServices'
async: no
onDone: (cb) ->
+ # well, this externalServices global shit stuff is a fucking mess.
+
schoolId = _(externalServices.get())
.map (s) -> s.profileData()?.schoolId
.find _.negate _.isUndefined
+ schoolId ?= getUserField Meteor.userId(), 'profile.schoolId'
+
done = (success) ->
if success?
addProgress 'externalServices', -> cb yes
@@ -193,26 +197,7 @@ setupItems = [
}
{
- # TODO: implement this, it should open a modal that asks
- # if the current schoolyear is over, if so we can ask the user to follow the setup
- # with stuff as `externalServices` and `externalClasses` again.
- name: 'newSchoolYear'
- func: ->
- return undefined
-
- alertModal(
- "Hey!",
- Locals["nl-NL"].NewSchoolYear(),
- DialogButtons.Ok,
- { main: "verder" },
- { main: "btn-primary" },
- { main: (->) },
- no
- )
- }
-
- {
- name: 'first-use'
+ name: 'final'
func: ->
addProgress 'first-use', ->
name = getUserField Meteor.userId(), 'profile.firstName'
@@ -231,10 +216,6 @@ running = undefined
setupProgress = getUserField Meteor.userId(), 'setupProgress'
return undefined unless setupProgress?
- setupProgress = setupProgress.concat [
- 'newSchoolYear' # TODO: Dunno how're going to do this shit
- ]
-
running = _.filter setupItems, (item) -> item.name not in setupProgress
if running.length > 0
diff --git a/lib/classes/course.coffee b/lib/classes/course.coffee
new file mode 100644
index 00000000..e1c0f6a0
--- /dev/null
+++ b/lib/classes/course.coffee
@@ -0,0 +1,63 @@
+###*
+# @class Course
+# @constructor
+# @param {Date} from
+# @param {Date} to
+# @param {String} profile
+# @param {String} userId
+###
+class @Course
+ constructor: (@from, @to, @profile, @userId) ->
+ ###*
+ # @property typeId
+ # @type Number|undefined
+ # @default undefined
+ ###
+ @typeId = undefined
+
+ ###*
+ # @property externalId
+ # @type mixed
+ # @default undefined
+ ###
+ @externalId = undefined
+
+ ###*
+ # @property fetchedBy
+ # @type String|undefined
+ # @default undefined
+ ###
+ @fetchedBy = undefined
+
+ ###*
+ # @property lastUpdated
+ # @type Date|undefined
+ # @default undefined
+ ###
+ @lastUpdated = undefined
+
+ ###*
+ # @method inside
+ # @param {Date} date
+ # @return {Boolean}
+ ###
+ inside: (date) -> @from <= date <= @to
+
+ @schema: new SimpleSchema
+ from:
+ type: Date
+ to:
+ type: Date
+ profile:
+ type: String
+ userId:
+ type: String
+ typeId:
+ type: null
+ optional: yes
+ externalId:
+ type: null
+ optional: yes
+ fetchedBy:
+ type: String
+ optional: yes
diff --git a/packages/external-services-connector/server/functions.coffee b/packages/external-services-connector/server/functions.coffee
index 16789de8..99d2b29f 100644
--- a/packages/external-services-connector/server/functions.coffee
+++ b/packages/external-services-connector/server/functions.coffee
@@ -48,3 +48,4 @@ export * from './functions/studyUtils.coffee'
export * from './functions/messages.coffee'
export * from './functions/profileData.coffee'
export * from './functions/serviceUpdates.coffee'
+export * from './functions/courses.coffee'
diff --git a/packages/external-services-connector/server/functions/courses.coffee b/packages/external-services-connector/server/functions/courses.coffee
new file mode 100644
index 00000000..2a524733
--- /dev/null
+++ b/packages/external-services-connector/server/functions/courses.coffee
@@ -0,0 +1,19 @@
+import { Services, ExternalServicesConnector } from '../connector.coffee'
+
+###*
+# @method getCourses
+# @param {String} userId
+# @return {Course[]}
+###
+export getCourses = (userId) ->
+ check userId, String
+ res = []
+
+ services = _.filter Services, (s) -> s.getCourses? and s.active userId
+ for service in services
+ try
+ res = res.concat service.getCourses userId
+ catch e
+ ExternalServicesConnector.handleServiceError service.name, userId, e
+
+ res
diff --git a/packages/magister-binding/magister-binding.js b/packages/magister-binding/magister-binding.js
index d2607987..77667cf5 100644
--- a/packages/magister-binding/magister-binding.js
+++ b/packages/magister-binding/magister-binding.js
@@ -1,6 +1,6 @@
/* global AbsenceInfo, Schools, Grade, StudyUtil, GradePeriod,
ExternalPerson, CalendarItem, Assignment, ExternalFile, getClassInfos,
- Message, ms, MagisterBinding, ServiceUpdate */
+ Message, ms, MagisterBinding, ServiceUpdate, Course */
// One heck of a binding this is.
@@ -249,6 +249,30 @@ function getCurrentCourse (magister) {
return fut.wait();
}
+/**
+ * @method getCourses
+ * @param {String} userId
+ * @return {Course}
+ */
+MagisterBinding.getCourses = function (userId) {
+ check(userId, String);
+ const magister = getMagisterObject(userId);
+ const courses = Meteor.wrapAsync(magister.courses, magister)();
+
+ return courses.map(function (c) {
+ const course = new Course(c.begin(), c.end(), c.profile(), userId);
+
+ course.profile = c.profile();
+ course.typeId = c.type().id;
+ course.externalId = prefixId(magister, c.id());
+ course.fetchedBy = MagisterBinding.name;
+
+ course.lastUpdated = new Date();
+
+ return course;
+ });
+};
+
/**
* Get the grades for the given userId from Magister.
* @method getGrades
diff --git a/server/cronJobs.coffee b/server/cronJobs.coffee
index a9be18ca..d790d856 100644
--- a/server/cronJobs.coffee
+++ b/server/cronJobs.coffee
@@ -180,3 +180,47 @@ SyncedCron.add
Date.today()
Date.today().addDays 14
)
+
+SyncedCron.add
+ name: 'Handle new schoolyears'
+ schedule: (parser) -> parser.recur().on(4).hour()
+ job: ->
+ userIds = Meteor.users.find({
+ 'profile.firstName': $ne: ''
+ }, {
+ fields:
+ _id: 1
+ 'profile.firstName': 1
+ emails: 1
+ }).map (u) -> u._id
+
+ for userId in userIds
+ courses = functions.getCourses userId
+ current = _.find courses, (c) -> c.inside new Date
+ next = _.find courses, (c) -> c.from > new Date
+
+ if current? and Date.today().addDays(-1) < current.start
+ ###
+ loginUrl = 'https://app.simplyHomework.nl/login'
+ sendMail user, 'Nieuw schooljaar', """
+ Hey #{user.profile.firstName}!
+
+ Zo te zien is het nieuwe schooljaar zojuist voor je begonnen.
+ We hopen dat simplyHomework je dit jaar weer kan helpen met school! :)
+
+ Je moet wel even eerst de setup doorlopen (ongeveer 2 minuten) op:
#{loginurl}
+
+ Success dit schooljaar!
+ """
+ ###
+ Meteor.users.update(
+ userId
+ $pullAll: setupProgress: [
+ 'externalServices'
+ 'extractInfo'
+ 'getExternalClasses'
+ ]
+ )
+
+ # REVIEW: do we want to send a message here? If so, what?
+ # else unless next?