Skip to content

Commit 51c5cf4

Browse files
committed
Get basic modal view for editing/creating a new subuser working
1 parent 8d52e2e commit 51c5cf4

File tree

13 files changed

+293
-186
lines changed

13 files changed

+293
-186
lines changed

app/Http/Controllers/Api/Client/ClientController.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Pterodactyl\Http\Controllers\Api\Client;
44

55
use Pterodactyl\Models\User;
6-
use Illuminate\Support\Collection;
76
use Pterodactyl\Models\Permission;
87
use Pterodactyl\Repositories\Eloquent\ServerRepository;
98
use Pterodactyl\Transformers\Api\Client\ServerTransformer;
@@ -72,16 +71,10 @@ public function index(GetServersRequest $request): array
7271
*/
7372
public function permissions()
7473
{
75-
$permissions = Permission::permissions()->map(function ($values, $key) {
76-
return Collection::make($values)->map(function ($permission) use ($key) {
77-
return $key . '.' . $permission;
78-
})->values()->toArray();
79-
})->flatten();
80-
8174
return [
8275
'object' => 'system_permissions',
8376
'attributes' => [
84-
'permissions' => $permissions,
77+
'permissions' => Permission::permissions(),
8578
],
8679
];
8780
}

app/Models/Permission.php

Lines changed: 58 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -98,105 +98,90 @@ class Permission extends Validable
9898
*/
9999
protected static $permissions = [
100100
'websocket' => [
101-
// Allows the user to connect to the server websocket, this will give them
102-
// access to view the console output as well as realtime server stats (CPU
103-
// and Memory usage).
104-
'*',
101+
'description' => 'Allows the user to connect to the server websocket, giving them access to view console output and realtime server stats.',
102+
'keys' => [
103+
'*' => 'Gives user full read access to the websocket.',
104+
],
105105
],
106106

107107
'control' => [
108-
// Allows the user to send data to the server console process. A user with this
109-
// permission will not be able to stop the server directly by issuing the specified
110-
// stop command for the Egg, however depending on plugins and server configuration
111-
// they may still be able to control the server power state.
112-
'console', // power.send-command
113-
114-
// Allows the user to start/stop/restart/kill the server process.
115-
'start', // power.power-start
116-
'stop', // power.power-stop
117-
'restart', // power.power-restart
118-
'kill', // power.power-kill
108+
'description' => 'Permissions that control a user\'s ability to control the power state of a server, or send commands.',
109+
'keys' => [
110+
'console' => 'Allows a user to send commands to the server instance via the console.',
111+
'start' => 'Allows a user to start the server if it is stopped.',
112+
'stop' => 'Allows a user to stop a server if it is running.',
113+
'restart' => 'Allows a user to perform a server restart. This allows them to start the server if it is offline, but not put the server in a completely stopped state.',
114+
'kill' => 'Allows a user to terminate a server process.',
115+
],
119116
],
120117

121118
'user' => [
122-
// Allows a user to create a new user assigned to the server. They will not be able
123-
// to assign any permissions they do not already have on their account as well.
124-
'create', // subuser.create-subuser
125-
'read', // subuser.list-subusers, subuser.view-subuser
126-
'update', // subuser.edit-subuser
127-
'delete', // subuser.delete-subuser
119+
'description' => 'Permissions that allow a user to manage other subusers on a server. They will never be able to edit their own account, or assign permissions they do not have themselves.',
120+
'keys' => [
121+
'create' => 'Allows a user to create new subusers for the server.',
122+
'read' => 'Allows the user to view subusers and their permissions for the server.',
123+
'update' => 'Allows a user to modify other subusers.',
124+
'delete' => 'Allows a user to delete a subuser from the server.',
125+
],
128126
],
129127

130128
'file' => [
131-
// Allows a user to create additional files and folders either via the Panel,
132-
// or via a direct upload.
133-
'create', // files.create-files, files.upload-files, files.copy-files, files.move-files
134-
135-
// Allows a user to view the contents of a directory as well as read the contents
136-
// of a given file. A user with this permission will be able to download files
137-
// as well.
138-
'read', // files.list-files, files.download-files
139-
140-
// Allows a user to update the contents of an existing file or directory.
141-
'update', // files.edit-files, files.save-files
142-
143-
// Allows a user to delete a file or directory.
144-
'delete', // files.delete-files
145-
146-
// Allows a user to archive the contents of a directory as well as decompress existing
147-
// archives on the system.
148-
'archive', // files.compress-files, files.decompress-files
149-
150-
// Allows the user to connect and manage server files using their account
151-
// credentials and a SFTP client.
152-
'sftp', // files.access-sftp
129+
'description' => 'Permissions that control a user\'s ability to modify the filesystem for this server.',
130+
'keys' => [
131+
'create' => 'Allows a user to create additional files and folders via the Panel or direct upload.',
132+
'read' => 'Allows a user to view the contents of a directory and read the contents of a file. Users with this permission can also download files.',
133+
'update' => 'Allows a user to update the contents of an existing file or directory.',
134+
'delete' => 'Allows a user to delete files or directories.',
135+
'archive' => 'Allows a user to archive the contents of a directory as well as decompress existing archives on the system.',
136+
'sftp' => 'Allows a user to connect to SFTP and manage server files using the other assigned file permissions.',
137+
],
153138
],
154139

155140
// Controls permissions for editing or viewing a server's allocations.
156141
'allocation' => [
157-
'read', // server.view-allocations
158-
'update', // server.edit-allocation
142+
'description' => 'Permissions that control a user\'s ability to modify the port allocations for this server.',
143+
'keys' => [
144+
'read' => 'Allows a user to view the allocations assigned to this server.',
145+
'update' => 'Allows a user to modify the allocations assigned to this server.',
146+
],
159147
],
160148

161149
// Controls permissions for editing or viewing a server's startup parameters.
162150
'startup' => [
163-
'read', // server.view-startup
164-
'update', // server.edit-startup
151+
'description' => 'Permissions that control a user\'s ability to view this server\'s startup parameters.',
152+
'keys' => [
153+
'read' => '',
154+
'update' => '',
155+
],
165156
],
166157

167158
'database' => [
168-
// Allows a user to create a new database for a server.
169-
'create', // database.create-database
170-
171-
// Allows a user to view the databases associated with the server. If they do not also
172-
// have the view_password permission they will only be able to see the connection address
173-
// and the name of the user.
174-
'read', // database.view-databases
175-
176-
// Allows a user to rotate the password on a database instance. If the user does not
177-
// alow have the view_password permission they will not be able to see the updated password
178-
// anywhere, but it will still be rotated.
179-
'update', // database.reset-db-password
180-
181-
// Allows a user to delete a database instance.
182-
'delete', // database.delete-database
183-
184-
// Allows a user to view the password associated with a database instance for the
185-
// server. Note that a user without this permission may still be able to access these
186-
// credentials by viewing files or the console.
187-
'view_password', // database.reset-db-password
159+
'description' => 'Permissions that control a user\'s access to the database management for this server.',
160+
'keys' => [
161+
'create' => 'Allows a user to create a new database for this server.',
162+
'read' => 'Allows a user to view the database associated with this server.',
163+
'update' => 'Allows a user to rotate the password on a database instance. If the user does not have the view_password permission they will not see the updated password.',
164+
'delete' => 'Allows a user to remove a database instance from this server.',
165+
'view_password' => 'Allows a user to view the password associated with a database instance for this server.',
166+
],
188167
],
189168

190169
'schedule' => [
191-
'create', // task.create-schedule
192-
'read', // task.view-schedule, task.list-schedules
193-
'update', // task.edit-schedule, task.queue-schedule, task.toggle-schedule
194-
'delete', // task.delete-schedule
170+
'description' => 'Permissions that control a user\'s access to the schedule management for this server.',
171+
'keys' => [
172+
'create' => '', // task.create-schedule
173+
'read' => '', // task.view-schedule, task.list-schedules
174+
'update' => '', // task.edit-schedule, task.queue-schedule, task.toggle-schedule
175+
'delete' => '', // task.delete-schedule
176+
],
195177
],
196178

197179
'settings' => [
198-
'rename',
199-
'reinstall',
180+
'description' => 'Permissions that control a user\'s access to the settings for this server.',
181+
'keys' => [
182+
'rename' => '',
183+
'reinstall' => '',
184+
],
200185
],
201186
];
202187

