Compare commits

..

No commits in common. "8a9f53102be5dedd3f2bacb9e8f04fe1353d668b" and "c8b8a8fc03996a3b08a9cf6bb2ffdff7006c8b06" have entirely different histories.

4 changed files with 14 additions and 94 deletions

View File

@ -144,8 +144,6 @@ function socket(request, response, client) {
JSON.stringify({ JSON.stringify({
action: 'session', action: 'session',
credentials: credentials, credentials: credentials,
identities: await ssb.getIdentities(credentials?.session?.name),
identity: await core.getActiveIdentity(credentials?.session?.name, packageOwner, packageName),
parentApp: parentApp, parentApp: parentApp,
id: blobId, id: blobId,
}), }),
@ -212,10 +210,6 @@ function socket(request, response, client) {
if (process) { if (process) {
process.resetPermission(message.permission); process.resetPermission(message.permission);
} }
} else if (message.action == 'setActiveIdentity') {
process.setActiveIdentity(message.identity);
} else if (message.action == 'createIdentity') {
process.createIdentity();
} else if (message.message == 'tfrpc') { } else if (message.message == 'tfrpc') {
if (message.id && g_calls[message.id]) { if (message.id && g_calls[message.id]) {
if (message.error !== undefined) { if (message.error !== undefined) {

View File

@ -56,8 +56,6 @@ class TfNavigationElement extends LitElement {
spark_lines: {type: Object}, spark_lines: {type: Object},
version: {type: Object}, version: {type: Object},
show_version: {type: Boolean}, show_version: {type: Boolean},
identity: {type: String},
identities: {type: Array},
}; };
} }
@ -67,7 +65,6 @@ class TfNavigationElement extends LitElement {
this.show_permissions = false; this.show_permissions = false;
this.status = {}; this.status = {};
this.spark_lines = {}; this.spark_lines = {};
this.identities = [];
} }
/** /**
@ -131,37 +128,6 @@ class TfNavigationElement extends LitElement {
} }
} }
set_active_identity(event) {
send({action: 'setActiveIdentity', identity: event.srcElement.value});
}
create_identity(event) {
send({action: 'createIdentity'});
}
render_identity() {
if (this.identities?.length) {
return html`
<link type="text/css" rel="stylesheet" href="/static/w3.css" />
<select
@change=${this.set_active_identity}
class="w3-input w3-cyan"
style="flex: 0 1 auto; width: auto; display: inline-blocktext-overflow: ellipsis; overflow: hidden; white-space: nowrap">
${this.identities.map(x => html`<option ?selected=${x === this.identity}>${x}</option>`)}
</select>
`;
} else {
return html`
<link type="text/css" rel="stylesheet" href="/static/w3.css" />
<button
@click=${this.create_identity}
class="w3-button w3-blue">
Create an Identity
</button>
`;
}
}
/** /**
* TODOC * TODOC
* @returns * @returns
@ -291,7 +257,6 @@ class TfNavigationElement extends LitElement {
x, x,
])}</span ])}</span
> >
${this.render_identity()}
<span style="flex: 0 0; white-space: nowrap" <span style="flex: 0 0; white-space: nowrap"
>${this.render_login()}</span >${this.render_login()}</span
> >
@ -1160,17 +1125,11 @@ function api_setHash(hash) {
function _receive_websocket_message(message) { function _receive_websocket_message(message) {
if (message && message.action == 'session') { if (message && message.action == 'session') {
setStatusMessage('🟢 Executing...', kStatusColor); setStatusMessage('🟢 Executing...', kStatusColor);
let navigation = document.getElementsByTagName('tf-navigation')[0]; document.getElementsByTagName('tf-navigation')[0].credentials =
navigation.credentials = message.credentials; message.credentials;
navigation.identities = message.identities;
navigation.identity = message.identity;
} else if (message && message.action == 'permissions') { } else if (message && message.action == 'permissions') {
let navigation = document.getElementsByTagName('tf-navigation')[0]; document.getElementsByTagName('tf-navigation')[0].permissions =
navigation.permissions = message.permissions ?? {}; message.permissions ?? {};
} else if (message && message.action == 'identities') {
let navigation = document.getElementsByTagName('tf-navigation')[0];
navigation.identities = message.identities;
navigation.identity = message.identity;
} else if (message && message.action == 'ready') { } else if (message && message.action == 'ready') {
setStatusMessage(null); setStatusMessage(null);
if (window.location.hash) { if (window.location.hash) {

View File

@ -508,30 +508,6 @@ async function getProcessBlob(blobId, key, options) {
url: options?.url, url: options?.url,
}, },
}; };
process.sendIdentities = async function() {
process.app.send({
action: 'identities',
identities: await ssb.getIdentities(process?.credentials?.session?.name),
identity: await getActiveIdentity(process?.credentials?.session?.name, options.packageOwner, options.packageName),
});
};
process.setActiveIdentity = async function(identity) {
if (process?.credentials?.session?.name && options.packageOwner && options.packageName) {
await new Database(process?.credentials?.session?.name).set(`id:${options.packageOwner}:${options.packageName}`, identity);
}
process.sendIdentities();
};
process.createIdentity = async function() {
if (
process.credentials &&
process.credentials.session &&
process.credentials.session.name
) {
let id = ssb.createIdentity(process.credentials.session.name);
await process.sendIdentities();
return id;
}
}
if (process.credentials?.permissions?.administration) { if (process.credentials?.permissions?.administration) {
imports.core.globalSettingsDescriptions = function () { imports.core.globalSettingsDescriptions = function () {
let settings = Object.assign({}, k_global_settings); let settings = Object.assign({}, k_global_settings);
@ -602,7 +578,15 @@ async function getProcessBlob(blobId, key, options) {
Object.keys(ssb).map((key) => [key, ssb[key].bind(ssb)]) Object.keys(ssb).map((key) => [key, ssb[key].bind(ssb)])
); );
imports.ssb.port = tildefriends.ssb_port; imports.ssb.port = tildefriends.ssb_port;
imports.ssb.createIdentity = () => process.createIdentity(); imports.ssb.createIdentity = function () {
if (
process.credentials &&
process.credentials.session &&
process.credentials.session.name
) {
return ssb.createIdentity(process.credentials.session.name);
}
};
imports.ssb.addIdentity = function (id) { imports.ssb.addIdentity = function (id) {
if ( if (
process.credentials && process.credentials &&
@ -629,8 +613,6 @@ async function getProcessBlob(blobId, key, options) {
}); });
} }
}; };
imports.ssb.setActiveIdentity = id => process.setActiveIdentity(id);
imports.ssb.getActiveIdentity = () => getActiveIdentity(process.credentials?.session?.name, options.packageOwner, options.packageName);
imports.ssb.getOwnerIdentities = function () { imports.ssb.getOwnerIdentities = function () {
if (options.packageOwner) { if (options.packageOwner) {
return ssb.getIdentities(options.packageOwner); return ssb.getIdentities(options.packageOwner);
@ -1476,25 +1458,10 @@ function storePermission(user, packageOwner, packageName, permission, allow) {
} }
} }
async function getActiveIdentity(user, packageOwner, packageName) {
if (user && packageOwner && packageName) {
let id = await new Database(user).get(`id:${packageOwner}:${packageName}`);
if (!id) {
let ids = await ssb.getIdentities(user);
if (ids) {
id = ids[0];
}
}
return id;
}
}
export { export {
gGlobalSettings as globalSettings, gGlobalSettings as globalSettings,
setGlobalSettings, setGlobalSettings,
enableStats, enableStats,
invoke, invoke,
getSessionProcessBlob, getSessionProcessBlob,
getActiveIdentity,
}; };

View File

@ -474,7 +474,7 @@ static JSValue _httpd_auth_query(JSContext* context, JSValueConst this_val, int
JSValue settings_value = settings ? JS_ParseJSON(context, settings, strlen(settings), NULL) : JS_UNDEFINED; JSValue settings_value = settings ? JS_ParseJSON(context, settings, strlen(settings), NULL) : JS_UNDEFINED;
JSValue permissions = JS_GetPropertyStr(context, settings_value, "permissions"); JSValue permissions = JS_GetPropertyStr(context, settings_value, "permissions");
JSValue user_permissions = JS_GetPropertyStr(context, permissions, name_string); JSValue user_permissions = JS_GetPropertyStr(context, permissions, name_string);
int length = !JS_IsUndefined(user_permissions) ? tf_util_get_length(context, user_permissions) : 0 ; int length = tf_util_get_length(context, user_permissions);
for (int i = 0; i < length; i++) for (int i = 0; i < length; i++)
{ {
JSValue permission = JS_GetPropertyUint32(context, user_permissions, i); JSValue permission = JS_GetPropertyUint32(context, user_permissions, i);