mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-05-26 00:21:42 +08:00
Merge branch 'master' of github.com:Deployd/Deployd
This commit is contained in:
@@ -1,13 +1,9 @@
|
||||
var Model = require('../../model')
|
||||
, ObjectID = require('mongodb').BSONPure.ObjectID
|
||||
, exec = require('child_process').exec
|
||||
, _ = require('underscore')
|
||||
, mongodb = require('mongodb')
|
||||
;
|
||||
var Model = require('../../model');
|
||||
|
||||
module.exports = Model.spawn({
|
||||
|
||||
collection: 'apps',
|
||||
plugin: 'app',
|
||||
|
||||
description: {
|
||||
name: {type: 'string', unique: true},
|
||||
@@ -16,14 +12,18 @@ module.exports = Model.spawn({
|
||||
host: 'string'
|
||||
},
|
||||
|
||||
allowed: {
|
||||
read: 'creator',
|
||||
write: 'creator',
|
||||
remove: 'creator'
|
||||
},
|
||||
|
||||
save: function() {
|
||||
var name = this.get('name')
|
||||
, host = this.toHostName()
|
||||
, creator = this.get('creator')
|
||||
;
|
||||
|
||||
console.log(creator, 'creator');
|
||||
|
||||
if(!creator) this.error('Must be logged in to create an app.', 'App');
|
||||
|
||||
if(host && creator) {
|
||||
|
||||
@@ -6,10 +6,6 @@ if(process.argv.length < 3) {
|
||||
require('./balancer');
|
||||
}
|
||||
|
||||
app.get('/apps', function(req, res) {
|
||||
|
||||
});
|
||||
|
||||
app.post('/app', function(req, res) {
|
||||
var session = req.session
|
||||
, me = session && session.user && session.user.email
|
||||
@@ -17,6 +13,7 @@ app.post('/app', function(req, res) {
|
||||
|
||||
App
|
||||
.spawn()
|
||||
.for(req)
|
||||
.set({name: req.param('name'), creator: me})
|
||||
.notify(res)
|
||||
.save()
|
||||
@@ -26,6 +23,7 @@ app.post('/app', function(req, res) {
|
||||
app.get('/app/:id', function(req, res) {
|
||||
App
|
||||
.spawn()
|
||||
.for(req)
|
||||
.set({_id: req.param('id')})
|
||||
.notify(res)
|
||||
.fetch()
|
||||
@@ -35,6 +33,7 @@ app.get('/app/:id', function(req, res) {
|
||||
app.del('/app/:id', function(req, res) {
|
||||
App
|
||||
.spawn()
|
||||
.for(req)
|
||||
.notify(res)
|
||||
.remove()
|
||||
;
|
||||
|
||||
@@ -4,7 +4,7 @@ var app = require('../../app')
|
||||
|
||||
|
||||
app.all('/search/:type?', function(req, res) {
|
||||
var c = Collection.spawn()
|
||||
var c = Collection.spawn().for(req)
|
||||
, find = req.param('find')
|
||||
, select = req.param('select')
|
||||
, type = req.param('type')
|
||||
|
||||
@@ -16,25 +16,35 @@ app.post('/setting', function (req, res) {
|
||||
app.get('/settings', function(req, res) {
|
||||
Settings
|
||||
.spawn()
|
||||
.for(req)
|
||||
.notify(res)
|
||||
.fetch()
|
||||
;
|
||||
});
|
||||
|
||||
app.get('/settings/:type', function(req, res) {
|
||||
app.get('/settings/:name', function(req, res) {
|
||||
Setting
|
||||
.spawn()
|
||||
.find({type: req.param('type')})
|
||||
.for(req)
|
||||
.find({name: req.param('name')})
|
||||
.notify(res)
|
||||
.fetch()
|
||||
;
|
||||
});
|
||||
|
||||
var Model = require('../../model').spawn();
|
||||
Model.unlock();
|
||||
Model.collection = 'system.indexes';
|
||||
Model.notify(function(data) {
|
||||
config.indexes = data;
|
||||
|
||||
Setting
|
||||
.spawn()
|
||||
.find({name: 'app'})
|
||||
.set(config)
|
||||
.set({name: 'app'})
|
||||
.save()
|
||||
;
|
||||
}).fetch();
|
||||
|
||||
// create or update app settings
|
||||
Setting
|
||||
.spawn()
|
||||
.find({type: 'app'})
|
||||
.set(config)
|
||||
.set({type: 'app'})
|
||||
.save()
|
||||
;
|
||||
@@ -3,9 +3,11 @@ var Model = require('../../model');
|
||||
module.exports = Model.spawn({
|
||||
|
||||
collection: 'settings',
|
||||
plugin: 'setting',
|
||||
|
||||
description: {
|
||||
type: {type: 'string', unique: true},
|
||||
name: {type: 'string'},
|
||||
type: 'string',
|
||||
description: 'object'
|
||||
},
|
||||
|
||||
|
||||
@@ -3,9 +3,10 @@ var app = require('../../app')
|
||||
, Users = require('./users')
|
||||
;
|
||||
|
||||
function user(action, params, res) {
|
||||
function user(action, params, req, res) {
|
||||
User
|
||||
.spawn()
|
||||
.for(req)
|
||||
.set(params)
|
||||
.notify(res)
|
||||
[action]()
|
||||
@@ -13,11 +14,11 @@ function user(action, params, res) {
|
||||
}
|
||||
|
||||
app.post('/user', function(req, res) {
|
||||
user('save', req.body, res);
|
||||
user('save', req.body, req, res);
|
||||
});
|
||||
|
||||
app.post('/user/login', function(req, res) {
|
||||
user('login', req.body, {
|
||||
user('login', req.body, req, {
|
||||
send: function(u) {
|
||||
u.auth = req.sessionID;
|
||||
res.send(req.session.user = u);
|
||||
@@ -27,33 +28,25 @@ app.post('/user/login', function(req, res) {
|
||||
|
||||
app.get('/user/logout', function(req, res) {
|
||||
req.session.destroy(function() {
|
||||
res.send({auth: null})
|
||||
})
|
||||
res.send({auth: null});
|
||||
});
|
||||
});
|
||||
|
||||
app.get('/me', function(req, res) {
|
||||
user('fetch', {email: req.session.user.email}, res);
|
||||
user('fetch', {email: req.session.user && req.session.user.email}, req, res);
|
||||
});
|
||||
|
||||
app.del('/me', function(req, res) {
|
||||
var u = req.session.user;
|
||||
if(u) user('remove', u, res);
|
||||
if(u) user('remove', u, req, res);
|
||||
});
|
||||
|
||||
app.get('/user/:uid', function(req, res) {
|
||||
user('fetch', {email: req.param('uid')}, res);
|
||||
app.get('/user/:email', function(req, res) {
|
||||
user('fetch', {email: req.param('email')}, req, res);
|
||||
});
|
||||
|
||||
app.post('/user/:user/group', function(req, res) {
|
||||
var user = req.param('user');
|
||||
if(user) {
|
||||
User
|
||||
.spawn()
|
||||
.set({email: user, group: req.param('group')})
|
||||
.notify(res)
|
||||
.save()
|
||||
;
|
||||
}
|
||||
app.post('/user/:email/group', function(req, res) {
|
||||
user('save', {email: req.param('email'), group: req.param('group')}, req, res);
|
||||
});
|
||||
|
||||
app.get('/users', function(req, res) {
|
||||
@@ -61,7 +54,8 @@ app.get('/users', function(req, res) {
|
||||
.spawn({
|
||||
query: req.params
|
||||
})
|
||||
.for(req)
|
||||
.notify(res)
|
||||
.fetch()
|
||||
;
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,6 +7,8 @@ module.exports = Model.spawn({
|
||||
|
||||
collection: 'users',
|
||||
|
||||
plugin: 'user',
|
||||
|
||||
description: {
|
||||
email: {type: 'email', unique: true},
|
||||
password: 'password',
|
||||
@@ -16,14 +18,10 @@ module.exports = Model.spawn({
|
||||
group: 'string'
|
||||
},
|
||||
|
||||
toQuery: function() {
|
||||
var email = this.get('email')
|
||||
, q = {email: email}
|
||||
;
|
||||
|
||||
if(!email) this.error('You must include an email (User.email) to search for', 'Invalid Request');
|
||||
|
||||
return q;
|
||||
allowed: {
|
||||
read: 'creator',
|
||||
write: 'creator',
|
||||
remove: 'creator'
|
||||
},
|
||||
|
||||
toJSON: function() {
|
||||
|
||||
Reference in New Issue
Block a user