resources/scripts/api/getSystemPermissions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { SubuserPermission } from '@/state/server/subusers';
1+
import { PanelPermissions } from '@/state/permissions';
22
import http from '@/api/http';
33

4-
export default (): Promise<SubuserPermission[]> => {
4+
export default (): Promise<PanelPermissions> => {
55
return new Promise((resolve, reject) => {
66
http.get(`/api/client/permissions`)
77
.then(({ data }) => resolve(data.attributes.permissions))

resources/scripts/components/dashboard/AccountApiContainer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export default () => {
9595
>
9696
<FontAwesomeIcon
9797
icon={faTrashAlt}
98-
className={'text-neutral-400 hover:text-red-400 transition-color duration-150'}
98+
className={'text-neutral-400 hover:text-red-400 transition-colors duration-150'}
9999
/>
100100
</button>
101101
</div>

resources/scripts/components/elements/ContentBox.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import * as React from 'react';
22
import classNames from 'classnames';
33
import FlashMessageRender from '@/components/FlashMessageRender';
4+
import SpinnerOverlay from '@/components/elements/SpinnerOverlay';
45

56
type Props = Readonly<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement> & {
67
title?: string;
78
borderColor?: string;
89
showFlashes?: string | boolean;
10+
showLoadingOverlay?: boolean;
911
}>;
1012

11-
const ContentBox = ({ title, borderColor, showFlashes, children, ...props }: Props) => (
13+
const ContentBox = ({ title, borderColor, showFlashes, showLoadingOverlay, children, ...props }: Props) => (
1214
<div {...props}>
1315
{title && <h2 className={'text-neutral-300 mb-4 px-4'}>{title}</h2>}
1416
{showFlashes &&
@@ -20,6 +22,7 @@ const ContentBox = ({ title, borderColor, showFlashes, children, ...props }: Pro
2022
<div className={classNames('bg-neutral-700 p-4 rounded shadow-lg relative', borderColor, {
2123
'border-t-4': !!borderColor,
2224
})}>
25+
<SpinnerOverlay visible={showLoadingOverlay || false}/>
2326
{children}
2427
</div>
2528
</div>

resources/scripts/components/elements/TitledGreyBox.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ import { IconProp } from '@fortawesome/fontawesome-svg-core';
44

55
interface Props {
66
icon?: IconProp;
7-
title: string;
7+
title: string | React.ReactNode;
88
className?: string;
99
children: React.ReactNode;
1010
}
1111

1212
const TitledGreyBox = ({ icon, title, children, className }: Props) => (
1313
<div className={`rounded shadow-md bg-neutral-700 ${className}`}>
1414
<div className={'bg-neutral-900 rounded-t p-3 border-b border-black'}>
15-
<p className={'text-sm uppercase'}>
16-
{icon && <FontAwesomeIcon icon={icon} className={'mr-2 text-neutral-300'}/>}{title}
17-
</p>
15+
{typeof title === 'string' ?
16+
<p className={'text-sm uppercase'}>
17+
{icon && <FontAwesomeIcon icon={icon} className={'mr-2 text-neutral-300'}/>}{title}
18+
</p>
19+
:
20+
title
21+
}
1822
</div>
1923
<div className={'p-3'}>
2024
{children}

resources/scripts/components/server/schedules/ScheduleTaskRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ export default ({ schedule, task, onTaskUpdated, onTaskRemoved }: Props) => {
7878
<button
7979
type={'button'}
8080
aria-label={'Edit scheduled task'}
81-
className={'block text-sm p-2 text-neutral-500 hover:text-neutral-100 transition-color duration-150 mr-4'}
81+
className={'block text-sm p-2 text-neutral-500 hover:text-neutral-100 transition-colors duration-150 mr-4'}
8282
onClick={() => setIsEditing(true)}
8383
>
8484
<FontAwesomeIcon icon={faPencilAlt}/>
8585
</button>
8686
<button
8787
type={'button'}
8888
aria-label={'Delete scheduled task'}
89-
className={'block text-sm p-2 text-neutral-500 hover:text-red-600 transition-color duration-150'}
89+
className={'block text-sm p-2 text-neutral-500 hover:text-red-600 transition-colors duration-150'}
9090
onClick={() => setVisible(true)}
9191
>
9292
<FontAwesomeIcon icon={faTrashAlt}/>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import React, { useState } from 'react';
2+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3+
import { faUserPlus } from '@fortawesome/free-solid-svg-icons/faUserPlus';
4+
import EditSubuserModal from '@/components/server/users/EditSubuserModal';
5+
6+
export default () => {
7+
const [ visible, setVisible ] = useState(false);
8+
9+
return (
10+
<>
11+
{visible && <EditSubuserModal
12+
appear={true}
13+
visible={true}
14+
onDismissed={() => setVisible(false)}
15+
/>}
16+
<button className={'btn btn-primary btn-sm'} onClick={() => setVisible(true)}>
17+
<FontAwesomeIcon icon={faUserPlus} className={'mr-1'}/> New User
18+
</button>
19+
</>
20+
);
21+
};

0 commit comments

Comments
 (0)