This repository was archived by the owner on Dec 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathAccountStoreMapping.js
More file actions
123 lines (107 loc) · 4 KB
/
AccountStoreMapping.js
File metadata and controls
123 lines (107 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
'use strict';
var utils = require('../utils');
var InstanceResource = require('./InstanceResource');
/**
* @class AccountStoreMapping
*
* @augments InstanceResource
*
* @description
*
* Encapsulates an Account Store Mapping Resource, and is a base class for
* {@link ApplicationAccountStoreMapping} and {@link OrganizationAccountStoreMapping}.
* For full documentation of the PasswordPolicy resource, please see
* [REST API Reference: Account Store Mapping](https://docs.stormpath.com/rest/product-guide/latest/reference.html?#account-store-mapping).
*
* This class should not be manually constructed. It should be obtained from one
* of these methods:
*
* - {@link Application#getAccountStoreMappings Application.getAccountStoreMappings()}
* - {@link Organization#getAccountStoreMappings Organization.getAccountStoreMappings()}
*
* An account store mapping can exist in two ways:
*
* - Between an {@link Application} and a {@link Directory}, {@link Group}, or
* {@link Organization}.
*
* - Between an {@link Organization} and a {@link Directory} or {@link Group}.
*
* For more information about account store mappings, please see
* [Modeling Your User Base](https://docs.stormpath.com/rest/product-guide/latest/accnt_mgmt.html#modeling-your-user-base).
*
* @param {object} accountStoreMappingResource
*
* The JSON representation of this resource.
*
*/
function AccountStoreMapping() {
AccountStoreMapping.super_.apply(this, arguments);
}
utils.inherits(AccountStoreMapping, InstanceResource);
function AccountStoreClassFactory(data, dataStore) {
var Class = null;
if (!data || !data.href) {
Class = InstanceResource;
}
if (/\/groups/.test(data.href)) {
Class = require('./Group');
}
if (/\/directories/.test(data.href)) {
Class = require('./Directory');
}
if (/\/organizations/.test(data.href)) {
Class = require('./Organization');
}
if (!Class) {
throw new Error('Unknown resource type of Account Store in Account Store Mapping, href:' + data.href);
}
return require('./ResourceFactory').instantiate(Class, data, null, dataStore);
}
AccountStoreClassFactory.super_ = InstanceResource;
AccountStoreMapping.prototype.getApplication = function getApplication(/* [options,] callback */) {
/*
This has been moved to ApplicationAccountStoreMapping, should be removed.
@TODO Version 1.0
*/
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.application.href, args.options, require('./Application'), args.callback);
};
/**
* @description
*
* Get the Account Store of this mapping. For an
* {@link ApplicationAccountStoreMapping} this will be a {@link Directory},
* {@link Group}, or {@link Organization}. For an
* {@link OrganizationAccountStoreMapping} this will be a {@link Directory} or
* {@link Group}.
*
* @param {ExpansionOptions} [expansionOptions]
* For retrieving linked resources of the {@link AccountStoreMapping} during this request.
*
* @param {Function} callback
* The callback to call when the operation is complete. Will be called with
* (err, <{@link Directory}|{@link Group}>).
*
*/
AccountStoreMapping.prototype.getAccountStore = function getAccountStore(/* [options,] callback */) {
var args = utils.resolveArgs(arguments, ['options', 'callback'], true);
return this.dataStore.getResource(this.accountStore.href, args.options, AccountStoreClassFactory, args.callback);
};
/**
* This is not necessary, application can be passed to createAccountStoreMapping(). Remove in 1.0
*
* @private
*/
AccountStoreMapping.prototype.setApplication = function setAccountStoreMappingApplication(application) {
this.application = { href: application.href };
};
/**
* This is not necessary, accountStore can be passed to createAccountStoreMapping(). Remove in 1.0
*
* @private
*/
AccountStoreMapping.prototype.setAccountStore = function setAccountStoreMappingAccountStore(accountStore) {
this.accountStore = { href: accountStore.href };
return this;
};
module.exports = AccountStoreMapping;