Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Implementation of CouchUser and CouchSecurity #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Commits on Jun 23, 2012

  1. Copy the full SHA
    dc3dea0 View commit details
    Browse the repository at this point in the history
  2. Implemented CouchUser (_users) and CouchSecurity (_security) support.

    CouchUser* user = [_server userWithName:@"Alice"];
    user.password = @"secret"; // will be hashed on the server
    // set some additional properties
    [user setValue:@"Alice" ofProperty:@"firstname"];
    [user setValue:@"Wonderland" ofProperty:@"lastname"];
    if ([[user save] wait]) NSLog(@"Saved: %@", user);
    
    CouchSecurity* security = [_db security];
    security.readerNames = [NSArray arrayWithObjects:@"bob", nil];
    security.adminRoles  = [NSArray arrayWithObjects:@"boss", nil];
    // add an admin user
    [security addObject:user.name forProperty:kSecurityAdminNamesKey];
    if ([security update]) NSLog(@"Saved: %@", security);
    fabien committed Jun 23, 2012
    Copy the full SHA
    7191f9b View commit details
    Browse the repository at this point in the history
  3. Implemented Embedded Model properties.

    With this setup a Model property can be embedded instead of referenced by ID,
    making it easy to develop a nested model structure. The next logical step is
    to enable this for NSArray properties - allowing embedding and referencing of
    other CouchModel objects.
    
    If an existing Model is embedded, it keeps a referenceID to the original Model.
    
    There are various ways to control the embedding behaviour, using hook methods:
    
    + (id) embeddedModelForDocument:(CouchDocument *)document
                             parent:(CouchModel*)parent
                           property:(NSString *)property;
    
    - (BOOL) isEmbedableModelProperty: (NSString*)property;
    - (BOOL) isEmbedableIn: (CouchModel*)parent forProperty:(NSString*)property;
    - (void) didEmbedIn: (CouchModel*)parent forProperty:(NSString*)property;
    - (NSDictionary*) embeddedPropertiesToSave;
    
    Example of creating a new embedded model:
    
    Student* alice = [self createModelWithName: @"Alice" grade: 9];
    Student* buddy = [alice embedModelForProperty:@"buddy"];
    buddy.name = @"Bob";
    [alice save];
    if (alice.buddy.name == bob.name) NSLog(@"Buddies");
    
    Example of embedding an existing model:
    
    Student* alice = [self createModelWithName: @"Alice" grade: 9];
    Student* bob = [self createModelWithName: @"Bob" grade: 7];
    [alice embedModel:bob forProperty:@"buddy"];
    [alice save];
    if (alice.buddy.name == bob.name) {
      NSLog(@"Buddies - referenceID: %@", alice.buddy.referenceID);
    }
    fabien committed Jun 23, 2012
    Copy the full SHA
    2f26103 View commit details
    Browse the repository at this point in the history