Skip to content

Commit

Permalink
restrict
Browse files Browse the repository at this point in the history
  • Loading branch information
gempir committed Feb 14, 2024
1 parent f9c35b9 commit f5347d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
11 changes: 11 additions & 0 deletions internal/server/overlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"strings"

"github.com/gempir/gempbot/internal/api"
"github.com/gempir/gempbot/internal/dto"
"github.com/gempir/gempbot/internal/store"
"github.com/gempir/gempbot/internal/ysweet"
"github.com/google/uuid"
Expand Down Expand Up @@ -60,6 +61,11 @@ func (a *Api) OverlayHandler(w http.ResponseWriter, r *http.Request) {
overlays := a.db.GetOverlays(userID)
api.WriteJson(w, overlays, http.StatusOK)
} else if r.Method == http.MethodPost {
if authResp.Data.UserID != dto.GEMPIR_USER_ID {
http.Error(w, "Only gempir can", http.StatusForbidden)
return
}

overlay := store.Overlay{}
overlay.OwnerTwitchID = userID
overlay.ID = shortid.MustGenerate()
Expand All @@ -79,6 +85,11 @@ func (a *Api) OverlayHandler(w http.ResponseWriter, r *http.Request) {
api.WriteJson(w, overlay, http.StatusCreated)

} else if r.Method == http.MethodDelete {
if authResp.Data.UserID != dto.GEMPIR_USER_ID {
http.Error(w, "Only gempir can", http.StatusForbidden)
return
}

if r.URL.Query().Get("id") == "" {
http.Error(w, "missing id", http.StatusBadRequest)
}
Expand Down
13 changes: 5 additions & 8 deletions web/src/components/Overlay/OverlaysPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,28 @@ import Link from "next/link";
import { useOverlays } from "../../hooks/useOverlays";
import { useUserConfig } from "../../hooks/useUserConfig";

const gempirId = "77829817";

export function OverlaysPage() {
const [overlays, addOverlay, deleteOverlay, errorMessage, loading] = useOverlays();
const [user] = useUserConfig();
const isGempir = user?.Protected.CurrentUserID === gempirId;

return <div className="relative w-full h-[100vh] p-4">
<div className="p-4 bg-gray-800 rounded shadow max-w-[800px]">
<div className="group">
<button disabled={!isGempir} onClick={addOverlay} className="bg-green-700 hover:bg-green-600 p-2 rounded shadow block cursor-pointer">Add Overlay</button>
{!isGempir && <span className="absolute z-50 hidden mt-2 p-2 w-48 text-center bg-black/75 text-white rounded tooltip-text group-hover:block pointer-events-none">
<button onClick={addOverlay} className="bg-green-700 hover:bg-green-600 p-2 rounded shadow block cursor-pointer">Add Overlay</button>
{<span className="absolute z-50 hidden mt-2 p-2 w-48 text-center bg-black/75 text-white rounded tooltip-text group-hover:block pointer-events-none">
Only gempir can
</span>}
</div>
<div className="mt-5">
{overlays.map(overlay => <div key={overlay.ID} className="flex items-center justify-between p-4 bg-gray-900">
<div>
<div className="group">
<button className="bg-red-700 hover:bg-red-600 p-2 rounded shadow block cursor-pointer" disabled={!isGempir} onClick={() => {
<button className="bg-red-700 hover:bg-red-600 p-2 rounded shadow block cursor-pointer" onClick={() => {
confirm("Are you sure you want to delete this overlay?") && deleteOverlay(overlay.ID)
}}>Delete</button>
{!isGempir && <span className="absolute z-50 hidden mt-2 p-2 w-48 text-center bg-black/75 text-white rounded tooltip-text group-hover:block pointer-events-none">
<span className="absolute z-50 hidden mt-2 p-2 w-48 text-center bg-black/75 text-white rounded tooltip-text group-hover:block pointer-events-none">
Only gempir can
</span>}
</span>
</div>
</div>
<div>{overlay.ID}</div>
Expand Down

0 comments on commit f5347d4

Please sign in to comment.