Permalink
Browse files

Updated doc ownership schema

Only wikis, not pages, have owners/members.
The member editing UI is still on pages for now, but controls access to the whole wiki.
Pull replication now syncs all channels (["*"]).
  • Loading branch information...
1 parent 0dbcd17 commit 4640163a599006e88f16b4811f53d66f6a18856d @snej snej committed Jan 24, 2013
@@ -489,6 +489,7 @@
GCC_SYMBOLS_PRIVATE_EXTERN = NO;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
@@ -514,6 +515,7 @@
GCC_C_LANGUAGE_STANDARD = gnu99;
GCC_TREAT_WARNINGS_AS_ERRORS = YES;
GCC_WARN_ABOUT_RETURN_TYPE = YES;
+ GCC_WARN_UNDECLARED_SELECTOR = YES;
GCC_WARN_UNINITIALIZED_AUTOS = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 6.0;
@@ -109,8 +109,7 @@ - (void) syncManager: (SyncManager*)manager addedReplication: (TDReplication*)re
if (replication.pull) {
// Pull replication: Define the set of channels to sync
replication.filter = @"sync_gateway/bychannel";
- NSArray* channels = _wikiStore.channelsToSync;
- replication.query_params = @{@"channels": [channels componentsJoinedByString: @","]};
+ replication.query_params = @{@"channels": @[@"*"]};
} else {
// Push replication: Set filter to block pushing draft documents
replication.filter = @"notDraft"; // defined in WikiStore.m
@@ -193,8 +192,8 @@ - (void) loadContent {
//FIX: Use a real template engine!
replace(html, @"{{ACCESSCLASS}}", klass);
- replace(html, @"{{OWNER}}", _page.owner_id);
- replace(html, @"{{MEMBERS}}", [_page.members componentsJoinedByString: @", "]);
+ replace(html, @"{{OWNER}}", _page.wiki.owner_id);
+ replace(html, @"{{MEMBERS}}", [_page.wiki.members componentsJoinedByString: @", "]);
if (_page.draft) {
[html appendString: @"<div id='banner'>PREVIEW</div>\n"];
@@ -380,7 +379,7 @@ - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)butto
- (void) updateMembers: (NSArray*)members {
members = [[NSOrderedSet orderedSetWithArray: members] array]; // Remove duplicates
- _page.members = members;
+ _page.wiki.members = members;
[_page.wiki addMembers: members];
}
View
@@ -28,6 +28,11 @@
- (NSString*) docIDForPageWithTitle: (NSString*)title;
+@property (readonly) NSString* owner_id;
+@property (copy) NSArray* members;
+
+- (void) addMembers: (NSArray*)newMembers;
+
@end
View
@@ -18,13 +18,14 @@ @implementation Wiki
NSSet* _allPageTitles;
}
-@dynamic title, markdown, created_at, updated_at;
+@dynamic title, markdown, created_at, updated_at, owner_id, members;
- (id) initNewWithTitle: (NSString*)title inWikiStore: (WikiStore*)wikiStore {
self = [super initWithNewDocumentInDatabase: wikiStore.database];
if (self) {
- [self setType: @"wiki" owner: wikiStore.username];
+ [self setupType: @"wiki"];
+ [self setValue: wikiStore.username ofProperty: @"owner_id"];
self.title = title;
}
return self;
@@ -90,4 +91,28 @@ - (void) observeValueForKeyPath:(NSString *)keyPath
}
+- (bool) editable {
+ NSString* username = self.wikiStore.username;
+ return [self.owner_id isEqualToString: username] || [self.members containsObject: username];
+}
+
+
+- (bool) owned {
+ NSString* username = self.wikiStore.username;
+ return [self.owner_id isEqualToString: username];
+}
+
+
+- (void) addMembers: (NSArray*)newMembers {
+ NSArray* oldMembers = self.members;
+ if (!oldMembers) {
+ self.members = newMembers;
+ return;
+ }
+ NSMutableOrderedSet* members = [NSMutableOrderedSet orderedSetWithArray: self.members];
+ [members addObjectsFromArray: newMembers];
+ self.members = members.array;
+}
+
+
@end
View
@@ -20,17 +20,12 @@
@property (strong) NSDate* created_at;
@property (strong) NSDate* updated_at;
-@property (readonly) NSString* owner_id;
-@property (copy) NSArray* members;
-
-- (void) addMembers: (NSArray*)newMembers;
-
@property (readonly) bool editable;
@property (readonly) bool owned;
@end
@interface WikiItem (Private)
-- (void) setType: (NSString*)type owner: (NSString*)owner;
+- (void) setupType: (NSString*)type;
@end
View
@@ -10,15 +10,10 @@
#import "WikiStore.h"
-@interface WikiItem ()
-@property (readwrite) NSString* owner_id;
-@end
-
-
@implementation WikiItem
-@dynamic title, markdown, created_at, updated_at, owner_id, members;
+@dynamic title, markdown, created_at, updated_at;
- (id) initWithDocument: (TDDocument*)document {
@@ -30,10 +25,8 @@ - (id) initWithDocument: (TDDocument*)document {
}
-- (void) setType: (NSString*)type owner: (NSString*)owner {
- NSParameterAssert(owner.length > 0);
+- (void) setupType: (NSString*)type {
[self setValue: type ofProperty: @"type"];
- self.owner_id = owner;
self.created_at = self.updated_at = [NSDate date];
}
@@ -56,26 +49,12 @@ - (WikiStore*) wikiStore {
- (bool) editable {
- NSString* username = self.wikiStore.username;
- return [self.owner_id isEqualToString: username] || [self.members containsObject: username];
+ return false; // abstract
}
- (bool) owned {
- NSString* username = self.wikiStore.username;
- return [self.owner_id isEqualToString: username];
-}
-
-
-- (void) addMembers: (NSArray*)newMembers {
- NSArray* oldMembers = self.members;
- if (!oldMembers) {
- self.members = newMembers;
- return;
- }
- NSMutableOrderedSet* members = [NSMutableOrderedSet orderedSetWithArray: self.members];
- [members addObjectsFromArray: newMembers];
- self.members = members.array;
+ return false; // abstract
}
View
@@ -17,10 +17,10 @@
@property (readonly) Wiki* wiki;
+// A document with this flag set will not be pushed to the server. */
@property bool draft;
// Ephemeral properties:
-//@property bool editing;
@property NSRange selectedRange;
+ (bool) parseDocID: (NSString*)docID
View
@@ -11,11 +11,6 @@
#import "WikiStore.h"
-@interface WikiPage ()
-@property (readwrite) NSString* owner_id;
-@end
-
-
@implementation WikiPage
@@ -26,7 +21,7 @@ - (id) initNewWithTitle: (NSString*)title inWiki: (Wiki*)wiki {
TDDocument* doc = [wiki.database documentWithID: [wiki docIDForPageWithTitle: title]];
self = [super initWithDocument: doc];
if (self) {
- [self setType: @"page" owner: wiki.wikiStore.username];
+ [self setupType: @"page"];
[self setValue: wiki.wikiID ofProperty: @"wiki_id"];
}
return self;
@@ -72,4 +67,14 @@ - (NSTimeInterval) autosaveDelay {
}
+- (bool) editable {
+ return self.wiki.editable;
+}
+
+
+- (bool) owned {
+ return self.wiki.owned;
+}
+
+
@end
View
@@ -32,6 +32,4 @@
@property (strong) NSString* username;
-@property (strong) NSArray* channelsToSync;
-
@end
View
@@ -95,23 +95,6 @@ - (void) setUsername:(NSString *)username {
}
-- (NSArray*) channelsToSync {
- //FIX: This would be better stored in a _local document in the database
- NSArray* channels = [[NSUserDefaults standardUserDefaults] objectForKey: @"ChannelsToSync"];
- if (!channels)
- channels = @[];
- NSString* username = self.username;
- if (username && ![channels containsObject: username])
- channels = [channels arrayByAddingObject: username];
- return channels;
-}
-
-
-- (void) setChannelsToSync:(NSArray *)channelsToSync {
- [[NSUserDefaults standardUserDefaults] setObject: channelsToSync forKey: @"ChannelsToSync"];
-}
-
-
- (TDQuery*) queryPagesOfWiki: (Wiki*)wiki {
TDQuery* query = [[_database viewNamed: @"pagesByTitle"] query];
query.startKey = @[wiki.wikiID];

0 comments on commit 4640163

Please sign in to comment.