Improve JSON responses for message actions

This commit is contained in:
Francis Lachapelle 2015-12-21 22:17:40 -05:00
parent 1e45606681
commit 1419f4b6ca

View file

@ -268,11 +268,10 @@ static NSString *mailETag = nil;
if (![co doesMailExist]) if (![co doesMailExist])
{ {
data = [NSDictionary dictionaryWithObjectsAndKeys: data = [NSDictionary dictionaryWithObject: [self labelForKey: @"Message got deleted"]
@"message got deleted", @"error", forKey: @"message"];
nil];
return [self responseWithStatus: 404 /* Not Found */ return [self responseWithStatus: 404 /* Not Found */
andString: [data jsonRepresentation]]; andJSONRepresentation: data];
} }
response = [self responseWithStatus: 304]; response = [self responseWithStatus: 304];
@ -283,11 +282,10 @@ static NSString *mailETag = nil;
if (![self message]) // TODO: redirect to proper error if (![self message]) // TODO: redirect to proper error
{ {
data = [NSDictionary dictionaryWithObjectsAndKeys: data = [NSDictionary dictionaryWithObject: [self labelForKey: @"Did not find specified message"]
@"did not find specified message!", @"error", forKey: @"message"];
nil];
return [self responseWithStatus: 404 /* Not Found */ return [self responseWithStatus: 404 /* Not Found */
andString: [data jsonRepresentation]]; andJSONRepresentation: data];
} }
data = [NSMutableDictionary dictionaryWithObjectsAndKeys: data = [NSMutableDictionary dictionaryWithObjectsAndKeys:
@ -311,7 +309,7 @@ static NSString *mailETag = nil;
[data setObject: addresses forKey: @"reply-to"]; [data setObject: addresses forKey: @"reply-to"];
response = [self responseWithStatus: 200 response = [self responseWithStatus: 200
andString: [data jsonRepresentation]]; andJSONRepresentation: data];
[response setHeader: mailETag forKey: @"etag"]; [response setHeader: mailETag forKey: @"etag"];
@ -674,7 +672,7 @@ static NSString *mailETag = nil;
- (WOResponse *) sendMDNAction - (WOResponse *) sendMDNAction
{ {
WOResponse *response; WOResponse *response;
NSDictionary *mailHeaders; NSDictionary *mailHeaders, *jsonResponse;
NSString *email, *action; NSString *email, *action;
mailHeaders = [[self clientObject] mailHeaders]; mailHeaders = [[self clientObject] mailHeaders];
@ -691,9 +689,11 @@ static NSString *mailETag = nil;
if (email) if (email)
{ {
if ([self _userHasEMail: email]) if ([self _userHasEMail: email])
response = [self responseWithStatus: 403 {
andString: (@"One cannot send an MDN to" jsonResponse = [NSDictionary dictionaryWithObject: [self labelForKey: @"One cannot send an MDN to oneself."]
@" oneself.")]; forKey: @"message"];
response = [self responseWithStatus: 403 andJSONRepresentation: jsonResponse];
}
else else
{ {
action = [self _receiptAction]; action = [self _receiptAction];
@ -703,16 +703,20 @@ static NSString *mailETag = nil;
response = [self responseWithStatus: 204]; response = [self responseWithStatus: 204];
} }
else else
response = [self responseWithStatus: 403 {
andString: (@"No notification header found in" jsonResponse = [NSDictionary dictionaryWithObject: [self labelForKey: @"No notification header found in original message."]
@" original message.")]; forKey: @"message"];
response = [self responseWithStatus: 403 andJSONRepresentation: jsonResponse];
}
} }
} }
else else
response = [self responseWithStatus: 403 {
andString: (@"No notification header found in" jsonResponse = [NSDictionary dictionaryWithObject: [self labelForKey: @"No notification header found in original message."]
@" original message.")]; forKey: @"message"];
response = [self responseWithStatus: 403 andJSONRepresentation: jsonResponse];
}
return response; return response;
} }