mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-06 01:20:41 +00:00
dev: add user-friendly permission requests for apps/subdomains
This commit is contained in:
@@ -205,7 +205,33 @@ async function get_permission_description (permission) {
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
if ( parts[0] === 'apps-of-user' ) {
|
||||
const whoami = await puter.auth.whoami();
|
||||
// An app can't ask to see other users' apps
|
||||
if ( whoami.uuid !== parts[1] ) return null;
|
||||
|
||||
if ( parts[2] === 'read' ) {
|
||||
return i18n('perm_apps_read');
|
||||
}
|
||||
if ( parts[2] === 'write' ) {
|
||||
return i18n('perm_apps_write');
|
||||
}
|
||||
}
|
||||
|
||||
if ( parts[0] === 'subdomains-of-user' ) {
|
||||
const whoami = await puter.auth.whoami();
|
||||
// An app can't ask to see other users' subdomains
|
||||
if ( whoami.uuid !== parts[1] ) return null;
|
||||
|
||||
if ( parts[2] === 'read' ) {
|
||||
return i18n('perm_subdomains_read');
|
||||
}
|
||||
if ( parts[2] === 'write' ) {
|
||||
return i18n('perm_subdomains_write');
|
||||
}
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -526,6 +526,10 @@ const en = {
|
||||
'perm_folder_documents': 'your Documents folder',
|
||||
'perm_folder_pictures': 'your Pictures folder',
|
||||
'perm_folder_videos': 'your Videos folder',
|
||||
'perm_apps_read': 'see your apps',
|
||||
'perm_apps_write': 'manage your apps',
|
||||
'perm_subdomains_read': 'see your subdomains',
|
||||
'perm_subdomains_write': 'manage your subdomains',
|
||||
|
||||
'error_user_or_path_not_found': 'User or path not found.',
|
||||
'error_invalid_username': 'Invalid username.',
|
||||
|
||||
@@ -232,6 +232,70 @@ export default class Perms {
|
||||
return this.requestFolder_('Videos', 'write');
|
||||
}
|
||||
|
||||
/**
|
||||
* Request read access to the user's apps. If the user has already granted
|
||||
* this permission the user will not be prompted and `true` will be returned.
|
||||
* If the user grants permission `true` will be returned. If the user does
|
||||
* not allow access `false` will be returned.
|
||||
*
|
||||
* @return {boolean} Whether read access to apps was granted
|
||||
*/
|
||||
async requestReadApps () {
|
||||
const whoami = await this.puter.auth.whoami();
|
||||
const granted = await this.puter.ui.requestPermission({
|
||||
permission: `apps-of-user:${whoami.uuid}:read`,
|
||||
});
|
||||
return granted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request write (manage) access to the user's apps. If the user has already
|
||||
* granted this permission the user will not be prompted and `true` will be
|
||||
* returned. If the user grants permission `true` will be returned. If the
|
||||
* user does not allow access `false` will be returned.
|
||||
*
|
||||
* @return {boolean} Whether manage access to apps was granted
|
||||
*/
|
||||
async requestManageApps () {
|
||||
const whoami = await this.puter.auth.whoami();
|
||||
const granted = await this.puter.ui.requestPermission({
|
||||
permission: `apps-of-user:${whoami.uuid}:write`,
|
||||
});
|
||||
return granted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request read access to the user's subdomains. If the user has already
|
||||
* granted this permission the user will not be prompted and `true` will be
|
||||
* returned. If the user grants permission `true` will be returned. If the
|
||||
* user does not allow access `false` will be returned.
|
||||
*
|
||||
* @return {boolean} Whether read access to subdomains was granted
|
||||
*/
|
||||
async requestReadSubdomains () {
|
||||
const whoami = await this.puter.auth.whoami();
|
||||
const granted = await this.puter.ui.requestPermission({
|
||||
permission: `subdomains-of-user:${whoami.uuid}:read`,
|
||||
});
|
||||
return granted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Request write (manage) access to the user's subdomains. If the user has
|
||||
* already granted this permission the user will not be prompted and `true`
|
||||
* will be returned. If the user grants permission `true` will be returned.
|
||||
* If the user does not allow access `false` will be returned.
|
||||
*
|
||||
* @return {boolean} Whether manage access to subdomains was granted
|
||||
*/
|
||||
async requestManageSubdomains () {
|
||||
const whoami = await this.puter.auth.whoami();
|
||||
const granted = await this.puter.ui.requestPermission({
|
||||
permission: `subdomains-of-user:${whoami.uuid}:write`,
|
||||
});
|
||||
return granted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal helper to request access to a user's special folder.
|
||||
* @private
|
||||
@@ -246,7 +310,7 @@ export default class Perms {
|
||||
// Check if we already have access by trying to stat the folder
|
||||
try {
|
||||
await this.puter.fs.stat({ path: folderPath });
|
||||
|
||||
|
||||
// If we can stat the folder, we have at least read access
|
||||
if ( accessLevel !== 'write' ) {
|
||||
return folderPath;
|
||||
|
||||
Reference in New Issue
Block a user