@@ -38,131 +38,6 @@ const is = require('is');
3838 */
3939class AclRoleAccessorMethods {
4040 constructor ( ) {
41- AclRoleAccessorMethods . roles . forEach ( this . _assignAccessMethods . bind ( this ) ) ;
42- }
43-
44- _assignAccessMethods ( role ) {
45- const accessMethods = AclRoleAccessorMethods . accessMethods ;
46- const entities = AclRoleAccessorMethods . entities ;
47- const roleGroup = role . toLowerCase ( ) + 's' ;
48-
49- this [ roleGroup ] = entities . reduce ( ( acc , entity ) => {
50- const isPrefix = entity . charAt ( entity . length - 1 ) === '-' ;
51-
52- accessMethods . forEach ( accessMethod => {
53- let method = accessMethod + entity [ 0 ] . toUpperCase ( ) + entity . substr ( 1 ) ;
54-
55- if ( isPrefix ) {
56- method = method . replace ( '-' , '' ) ;
57- }
58-
59- // Wrap the parent accessor method (e.g. `add` or `delete`) to avoid the
60- // more complex API of specifying an `entity` and `role`.
61- acc [ method ] = ( entityId , options , callback ) => {
62- let apiEntity ;
63-
64- if ( is . fn ( options ) ) {
65- callback = options ;
66- options = { } ;
67- }
68-
69- if ( isPrefix ) {
70- apiEntity = entity + entityId ;
71- } else {
72- // If the entity is not a prefix, it is a special entity group that
73- // does not require further details. The accessor methods only accept
74- // a callback.
75- apiEntity = entity ;
76- callback = entityId ;
77- }
78-
79- options = extend (
80- {
81- entity : apiEntity ,
82- role : role ,
83- } ,
84- options
85- ) ;
86-
87- const args = [ options ] ;
88-
89- if ( is . fn ( callback ) ) {
90- args . push ( callback ) ;
91- }
92-
93- return this [ accessMethod ] . apply ( this , args ) ;
94- } ;
95- } ) ;
96-
97- return acc ;
98- } , { } ) ;
99- }
100- }
101-
102- AclRoleAccessorMethods . accessMethods = [ 'add' , 'delete' ] ;
103-
104- AclRoleAccessorMethods . entities = [
105- // Special entity groups that do not require further specification.
106- 'allAuthenticatedUsers' ,
107- 'allUsers' ,
108-
109- // Entity groups that require specification, e.g. `user-email@example.com`.
110- 'domain-' ,
111- 'group-' ,
112- 'project-' ,
113- 'user-' ,
114- ] ;
115-
116- AclRoleAccessorMethods . roles = [ 'OWNER' , 'READER' , 'WRITER' ] ;
117-
118- /**
119- * Cloud Storage uses access control lists (ACLs) to manage object and
120- * bucket access. ACLs are the mechanism you use to share objects with other
121- * users and allow other users to access your buckets and objects.
122- *
123- * An ACL consists of one or more entries, where each entry grants permissions
124- * to an entity. Permissions define the actions that can be performed against an
125- * object or bucket (for example, `READ` or `WRITE`); the entity defines who the
126- * permission applies to (for example, a specific user or group of users).
127- *
128- * Where an `entity` value is accepted, we follow the format the Cloud Storage
129- * API expects.
130- *
131- * Refer to
132- * https://cloud.google.com/storage/docs/json_api/v1/defaultObjectAccessControls
133- * for the most up-to-date values.
134- *
135- * - `user-userId`
136- * - `user-email`
137- * - `group-groupId`
138- * - `group-email`
139- * - `domain-domain`
140- * - `project-team-projectId`
141- * - `allUsers`
142- * - `allAuthenticatedUsers`
143- *
144- * Examples:
145- *
146- * - The user "liz@example.com" would be `user-liz@example.com`.
147- * - The group "example@googlegroups.com" would be
148- * `group-example@googlegroups.com`.
149- * - To refer to all members of the Google Apps for Business domain
150- * "example.com", the entity would be `domain-example.com`.
151- *
152- * For more detailed information, see
153- * [About Access Control Lists](http://goo.gl/6qBBPO).
154- *
155- * @constructor Acl
156- * @mixin
157- * @param {object } options Configuration options.
158- */
159- class Acl extends AclRoleAccessorMethods {
160- constructor ( options ) {
161- super ( ) ;
162-
163- this . pathPrefix = options . pathPrefix ;
164- this . request_ = options . request ;
165-
16641 /**
16742 * An object of convenience methods to add or delete owner ACL permissions for a
16843 * given entity.
@@ -311,6 +186,131 @@ class Acl extends AclRoleAccessorMethods {
311186 * });
312187 */
313188 this . writers = { } ;
189+
190+ AclRoleAccessorMethods . roles . forEach ( this . _assignAccessMethods . bind ( this ) ) ;
191+ }
192+
193+ _assignAccessMethods ( role ) {
194+ const accessMethods = AclRoleAccessorMethods . accessMethods ;
195+ const entities = AclRoleAccessorMethods . entities ;
196+ const roleGroup = role . toLowerCase ( ) + 's' ;
197+
198+ this [ roleGroup ] = entities . reduce ( ( acc , entity ) => {
199+ const isPrefix = entity . charAt ( entity . length - 1 ) === '-' ;
200+
201+ accessMethods . forEach ( accessMethod => {
202+ let method = accessMethod + entity [ 0 ] . toUpperCase ( ) + entity . substr ( 1 ) ;
203+
204+ if ( isPrefix ) {
205+ method = method . replace ( '-' , '' ) ;
206+ }
207+
208+ // Wrap the parent accessor method (e.g. `add` or `delete`) to avoid the
209+ // more complex API of specifying an `entity` and `role`.
210+ acc [ method ] = ( entityId , options , callback ) => {
211+ let apiEntity ;
212+
213+ if ( is . fn ( options ) ) {
214+ callback = options ;
215+ options = { } ;
216+ }
217+
218+ if ( isPrefix ) {
219+ apiEntity = entity + entityId ;
220+ } else {
221+ // If the entity is not a prefix, it is a special entity group that
222+ // does not require further details. The accessor methods only accept
223+ // a callback.
224+ apiEntity = entity ;
225+ callback = entityId ;
226+ }
227+
228+ options = extend (
229+ {
230+ entity : apiEntity ,
231+ role : role ,
232+ } ,
233+ options
234+ ) ;
235+
236+ const args = [ options ] ;
237+
238+ if ( is . fn ( callback ) ) {
239+ args . push ( callback ) ;
240+ }
241+
242+ return this [ accessMethod ] . apply ( this , args ) ;
243+ } ;
244+ } ) ;
245+
246+ return acc ;
247+ } , { } ) ;
248+ }
249+ }
250+
251+ AclRoleAccessorMethods . accessMethods = [ 'add' , 'delete' ] ;
252+
253+ AclRoleAccessorMethods . entities = [
254+ // Special entity groups that do not require further specification.
255+ 'allAuthenticatedUsers' ,
256+ 'allUsers' ,
257+
258+ // Entity groups that require specification, e.g. `user-email@example.com`.
259+ 'domain-' ,
260+ 'group-' ,
261+ 'project-' ,
262+ 'user-' ,
263+ ] ;
264+
265+ AclRoleAccessorMethods . roles = [ 'OWNER' , 'READER' , 'WRITER' ] ;
266+
267+ /**
268+ * Cloud Storage uses access control lists (ACLs) to manage object and
269+ * bucket access. ACLs are the mechanism you use to share objects with other
270+ * users and allow other users to access your buckets and objects.
271+ *
272+ * An ACL consists of one or more entries, where each entry grants permissions
273+ * to an entity. Permissions define the actions that can be performed against an
274+ * object or bucket (for example, `READ` or `WRITE`); the entity defines who the
275+ * permission applies to (for example, a specific user or group of users).
276+ *
277+ * Where an `entity` value is accepted, we follow the format the Cloud Storage
278+ * API expects.
279+ *
280+ * Refer to
281+ * https://cloud.google.com/storage/docs/json_api/v1/defaultObjectAccessControls
282+ * for the most up-to-date values.
283+ *
284+ * - `user-userId`
285+ * - `user-email`
286+ * - `group-groupId`
287+ * - `group-email`
288+ * - `domain-domain`
289+ * - `project-team-projectId`
290+ * - `allUsers`
291+ * - `allAuthenticatedUsers`
292+ *
293+ * Examples:
294+ *
295+ * - The user "liz@example.com" would be `user-liz@example.com`.
296+ * - The group "example@googlegroups.com" would be
297+ * `group-example@googlegroups.com`.
298+ * - To refer to all members of the Google Apps for Business domain
299+ * "example.com", the entity would be `domain-example.com`.
300+ *
301+ * For more detailed information, see
302+ * [About Access Control Lists](http://goo.gl/6qBBPO).
303+ *
304+ * @constructor Acl
305+ * @mixin
306+ * @param {object } options Configuration options.
307+ */
308+ class Acl extends AclRoleAccessorMethods {
309+ constructor ( options ) {
310+ super ( ) ;
311+
312+ this . pathPrefix = options . pathPrefix ;
313+ this . request_ = options . request ;
314314 }
315315
316316 /**
0 commit comments