2017-01-31 13:07:29 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright 2016 Realm Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
//
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
'use strict';
|
|
|
|
|
2017-09-27 22:26:20 +00:00
|
|
|
import { createUser as createUserRPC, _adminUser as _adminUserRPC, getAllUsers as getAllUsersRPC } from './rpc';
|
2017-01-31 13:07:29 +00:00
|
|
|
import { keys, objectTypes } from './constants';
|
|
|
|
import { createMethods } from './util';
|
|
|
|
|
|
|
|
export default class User {
|
2017-06-17 14:59:15 +00:00
|
|
|
static createUser(server, identity, token, isAdminToken, isAdminUser) {
|
|
|
|
return createUserRPC(Array.from(arguments));
|
2017-01-31 13:07:29 +00:00
|
|
|
}
|
|
|
|
|
2017-09-27 22:26:20 +00:00
|
|
|
static _adminUser(adminToken, server) {
|
|
|
|
return _adminUserRPC(Array.from(arguments));
|
|
|
|
}
|
|
|
|
|
2017-01-31 13:07:29 +00:00
|
|
|
static get all() {
|
|
|
|
return getAllUsersRPC();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
createMethods(User.prototype, objectTypes.USER, [
|
2017-02-01 13:18:59 +00:00
|
|
|
'logout',
|
|
|
|
'_sessionForOnDiskPath'
|
2017-01-31 13:07:29 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
export function createUser(realmId, info) {
|
|
|
|
const userProxy = Object.create(User.prototype);
|
|
|
|
|
|
|
|
// FIXME: This is currently necessary because util/createMethod expects
|
|
|
|
// the realm id to be present on any object that is used over rpc
|
|
|
|
userProxy[keys.realm] = "(User object)";
|
|
|
|
|
|
|
|
userProxy[keys.id] = info.id;
|
|
|
|
userProxy[keys.type] = objectTypes.USER;
|
|
|
|
Object.assign(userProxy, info.data);
|
|
|
|
|
|
|
|
return userProxy;
|
|
|
|
}
|