Permalink
Browse files

fixed merge conflict

  • Loading branch information...
2 parents b9dbb9e + ca0296f commit ea0fa941f3a55df5c43cd1207d5372366e8fe24f @remy remy committed Apr 9, 2013
Showing with 65 additions and 11 deletions.
  1. +13 −0 lib/db/mysql.js
  2. +2 −1 lib/db/sql_templates.json
  3. +20 −1 lib/db/sqlite.js
  4. +18 −5 lib/handlers/bin.js
  5. +8 −0 lib/models/user.js
  6. +1 −1 lib/store.js
  7. +2 −2 public/js/editors/libraries.js
  8. +1 −1 public/js/render/console.js
View
@@ -392,5 +392,18 @@ module.exports = utils.inherit(Object, {
}
fn(null);
});
+ },
+ isOwnerOf: function (params, fn) {
+ var values = [
+ params.name,
+ params.url
+ ], sql = templates.isOwnerOf;
+
+ this.connection.query(sql, values, function (err, result) {
+ if (err) {
+ return fn(err);
+ }
+ fn(null, { found: !!result.length, isowner: result.length ? result[0].owner === 1 : false });
+ });
}
});
@@ -26,5 +26,6 @@
"getUserForForgotToken": "SELECT `ownership`.*, expires FROM `ownership` INNER JOIN `forgot_tokens` ON `name` = `owner_name` WHERE `token` = ? AND `forgot_tokens`.`expires` >= ?",
"setForgotToken": "INSERT INTO `forgot_tokens` (`owner_name`, `token`, `expires`, `created`) VALUES (?, ?, ?, ?)",
"deleteExpiredForgotToken": "DELETE FROM `forgot_tokens` WHERE `expires` <= ? OR `token`=? OR `owner_name`=?",
- "reportBin": "UPDATE `sandbox` SET `reported`=? WHERE `url`=? AND `revision`=? AND `active`='y'"
+ "reportBin": "UPDATE `sandbox` SET `reported`=? WHERE `url`=? AND `revision`=? AND `active`='y'",
+ "isOwnerOf": "SELECT name=? as `owner` FROM `owners` WHERE `url`=? AND `revision`=1"
}
View
@@ -209,7 +209,7 @@ module.exports = utils.inherit(Object, {
if (result) {
result = _this.convertUserDates(result);
}
- fn(null, result);
+ fn(null, result);
}
});
},
@@ -450,5 +450,24 @@ module.exports = utils.inherit(Object, {
}
fn(null, results);
});
+ },
+ isOwnerOf: function (params, fn) {
+ var values = [
+ params.name || '',
+ params.url
+ ], sql = templates.isOwnerOf;
+
+ // note: .get gets one row
+ this.connection.get(sql, values, function (err, result) {
+ if (err) {
+ return fn(err);
+ }
+ if (typeof result === 'undefined') {
+ return fn(null, { found: false });
+ } else {
+ return fn(null, { found: true, isowner: result.owner === 1 });
+ }
+ });
}
+
});
View
@@ -243,20 +243,33 @@ module.exports = Observable.extend({
if (req.param('method') === 'save') {
params = utils.extract(req.body, 'html', 'css', 'javascript', 'settings');
params.url = req.bin.url;
- params.revision = req.bin.revision + 1;
+ params.revision = parseInt(req.params.rev, 10) || 1, //req.bin.revision;
params.summary = utils.titleForBin(params);
this.validateBin(params, function (err) {
if (err) {
return next(err);
}
- _this.models.bin.createRevision(params, function (err, result) {
- if (err) {
- return next(err);
+ var username = req.session.user ? req.session.user.name : undefined;
+
+ _this.models.user.isOwnerOf(username, params, function (err, result) {
+ var method = 'create';
+
+ if (result.isowner || result.found === false) {
+ method = 'createRevision';
+ params.revision = req.bin.revision + 1; // bump the revision from the *latest*
+ } else {
+ delete params.revision;
}
- _this.completeCreateBin(result, req, res, next);
+ _this.models.bin[method](params, function (err, result) {
+ if (err) {
+ return next(err);
+ }
+
+ _this.completeCreateBin(result, req, res, next);
+ });
});
});
} else if (req.param('method') === 'update') {
View
@@ -67,6 +67,14 @@ module.exports = Observable.extend({
};
this.store.getBinsByUser(id, fn);
},
+ isOwnerOf: function (username, bin, fn) {
+ var params = {
+ name: username,
+ url: bin.url,
+ revision: bin.revision
+ };
+ this.store.isOwnerOf(params, fn);
+ },
setBinOwner: function (id, bin, fn) {
var params = {
name: id,
View
@@ -41,7 +41,7 @@ var methods = [
'reportBin',
'getAllOwners',
'getOwnersBlock',
-
+ 'isOwnerOf',
'populateOwners'
];
@@ -146,8 +146,8 @@ var libraries = [
"group": "Prototype"
},
{
- "url": "http://yui.yahooapis.com/3.8.1/build/yui/yui-min.js",
- "label": "YUI 3.8.1",
+ "url": "http://yui.yahooapis.com/3.9.1/build/yui/yui-min.js",
+ "label": "YUI 3.9.1",
"group": "YUI"
},
{
@@ -414,7 +414,7 @@ var exec = document.getElementById('exec'),
underscore: 'http://documentcloud.github.com/underscore/underscore-min.js',
rightjs: 'http://rightjs.org/hotlink/right.js',
coffeescript: 'http://jashkenas.github.com/coffee-script/extras/coffee-script.js',
- yui: 'http://yui.yahooapis.com/3.8.1/build/yui/yui-min.js'
+ yui: 'http://yui.yahooapis.com/3.9.1/build/yui/yui-min.js'
},
body = document.getElementsByTagName('body')[0],
logAfter = null,

0 comments on commit ea0fa94

Please sign in to comment.