@iotile/iotile-cloud
Version:
A typescript library for interfacing with the IOTile Cloud API
105 lines • 3.34 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var User = /** @class */ (function () {
function User(data, token) {
if (data === void 0) { data = {}; }
this.slug = '';
this.isStaff = false;
this.tagline = data.tagline || '';
this.username = data.username || "";
this.name = data.name || "";
this.email = data.email || "";
this.isStaff = data.is_staff || false;
this.id = data.id || "";
this.orgRoles = data.orgRoles || {};
if ('slug' in data) {
this.slug = data.slug;
}
if (data.avatar) {
this.avatarUrl = data.avatar.thumbnail;
}
if (data.created_at) {
this.creationDate = new Date(data.created_at);
}
else {
this.creationDate = new Date();
}
this.token = data.token || token || null;
}
User.prototype.toJson = function () {
var rawData = {
"username": this.username,
"name": this.name,
"email": this.email,
"created_at": this.creationDate,
"is_staff": this.isStaff,
"id": this.id,
"token": this.token,
"avatar": {},
"orgRoles": this.orgRoles
};
if (this.avatarUrl) {
rawData.avatar["thumbnail"] = this.avatarUrl;
}
return rawData;
};
User.Unserialize = function (obj) {
var user = new User(obj);
var server = undefined;
if (obj['server']) {
server = obj['server'];
}
return { user: user, server: server };
};
User.prototype.getFullName = function () {
var name = "";
if (this.name) {
name = this.name;
}
else {
name = this.username;
}
return name;
};
User.prototype.getUsername = function () {
return "@" + this.username;
};
User.prototype.getAvatar = function () {
if (this.avatarUrl) {
return this.avatarUrl;
}
else {
return "";
}
};
User.prototype.setOrgRoles = function (roles) {
this.orgRoles = roles;
};
User.prototype.canReadProperties = function (orgSlug) {
if (orgSlug in this.orgRoles) {
return this.isStaff || this.orgRoles[orgSlug].permissions['can_read_device_properties'] || false;
}
return this.isStaff;
};
User.prototype.canModifyDevice = function (orgSlug) {
if (orgSlug in this.orgRoles) {
return this.isStaff || this.orgRoles[orgSlug].permissions['can_modify_device'] || false;
}
return this.isStaff;
};
User.prototype.canModifyStreamVariables = function (orgSlug) {
if (orgSlug in this.orgRoles) {
return this.isStaff || this.orgRoles[orgSlug].permissions['can_modify_stream_variables'] || false;
}
return this.isStaff;
};
User.prototype.canResetDevice = function (orgSlug) {
if (orgSlug in this.orgRoles) {
return this.isStaff || this.orgRoles[orgSlug].permissions['can_reset_device'] || false;
}
return this.isStaff;
};
return User;
}());
exports.User = User;
//# sourceMappingURL=user.js.map