Permalink
Browse files

validation works better for deletion.

  • Loading branch information...
1 parent 338a2da commit ce43ff2ed714f1c9b0233b6a13524877fcecd7d4 @jchris committed Mar 22, 2010
Showing with 15 additions and 22 deletions.
  1. +1 −1 couchapp.json
  2. +5 −2 lib/validate.js
  3. +4 −14 templates/edit.html
  4. +4 −4 validate_doc_update.js
  5. +1 −1 views/recent-posts/map.js
View
@@ -1,3 +1,3 @@
{
- "index" : "_list/index/recent-posts?descending=true&limit=5"
+ "index" : "_list/index/recent-posts?descending=true&limit=10"
}
View
@@ -15,9 +15,12 @@ exports.init = function(newDoc, oldDoc, userCtx, secObj) {
if (!should) v.forbidden(message);
}
-
+ v.isAuthor = function() {
+ return userCtx.roles.indexOf('author') != -1
+ };
+
v.isAdmin = function() {
- userCtx.roles.indexOf('_admin') != -1
+ return userCtx.roles.indexOf('_admin') != -1
};
v.require = function() {
View
@@ -86,26 +86,16 @@
},
success : function(resp) {
$("#saved").text("Saved _rev: "+resp.rev).fadeIn(500).fadeOut(6000);
- $('h1').html('Editing <a href="'+path.show('post',doc._id)+'">'+doc._id+'</a>');
+ $('h1').html('Editing <a href="'+path.show('post',resp.id)+'">'+resp.id+'</a>');
}
});
}
- })
-
- var formatBody = function(body, format) {
- if (format == 'markdown') {
- var converter = new Showdown.converter();
- return converter.makeHtml(body);
- } else if (format == 'textile') {
- return "superTextile(body);" // TODO use commonjs one
- } else {
- return body;
- }
- }
+ });
$("#preview").click(function() {
+ var markdown = app.require("vendor/markdown/lib/markdown");
var doc = postForm.localDoc();
- var html = formatBody(doc.body, doc.format);
+ var html = markdown.encode(doc.body);
$('#show-preview').html(html);
$('body').scrollTo('#show-preview', {duration: 500});
});
View
@@ -1,6 +1,9 @@
function (newDoc, oldDoc, userCtx, secObj) {
var v = require("lib/validate").init(newDoc, oldDoc, userCtx, secObj);
+ // admins can always delete
+ if ((v.isAdmin() || v.isAuthor()) && newDoc._deleted) return true;
+
v.unchanged("type");
v.unchanged("author");
v.unchanged("created_at");
@@ -12,10 +15,7 @@ function (newDoc, oldDoc, userCtx, secObj) {
if (!v.isAdmin(userCtx) && newDoc.author && newDoc.author != userCtx.name) {
v.unauthorized("Only "+newDoc.author+" may edit this document.");
}
-
- // admins can always delete
- if (v.isAdmin(userCtx) && newDoc._deleted) return true;
-
+
if (newDoc.type == 'post') {
v.require("created_at", "author", "body", "format", "title");
@@ -16,7 +16,7 @@ function(doc) {
// }
if (doc.type == "post") {
// var summary = (html.replace(/<(.|\n)*?>/g, '').substring(0,350) + '...');
- emit(doc.created_at, {
+ emit(new Date(doc.created_at), {
body : doc.body,
title : doc.title,
author : doc.author,

0 comments on commit ce43ff2

Please sign in to comment.