Browse Source

working exmpale

sou 7 years ago
parent
commit
157093343b
3 changed files with 42 additions and 8 deletions
  1. 17 7
      lib/models/global-notification-setting.js
  2. 24 0
      lib/routes/admin.js
  3. 1 1
      lib/routes/index.js

+ 17 - 7
lib/models/global-notification-setting.js

@@ -5,12 +5,13 @@ const Notification = this;
 /*
  * define schema
  */
-const notificationSchema = new mongoose.Schema({
-  isEnabled: { type: Boolean, required: true, default: true },
-  triggerPath: { type: String, required: true },
-  triggerEvents: { type: [String] },
-  notifyTo: { type: String, default: '{}',
-    get: data => {
+
+const notifyToSchema = new mongoose.Schema({
+  type: { type: String, required: true },
+  extended: {
+    type: String,
+    default: '{}',
+    get: function(data) {
       try {
         return JSON.parse(data);
       }
@@ -18,10 +19,19 @@ const notificationSchema = new mongoose.Schema({
         return data;
       }
     },
-    set: data => JSON.stringify(data)
+    set: function(data) {
+      return JSON.stringify(data);
+    }
   },
 });
 
+const notificationSchema = new mongoose.Schema({
+  isEnabled: { type: Boolean, required: true, default: true },
+  triggerPath: { type: String, required: true },
+  triggerEvents: { type: [String] },
+  notifyTo: notifyToSchema
+});
+
 /**
  * GlobalNotificationSetting Class
  * @class GlobalNotificationSetting

+ 24 - 0
lib/routes/admin.js

@@ -5,6 +5,7 @@ module.exports = function(crowi, app) {
     , fs = require('fs')
     , models = crowi.models
     , Page = models.Page
+    , GlobalNotification = models.GlobalNotification
     , PageGroupRelation = models.PageGroupRelation
     , User = models.User
     , ExternalAccount = models.ExternalAccount
@@ -1130,6 +1131,29 @@ module.exports = function(crowi, app) {
     }, callback);
   }
 
+  //DELETEME
+  actions.test = (req, res) => {
+    let notif = new GlobalNotification();
+    notif.isEnabled = true;
+    notif.triggerPath = '/*',
+    notif.triggerEvents = 'comment, pageCreate';
+    notif.notifyTo = {
+      type: 'mail',
+      extended: {
+        toEmail: 'email here',
+      }
+    };
+
+    notif.save(function(err, notif) {
+      if(err) {
+        console.log(err);
+        return;
+      }
+      console.log(notif);
+      return res.json(ApiResponse.success());
+    });
+  };
+
 
   return actions;
 };

+ 1 - 1
lib/routes/index.js

@@ -79,7 +79,7 @@ module.exports = function(crowi, app) {
   app.get('/admin/markdown'                   , loginRequired(crowi, app) , middleware.adminRequired() , admin.markdown.index);
   app.post('/admin/markdown/lineBreaksSetting', loginRequired(crowi, app) , middleware.adminRequired() , csrf, form.admin.markdown, admin.markdown.lineBreaksSetting); //change form name
   app.post('/admin/markdown/xss-setting'       , loginRequired(crowi, app) , middleware.adminRequired() , csrf, form.admin.markdownXss, admin.markdown.xssSetting);
-
+  app.get('/admin/test'               , loginRequired(crowi, app, false) , admin.test); //DELETEME
   // markdown admin
   app.get('/admin/customize'                , loginRequired(crowi, app) , middleware.adminRequired() , admin.customize.index);
   app.post('/_api/admin/customize/css'      , loginRequired(crowi, app) , middleware.adminRequired() , csrf, form.admin.customcss, admin.api.customizeSetting);