|
| 1 | +// AVACL.h |
| 2 | +// Copyright 2013 AVOS Inc. All rights reserved. |
| 3 | + |
| 4 | +#import <Foundation/Foundation.h> |
| 5 | + |
| 6 | +@class AVUser; |
| 7 | +@class AVRole; |
| 8 | + |
| 9 | +/*! |
| 10 | + A AVACL is used to control which users can access or modify a particular |
| 11 | + object. Each AVObject can have its own AVACL. You can grant |
| 12 | + read and write permissions separately to specific users, to groups of users |
| 13 | + that belong to roles, or you can grant permissions to "the public" so that, |
| 14 | + for example, any user could read a particular object but only a particular |
| 15 | + set of users could write to that object. |
| 16 | + */ |
| 17 | +@interface AVACL : NSObject <NSCopying> |
| 18 | + |
| 19 | +/** @name Creating an ACL */ |
| 20 | + |
| 21 | +/*! |
| 22 | + Creates an ACL with no permissions granted. |
| 23 | + */ |
| 24 | ++ (AVACL *)ACL; |
| 25 | + |
| 26 | +/*! |
| 27 | + Creates an ACL where only the provided user has access. |
| 28 | + @param user the AVUser |
| 29 | + */ |
| 30 | ++ (AVACL *)ACLWithUser:(AVUser *)user; |
| 31 | + |
| 32 | +/** @name Controlling Public Access */ |
| 33 | + |
| 34 | +/*! |
| 35 | + Set whether the public is allowed to read this object. |
| 36 | + @param allowed allowed or not |
| 37 | + */ |
| 38 | + |
| 39 | +- (void)setPublicReadAccess:(BOOL)allowed; |
| 40 | + |
| 41 | +/*! |
| 42 | + Gets whether the public is allowed to read this object. |
| 43 | + */ |
| 44 | +- (BOOL)getPublicReadAccess; |
| 45 | + |
| 46 | +/*! |
| 47 | + Set whether the public is allowed to write this object. |
| 48 | + @param allowed allowed or not |
| 49 | + */ |
| 50 | +- (void)setPublicWriteAccess:(BOOL)allowed; |
| 51 | + |
| 52 | +/*! |
| 53 | + Gets whether the public is allowed to write this object. |
| 54 | + */ |
| 55 | +- (BOOL)getPublicWriteAccess; |
| 56 | + |
| 57 | +/** @name Controlling Access Per-User */ |
| 58 | + |
| 59 | +/*! |
| 60 | + Set whether the given user id is allowed to read this object. |
| 61 | + @param allowed allowed or not |
| 62 | + @param userId the AVUser's objectId |
| 63 | + */ |
| 64 | +- (void)setReadAccess:(BOOL)allowed forUserId:(NSString *)userId; |
| 65 | + |
| 66 | +/*! |
| 67 | + Gets whether the given user id is *explicitly* allowed to read this object. |
| 68 | + Even if this returns NO, the user may still be able to access it if getPublicReadAccess returns YES |
| 69 | + or if the user belongs to a role that has access. |
| 70 | + @param userId the AVUser's objectId |
| 71 | + */ |
| 72 | +- (BOOL)getReadAccessForUserId:(NSString *)userId; |
| 73 | + |
| 74 | +/*! |
| 75 | + Set whether the given user id is allowed to write this object. |
| 76 | + @param allowed allowed or not |
| 77 | + @param userId the AVUser's objectId |
| 78 | + */ |
| 79 | +- (void)setWriteAccess:(BOOL)allowed forUserId:(NSString *)userId; |
| 80 | + |
| 81 | +/*! |
| 82 | + Gets whether the given user id is *explicitly* allowed to write this object. |
| 83 | + Even if this returns NO, the user may still be able to write it if getPublicWriteAccess returns YES |
| 84 | + or if the user belongs to a role that has access. |
| 85 | + |
| 86 | + @param userId the AVUser's objectId |
| 87 | + */ |
| 88 | +- (BOOL)getWriteAccessForUserId:(NSString *)userId; |
| 89 | + |
| 90 | +/*! |
| 91 | + Set whether the given user is allowed to read this object. |
| 92 | + @param allowed allowed or not |
| 93 | + @param user the AVUser |
| 94 | + */ |
| 95 | +- (void)setReadAccess:(BOOL)allowed forUser:(AVUser *)user; |
| 96 | + |
| 97 | +/*! |
| 98 | + Gets whether the given user is *explicitly* allowed to read this object. |
| 99 | + Even if this returns NO, the user may still be able to access it if getPublicReadAccess returns YES |
| 100 | + or if the user belongs to a role that has access. |
| 101 | + @param user the AVUser |
| 102 | + */ |
| 103 | +- (BOOL)getReadAccessForUser:(AVUser *)user; |
| 104 | + |
| 105 | +/*! |
| 106 | + Set whether the given user is allowed to write this object. |
| 107 | + @param allowed allowed or not |
| 108 | + @param user the AVUser |
| 109 | + */ |
| 110 | +- (void)setWriteAccess:(BOOL)allowed forUser:(AVUser *)user; |
| 111 | + |
| 112 | +/*! |
| 113 | + Gets whether the given user is *explicitly* allowed to write this object. |
| 114 | + Even if this returns NO, the user may still be able to write it if getPublicWriteAccess returns YES |
| 115 | + or if the user belongs to a role that has access. |
| 116 | + @param user the AVUser |
| 117 | + */ |
| 118 | +- (BOOL)getWriteAccessForUser:(AVUser *)user; |
| 119 | + |
| 120 | +/** @name Controlling Access Per-Role */ |
| 121 | + |
| 122 | +/*! |
| 123 | + Get whether users belonging to the role with the given name are allowed |
| 124 | + to read this object. Even if this returns false, the role may still |
| 125 | + be able to read it if a parent role has read access. |
| 126 | + |
| 127 | + @param name The name of the role. |
| 128 | + @return YES if the role has read access. NO otherwise. |
| 129 | + */ |
| 130 | +- (BOOL)getReadAccessForRoleWithName:(NSString *)name; |
| 131 | + |
| 132 | +/*! |
| 133 | + Set whether users belonging to the role with the given name are allowed |
| 134 | + to read this object. |
| 135 | + |
| 136 | + @param name The name of the role. |
| 137 | + @param allowed Whether the given role can read this object. |
| 138 | + */ |
| 139 | +- (void)setReadAccess:(BOOL)allowed forRoleWithName:(NSString *)name; |
| 140 | + |
| 141 | +/*! |
| 142 | + Get whether users belonging to the role with the given name are allowed |
| 143 | + to write this object. Even if this returns false, the role may still |
| 144 | + be able to write it if a parent role has write access. |
| 145 | + |
| 146 | + @param name The name of the role. |
| 147 | + @return YES if the role has read access. NO otherwise. |
| 148 | + */ |
| 149 | +- (BOOL)getWriteAccessForRoleWithName:(NSString *)name; |
| 150 | + |
| 151 | +/*! |
| 152 | + Set whether users belonging to the role with the given name are allowed |
| 153 | + to write this object. |
| 154 | + |
| 155 | + @param name The name of the role. |
| 156 | + @param allowed Whether the given role can write this object. |
| 157 | + */ |
| 158 | +- (void)setWriteAccess:(BOOL)allowed forRoleWithName:(NSString *)name; |
| 159 | + |
| 160 | +/*! |
| 161 | + Get whether users belonging to the given role are allowed to read this |
| 162 | + object. Even if this returns NO, the role may still be able to |
| 163 | + read it if a parent role has read access. The role must already be saved on |
| 164 | + the server and its data must have been fetched in order to use this method. |
| 165 | + |
| 166 | + @param role the given role |
| 167 | + @return YES if the role has read access. NO otherwise. |
| 168 | + */ |
| 169 | +- (BOOL)getReadAccessForRole:(AVRole *)role; |
| 170 | + |
| 171 | +/*! |
| 172 | + Set whether users belonging to the given role are allowed to read this |
| 173 | + object. The role must already be saved on the server and its data must have |
| 174 | + been fetched in order to use this method. |
| 175 | + |
| 176 | + @param role The role to assign access. |
| 177 | + @param allowed Whether the given role can read this object. |
| 178 | + */ |
| 179 | +- (void)setReadAccess:(BOOL)allowed forRole:(AVRole *)role; |
| 180 | + |
| 181 | +/*! |
| 182 | + Get whether users belonging to the given role are allowed to write this |
| 183 | + object. Even if this returns NO, the role may still be able to |
| 184 | + write it if a parent role has write access. The role must already be saved on |
| 185 | + the server and its data must have been fetched in order to use this method. |
| 186 | + |
| 187 | + @param role the given role |
| 188 | + @return YES if the role has write access. NO otherwise. |
| 189 | + */ |
| 190 | +- (BOOL)getWriteAccessForRole:(AVRole *)role; |
| 191 | + |
| 192 | +/*! |
| 193 | + Set whether users belonging to the given role are allowed to write this |
| 194 | + object. The role must already be saved on the server and its data must have |
| 195 | + been fetched in order to use this method. |
| 196 | + |
| 197 | + @param role The role to assign access. |
| 198 | + @param allowed Whether the given role can write this object. |
| 199 | + */ |
| 200 | +- (void)setWriteAccess:(BOOL)allowed forRole:(AVRole *)role; |
| 201 | + |
| 202 | +/** @name Setting Access Defaults */ |
| 203 | + |
| 204 | +/*! |
| 205 | + Sets a default ACL that will be applied to all AVObjects when they are created. |
| 206 | + @param acl The ACL to use as a template for all AVObjects created after setDefaultACL has been called. |
| 207 | + This value will be copied and used as a template for the creation of new ACLs, so changes to the |
| 208 | + instance after setDefaultACL has been called will not be reflected in new AVObjects. |
| 209 | + @param currentUserAccess If true, the AVACL that is applied to newly-created AVObjects will |
| 210 | + provide read and write access to the currentUser at the time of creation. If false, |
| 211 | + the provided ACL will be used without modification. If acl is nil, this value is ignored. |
| 212 | + */ |
| 213 | ++ (void)setDefaultACL:(AVACL *)acl withAccessForCurrentUser:(BOOL)currentUserAccess; |
| 214 | + |
| 215 | +@end |
0 commit comments