diff --git a/CHANGELOG.md b/CHANGELOG.md
index daf8e0d..e12bc36 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [next]
+### Added
+
+- Admin users can now delete devices from the "all devices" page (issue [#57](https://github.com/Place1/wg-access-server/issues/57))
+
### Bug Fixes
- Fixes website routing to solve 404s (issue [#56](https://github.com/Place1/wg-access-server/issues/56))
diff --git a/internal/services/device_service.go b/internal/services/device_service.go
index c9eb958..8a63609 100644
--- a/internal/services/device_service.go
+++ b/internal/services/device_service.go
@@ -56,7 +56,17 @@ func (d *DeviceService) DeleteDevice(ctx context.Context, req *proto.DeleteDevic
return nil, status.Errorf(codes.PermissionDenied, "not authenticated")
}
- if err := d.DeviceManager.DeleteDevice(user.Subject, req.GetName()); err != nil {
+ deviceOwner := user.Subject
+
+ if req.Owner != nil {
+ if user.Claims.Contains("admin") {
+ deviceOwner = req.Owner.Value
+ } else {
+ return nil, status.Errorf(codes.PermissionDenied, "must be an admin")
+ }
+ }
+
+ if err := d.DeviceManager.DeleteDevice(deviceOwner, req.GetName()); err != nil {
ctxlogrus.Extract(ctx).Error(err)
return nil, status.Errorf(codes.Internal, "failed to delete device")
}
diff --git a/proto/devices.proto b/proto/devices.proto
index d54a5b3..435fcc2 100644
--- a/proto/devices.proto
+++ b/proto/devices.proto
@@ -2,6 +2,7 @@ syntax = "proto3";
package proto;
+import "google/protobuf/wrappers.proto";
import "google/protobuf/timestamp.proto";
import "google/protobuf/empty.proto";
@@ -45,6 +46,11 @@ message ListDevicesRes {
message DeleteDeviceReq {
string name = 1;
+
+ // admin's may delete a device owned
+ // by someone other than the current user
+ // if empty, defaults to the current user
+ google.protobuf.StringValue owner = 2;
}
message ListAllDevicesReq {
diff --git a/proto/proto/devices.pb.go b/proto/proto/devices.pb.go
index f304655..8da043d 100644
--- a/proto/proto/devices.pb.go
+++ b/proto/proto/devices.pb.go
@@ -9,6 +9,7 @@ import (
proto "github.com/golang/protobuf/proto"
empty "github.com/golang/protobuf/ptypes/empty"
timestamp "github.com/golang/protobuf/ptypes/timestamp"
+ wrappers "github.com/golang/protobuf/ptypes/wrappers"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
@@ -279,10 +280,14 @@ func (m *ListDevicesRes) GetItems() []*Device {
}
type DeleteDeviceReq struct {
- Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
- XXX_NoUnkeyedLiteral struct{} `json:"-"`
- XXX_unrecognized []byte `json:"-"`
- XXX_sizecache int32 `json:"-"`
+ Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
+ // admin's may delete a device owned
+ // by someone other than the current user
+ // if empty, defaults to the current user
+ Owner *wrappers.StringValue `protobuf:"bytes,2,opt,name=owner,proto3" json:"owner,omitempty"`
+ XXX_NoUnkeyedLiteral struct{} `json:"-"`
+ XXX_unrecognized []byte `json:"-"`
+ XXX_sizecache int32 `json:"-"`
}
func (m *DeleteDeviceReq) Reset() { *m = DeleteDeviceReq{} }
@@ -317,6 +322,13 @@ func (m *DeleteDeviceReq) GetName() string {
return ""
}
+func (m *DeleteDeviceReq) GetOwner() *wrappers.StringValue {
+ if m != nil {
+ return m.Owner
+ }
+ return nil
+}
+
type ListAllDevicesReq struct {
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
@@ -400,40 +412,42 @@ func init() {
func init() { proto.RegisterFile("devices.proto", fileDescriptor_6d27ec3f2c0e2043) }
var fileDescriptor_6d27ec3f2c0e2043 = []byte{
- // 513 bytes of a gzipped FileDescriptorProto
- 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xdb, 0x6e, 0xd3, 0x40,
- 0x10, 0x8d, 0x93, 0xe6, 0xe2, 0x49, 0x5c, 0xe8, 0x04, 0xaa, 0x95, 0x01, 0x35,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0xc8, 0xf4, 0xd5, 0x9e, 0xff, 0x0d, 0xfe,
+ 0x3b, 0xc7, 0x14, 0x25, 0xfe, 0x79, 0x9c, 0x71, 0xfd, 0xad, 0x73, 0xc6, 0xc7, 0x3b, 0xfb, 0xfb,
+ 0x2c, 0x79, 0x92, 0xcf, 0xbe, 0xb2, 0x74, 0x8e, 0xe6, 0x9d, 0xf4, 0xfb, 0x70, 0x58, 0x4d, 0x34,
+ 0x49, 0xd3, 0xda, 0x98, 0xcf, 0x77, 0xc5, 0x7f, 0x9b, 0x74, 0xfc, 0x63, 0x0f, 0x3a, 0xa6, 0x86,
+ 0x3c, 0x01, 0x7b, 0x4d, 0x90, 0xf4, 0x4d, 0xbc, 0xce, 0xd4, 0xdb, 0xbc, 0xc3, 0x6f, 0x90, 0x97,
+ 0xe0, 0xd4, 0xf8, 0x90, 0xfb, 0xc6, 0xdf, 0xa4, 0xe8, 0xdd, 0x29, 0x0b, 0xbf, 0x41, 0x5e, 0x41,
+ 0xaf, 0xce, 0x89, 0x1c, 0xad, 0xef, 0xdf, 0x80, 0xe7, 0x1d, 0xed, 0x90, 0xb9, 0xa8, 0xbe, 0x6d,
+ 0xbf, 0x41, 0xde, 0xe8, 0x05, 0xdd, 0x3e, 0x39, 0xa1, 0xb5, 0x66, 0x1b, 0x94, 0xbc, 0xdf, 0x39,
+ 0xc2, 0x6f, 0x4c, 0xdb, 0xca, 0x7a, 0xfa, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x66, 0x8c, 0x07, 0x7b,
+ 0x9c, 0x04, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
diff --git a/website/src/Api.ts b/website/src/Api.ts
index 2ae6a52..358c87b 100644
--- a/website/src/Api.ts
+++ b/website/src/Api.ts
@@ -7,7 +7,7 @@ const backend = window.location.origin + '/api';
export const grpc = {
server: new Server(backend),
devices: new Devices(backend),
-}
+};
// https://github.com/SafetyCulture/grpc-web-devtools
const devtools = (window as any).__GRPCWEB_DEVTOOLS__;
diff --git a/website/src/App.tsx b/website/src/App.tsx
index 89d399c..ac4963a 100644
--- a/website/src/App.tsx
+++ b/website/src/App.tsx
@@ -2,11 +2,7 @@ import React from 'react';
import CssBaseline from '@material-ui/core/CssBaseline';
import Box from '@material-ui/core/Box';
import Navigation from './components/Navigation';
-import {
- BrowserRouter as Router,
- Switch,
- Route,
-} from 'react-router-dom';
+import { BrowserRouter as Router, Switch, Route } from 'react-router-dom';
import { observer } from 'mobx-react';
import { grpc } from './Api';
import { AppState } from './AppState';
@@ -15,14 +11,13 @@ import { AllDevices } from './pages/admin/AllDevices';
@observer
export class App extends React.Component {
-
async componentDidMount() {
AppState.info = await grpc.server.info({});
}
render() {
if (!AppState.info) {
- return
loading...
+ return loading...
;
}
return (
@@ -31,11 +26,11 @@ export class App extends React.Component {
- {AppState.info.isAdmin &&
+ {AppState.info.isAdmin && (
<>
>
- }
+ )}
diff --git a/website/src/AppState.ts b/website/src/AppState.ts
index d4a4f7a..3c43efb 100644
--- a/website/src/AppState.ts
+++ b/website/src/AppState.ts
@@ -2,10 +2,8 @@ import { observable } from 'mobx';
import { InfoRes } from './sdk/server_pb';
class GlobalAppState {
-
@observable
info?: InfoRes.AsObject;
-
}
export const AppState = new GlobalAppState();
@@ -15,5 +13,5 @@ console.info('see global app state by typing "window.AppState"');
Object.assign(window as any, {
get AppState() {
return JSON.parse(JSON.stringify(AppState));
- }
+ },
});
diff --git a/website/src/Util.ts b/website/src/Util.ts
index ee298ba..f3fbd4f 100644
--- a/website/src/Util.ts
+++ b/website/src/Util.ts
@@ -1,8 +1,8 @@
-import formatDistance from "date-fns/formatDistance";
+import formatDistance from 'date-fns/formatDistance';
import timestamp_pb from 'google-protobuf/google/protobuf/timestamp_pb';
-import { toDate } from "./Api";
-import { fromResource, lazyObservable } from "mobx-utils";
-import { toast } from "./components/Toast";
+import { toDate } from './Api';
+import { fromResource, lazyObservable } from 'mobx-utils';
+import { toast } from './components/Toast';
export function sleep(seconds: number) {
return new Promise((resolve) => {
@@ -22,7 +22,7 @@ export function lastSeen(timestamp: timestamp_pb.Timestamp.AsObject | undefined)
}
export function lazy(cb: () => Promise) {
- const resource = lazyObservable(async sink => {
+ const resource = lazyObservable(async (sink) => {
sink(await cb());
});
@@ -41,7 +41,7 @@ export function autorefresh(seconds: number, cb: () => Promise) {
let sink: ((next: T) => void) | undefined;
const resource = fromResource(
- async s => {
+ async (s) => {
sink = s;
running = true;
while (running) {
@@ -51,7 +51,7 @@ export function autorefresh(seconds: number, cb: () => Promise) {
},
() => {
running = false;
- }
+ },
);
return {
diff --git a/website/src/components/AddDevice.tsx b/website/src/components/AddDevice.tsx
index e8cdbc0..ff15467 100644
--- a/website/src/components/AddDevice.tsx
+++ b/website/src/components/AddDevice.tsx
@@ -28,7 +28,6 @@ interface Props {
@observer
export class AddDevice extends React.Component {
-
@observable
dialogOpen = false;
@@ -81,25 +80,22 @@ export class AddDevice extends React.Component {
this.configFileUri = URL.createObjectURL(new Blob([configFile]));
this.dialogOpen = true;
this.reset();
-
} catch (error) {
console.log(error);
// TODO: unwrap grpc error message
this.error = 'failed';
}
- }
+ };
reset = () => {
this.formState.name = '';
- }
+ };
render() {
return (
<>
-
+
-