From b6afce22b730a9ef05509594aba8cd23a28c26f5 Mon Sep 17 00:00:00 2001 From: Nick Tampakas Date: Thu, 8 Feb 2024 13:59:58 +0200 Subject: [PATCH 01/14] Add workflow --- .github/workflows/ephemeral.yml | 48 +++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/ephemeral.yml diff --git a/.github/workflows/ephemeral.yml b/.github/workflows/ephemeral.yml new file mode 100644 index 00000000..3f5da925 --- /dev/null +++ b/.github/workflows/ephemeral.yml @@ -0,0 +1,48 @@ +name: Ephemeral +on: + schedule: + - cron: '0 */6 * * *' + workflow_dispatch: + inputs: + action: + description: "Action" + required: true + default: "spawn" + type: choice + options: + - spawn + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false + +jobs: + deploy: + timeout-minutes: 5 + runs-on: ubuntu-latest + env: + DATA: ${{ github.event.inputs.action || 'maintenance' }} + permissions: + id-token: write + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::490752553772:role/bandada-ephemeral-deploy-slc + role-duration-seconds: 900 + aws-region: eu-central-1 + + - name: Launch instance + run: | + .github/scripts/run.sh ${{ env.DATA }} $GITHUB_REF_NAME $GITHUB_TRIGGERING_ACTOR $GITHUB_SHA + + - name: Instance IP + run: | + .github/scripts/get_ip.sh ${{ env.DATA }} $GITHUB_TRIGGERING_ACTOR From e7f358f90dce717daf903e1a9e6d2ff3b37d933c Mon Sep 17 00:00:00 2001 From: Nick Tampakas Date: Thu, 8 Feb 2024 14:01:25 +0200 Subject: [PATCH 02/14] Add auxiliary scripts to spawn/configure/manage the ephemeral instance --- .github/scripts/cloud-init.sh | 36 +++++++++++++++++++++++++++ .github/scripts/get_ip.sh | 16 ++++++++++++ .github/scripts/run.sh | 47 +++++++++++++++++++++++++++++++++++ 3 files changed, 99 insertions(+) create mode 100755 .github/scripts/cloud-init.sh create mode 100755 .github/scripts/get_ip.sh create mode 100755 .github/scripts/run.sh diff --git a/.github/scripts/cloud-init.sh b/.github/scripts/cloud-init.sh new file mode 100755 index 00000000..4c067184 --- /dev/null +++ b/.github/scripts/cloud-init.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +set -eux +trap 'poweroff' TERM EXIT INT + +Repo=$(curl http://169.254.169.254/latest/meta-data/tags/instance/Repo) +Branch=$(curl http://169.254.169.254/latest/meta-data/tags/instance/Branch) + +Local_IP=$(curl http://169.254.169.254/latest/meta-data/local-ipv4) + +# Install pkgs +apt-get update +apt-get install -y net-tools +for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done +install -m 0755 -d /etc/apt/keyrings +curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg +chmod a+r /etc/apt/keyrings/docker.gpg +echo \ + "deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + "$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null +apt-get update +apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin +usermod -aG docker ubuntu + +su -P ubuntu -c "git clone -b $Branch --single-branch https://github.com/ntampakas/$Repo.git /home/ubuntu/$Repo" +su -P ubuntu -c "cp /home/ubuntu/$Repo/apps/api/.env.example /home/ubuntu/$Repo/apps/api/.env" +su -P ubuntu -c "sed -i 's/\(DB_TYPE=\).*/\1postgres/' /home/ubuntu/$Repo/apps/api/.env" +su -P ubuntu -c "sed -i 's/\(DB_URL=\).*/\1postgres:\/\/root:helloworld\@postgres:5432\/bandada/' /home/ubuntu/$Repo/apps/api/.env" + +su -P ubuntu -c "rm /home/ubuntu/$Repo/apps/{client,dashboard}/.env.production /home/ubuntu/$Repo/apps/{client,dashboard}/.env.staging" +su -P ubuntu -c "sed -i 's/localhost/$Local_IP/g' /home/ubuntu/$Repo/apps/{client,dashboard}/.env.local" + +su -P ubuntu -c "cd /home/ubuntu/$Repo ; docker compose up -d" + +sleep 6h diff --git a/.github/scripts/get_ip.sh b/.github/scripts/get_ip.sh new file mode 100755 index 00000000..7ca23774 --- /dev/null +++ b/.github/scripts/get_ip.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -eux + +TRIGGER=$1 +ACTOR=$2 +VPC="vpc-07d12b28fd72d152e" + +# Stop here in schedule +[ ! $TRIGGER = "maintenance" ] || exit 0 + +sleep 10 + +EC2_IP=$(aws ec2 describe-instances --filters "Name=instance-state-name,Values=[running]" "Name=tag:Name,Values='bandada-ephemeral-$ACTOR-*'" "Name=network-interface.vpc-id,Values=[$VPC]" --query "Reservations[*].Instances[*].[NetworkInterfaces[*].[PrivateIpAddress]]" --output text) + +echo "URL: http://$EC2_IP:3001" diff --git a/.github/scripts/run.sh b/.github/scripts/run.sh new file mode 100755 index 00000000..6e9edae0 --- /dev/null +++ b/.github/scripts/run.sh @@ -0,0 +1,47 @@ +#!/bin/sh + +set -eux + +TRIGGER=$1 +BRANCH=$2 +ACTOR=$3 +SHA=$4 +AMI="ami-04e601abe3e1a910f" +SG="sg-04d8c2eb4beca2de9" +SUBNET="subnet-066cf21c696ef55c8" +VPC="vpc-07d12b28fd72d152e" + +# Kill old instances +CURRENT_TIME_EPOCH=$(date -d `date -Is` +"%s") +EC2=$(aws ec2 describe-instances --filters "Name=instance-state-name,Values=[running]" "Name=tag:Name,Values='bandada-ephemeral-*'" "Name=network-interface.vpc-id,Values=[$VPC]" --query "Reservations[*].Instances[*].InstanceId" --output text) +for i in $EC2; do + EC2_LAUNCH_TIME=$(aws ec2 describe-instances --instance-ids $i --query 'Reservations[*].Instances[*].LaunchTime' --output text) + LAUNCH_TIME_EPOCH=$(date -d $EC2_LAUNCH_TIME +"%s") + diff=$(expr $CURRENT_TIME_EPOCH - $LAUNCH_TIME_EPOCH) + + if [ $diff -gt 21600 ]; then + aws ec2 terminate-instances --instance-ids $i + fi +done + +# Stop here in schedule +[ ! $TRIGGER = "maintenance" ] || exit 0 + +# Check if actor ec2 exists +ACTOR_EC2=$(aws ec2 describe-instances --filters "Name=instance-state-name,Values=[running]" "Name=tag:Name,Values='bandada-ephemeral-$ACTOR-*'" "Name=network-interface.vpc-id,Values=[$VPC]" --query "Reservations[*].Instances[*].InstanceId" --output text) + +[ -z $ACTOR_EC2 ] || aws ec2 terminate-instances --instance-ids $ACTOR_EC2 + +# Launch new instance +aws ec2 run-instances \ + --user-data "file://.github/scripts/cloud-init.sh" \ + --image-id $AMI \ + --count 1 \ + --instance-type t3a.large \ + --key-name bandada \ + --security-group-ids $SG \ + --subnet-id $SUBNET \ + --block-device-mappings "[{\"DeviceName\":\"/dev/sda1\",\"Ebs\":{\"VolumeSize\":32,\"DeleteOnTermination\":true}}]" \ + --instance-initiated-shutdown-behavior terminate \ + --tag-specification "ResourceType=instance,Tags=[{Key=Name,Value="bandada-ephemeral-$ACTOR-$SHA"},{Key=Repo,Value="bandada"},{Key=Branch,Value="$BRANCH"}]" \ + --metadata-options "InstanceMetadataTags=enabled" From 4a61913cb704db946d6c9430cfa66b18777a3f35 Mon Sep 17 00:00:00 2001 From: Nick Tampakas Date: Fri, 9 Feb 2024 15:02:15 +0200 Subject: [PATCH 03/14] Run prettier --- .github/workflows/ephemeral.yml | 80 ++++++++++++++++----------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/.github/workflows/ephemeral.yml b/.github/workflows/ephemeral.yml index 3f5da925..9c5c1417 100644 --- a/.github/workflows/ephemeral.yml +++ b/.github/workflows/ephemeral.yml @@ -1,48 +1,48 @@ name: Ephemeral on: - schedule: - - cron: '0 */6 * * *' - workflow_dispatch: - inputs: - action: - description: "Action" - required: true - default: "spawn" - type: choice - options: - - spawn + schedule: + - cron: "0 */6 * * *" + workflow_dispatch: + inputs: + action: + description: "Action" + required: true + default: "spawn" + type: choice + options: + - spawn concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: false + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: false jobs: - deploy: - timeout-minutes: 5 - runs-on: ubuntu-latest - env: - DATA: ${{ github.event.inputs.action || 'maintenance' }} - permissions: - id-token: write - contents: read + deploy: + timeout-minutes: 5 + runs-on: ubuntu-latest + env: + DATA: ${{ github.event.inputs.action || 'maintenance' }} + permissions: + id-token: write + contents: read - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - persist-credentials: false - - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - role-to-assume: arn:aws:iam::490752553772:role/bandada-ephemeral-deploy-slc - role-duration-seconds: 900 - aws-region: eu-central-1 - - - name: Launch instance - run: | - .github/scripts/run.sh ${{ env.DATA }} $GITHUB_REF_NAME $GITHUB_TRIGGERING_ACTOR $GITHUB_SHA + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false - - name: Instance IP - run: | - .github/scripts/get_ip.sh ${{ env.DATA }} $GITHUB_TRIGGERING_ACTOR + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: arn:aws:iam::490752553772:role/bandada-ephemeral-deploy-slc + role-duration-seconds: 900 + aws-region: eu-central-1 + + - name: Launch instance + run: | + .github/scripts/run.sh ${{ env.DATA }} $GITHUB_REF_NAME $GITHUB_TRIGGERING_ACTOR $GITHUB_SHA + + - name: Instance IP + run: | + .github/scripts/get_ip.sh ${{ env.DATA }} $GITHUB_TRIGGERING_ACTOR From 65136d94a183a7468c23441d28c2c95abc3d9fc8 Mon Sep 17 00:00:00 2001 From: Daehyun Paik Date: Sat, 10 Feb 2024 09:29:49 +0100 Subject: [PATCH 04/14] ci: improve ci performance --- .github/workflows/coverall.yml | 30 ++++++------------------------ .github/workflows/deploy.yml | 2 +- .github/workflows/postgres.yml | 2 +- .github/workflows/release.yml | 22 ++++++---------------- .github/workflows/style.yml | 23 ++++------------------- .github/workflows/test.yml | 26 ++++---------------------- 6 files changed, 22 insertions(+), 83 deletions(-) diff --git a/.github/workflows/coverall.yml b/.github/workflows/coverall.yml index bd7b260f..f1ce5166 100644 --- a/.github/workflows/coverall.yml +++ b/.github/workflows/coverall.yml @@ -5,9 +5,6 @@ on: branches: - main -env: - DEFAULT_NETWORK: localhost - jobs: test: runs-on: ubuntu-latest @@ -18,37 +15,22 @@ jobs: - contracts steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18.x + cache: "yarn" - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn config get cacheFolder)" - - - name: Restore yarn cache - uses: actions/cache@v3 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Install dependencies + - name: Build monorepo run: yarn - - name: Build libraries - run: yarn workspaces foreach --no-private run build - - name: Test code run: yarn test:${{ matrix.tests }}:coverage - name: Coveralls - uses: coverallsapp/github-action@master + uses: coverallsapp/github-action@v2 with: github-token: ${{ secrets.GITHUB_TOKEN }} flag-name: run-${{ matrix.tests }} @@ -60,7 +42,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Coveralls Finished - uses: coverallsapp/github-action@master + uses: coverallsapp/github-action@v2 with: github-token: ${{ secrets.GITHUB_TOKEN }} parallel-finished: true diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4690ef0d..46909a85 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -60,7 +60,7 @@ jobs: fi - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: persist-credentials: false diff --git a/.github/workflows/postgres.yml b/.github/workflows/postgres.yml index 7dc52031..3eb9e927 100644 --- a/.github/workflows/postgres.yml +++ b/.github/workflows/postgres.yml @@ -35,7 +35,7 @@ jobs: fi - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v4 with: persist-credentials: false diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c3329882..85699f95 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,29 +13,19 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 + - uses: actions/checkout@v4 + - name: Install Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18.x + cache: "yarn" - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn config get cacheFolder)" - - - name: Restore yarn cache - uses: actions/cache@v3 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Install dependencies + - name: Build monorepo run: yarn - run: yarn version:release diff --git a/.github/workflows/style.yml b/.github/workflows/style.yml index 246934b9..4b3f0166 100644 --- a/.github/workflows/style.yml +++ b/.github/workflows/style.yml @@ -11,32 +11,17 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18.x + cache: "yarn" - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn config get cacheFolder)" - - - name: Restore yarn cache - uses: actions/cache@v3 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Install dependencies + - name: Build monorepo run: yarn - - name: Build - run: yarn build - - name: Run Prettier run: yarn prettier diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 11992ec9..d3a0957f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,39 +6,21 @@ on: branches: - main -env: - DEFAULT_NETWORK: localhost - jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Install Node.js - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: node-version: 18.x + cache: "yarn" - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn config get cacheFolder)" - - - name: Restore yarn cache - uses: actions/cache@v3 - id: yarn-cache - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Install dependencies + - name: Build monorepo run: yarn - - name: Build libraries - run: yarn workspaces foreach --no-private run build - - name: Test code run: yarn test From afe0f67a4b32693bef9755bf20666a89c8efa21b Mon Sep 17 00:00:00 2001 From: Miguel Lemos Date: Wed, 21 Feb 2024 15:58:12 +0000 Subject: [PATCH 05/14] docs: add Bandada repository link to the API docs (closes #403) --- apps/api/src/main.ts | 51 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index cbd02fe5..2ebd1480 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -57,8 +57,55 @@ async function bootstrap() { "https://raw.githubusercontent.com/privacy-scaling-explorations/bandada/main/apps/dashboard/src/assets/favicon.ico", customSiteTitle: "Bandada API Docs", customCss: `.topbar-wrapper img {content:url('https://raw.githubusercontent.com/privacy-scaling-explorations/bandada/d5268274cbb93f73a1960e131bff0d2bf1eacea9/apps/dashboard/src/assets/icon1.svg'); width:60px; height:auto;} - .swagger-ui .topbar { background-color: transparent; } small.version-stamp { display: none !important; }` - } + .swagger-ui .topbar { background-color: transparent; } small.version-stamp { display: none !important; }`, + customJsStr: ` + // Add a custom title to the right side of the Swagger UI page + document.addEventListener('DOMContentLoaded', function() { + const customTitle = document.createElement('div'); + customTitle.style.position = 'fixed'; + customTitle.style.top = '130px'; + customTitle.style.right = '40px'; + customTitle.style.padding = '10px'; + customTitle.style.color = 'black'; + customTitle.style.fontSize = '18px'; + + // Create a hyperlink element + const link = document.createElement('a'); + link.href = 'https://github.com/privacy-scaling-explorations/bandada'; + link.style.color = 'grey'; + + // Create a text node for the link text + const linkText = document.createTextNode('Github'); + + // Append the text node to the link + link.appendChild(linkText); + + // Create an SVG element for the GitHub icon + const githubIcon = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); + githubIcon.setAttribute('width', '24'); + githubIcon.setAttribute('height', '24'); + githubIcon.setAttribute('viewBox', '0 0 20 20'); + githubIcon.setAttribute('fill', 'currentColor'); + + const path = document.createElementNS('http://www.w3.org/2000/svg', 'path'); + path.setAttribute('d', 'M8 .153C3.589.153 0 3.742 0 8.153c0 3.436 2.223 6.358 5.307 7.408.387.071.53-.168.53-.374 0-.185-.007-.674-.01-1.322-2.039.445-2.47-.979-2.47-.979-.334-.849-.815-1.075-.815-1.075-.667-.457.05-.448.05-.448.739.052 1.13.76 1.13.76.656 1.124 1.719.799 2.134.61.067-.478.256-.8.466-.98-1.63-.184-3.34-.815-3.34-3.627 0-.8.287-1.457.754-1.969-.076-.185-.327-.932.072-1.943 0 0 .618-.198 2.03.752a6.74 6.74 0 0 1 1.8-.245c.61.003 1.226.082 1.8.245 1.41-.95 2.027-.752 2.027-.752.4 1.011.148 1.758.073 1.943.47.512.754 1.17.754 1.969 0 2.82-1.712 3.44-3.35 3.623.264.227.497.672.497 1.356 0 .977-.009 1.764-.009 2.004 0 .207.141.449.544.373C13.775 14.511 16 11.59 16 8.154 16 3.743 12.411 .154 8 .154z'); + + // Append the path to the GitHub icon + githubIcon.appendChild(path); + + // Append the GitHub icon to the link + link.insertBefore(githubIcon, link.firstChild); + + // Apply some padding to create space between the icon and the text + link.style.paddingLeft = '8px'; + + // Append the link to the custom title + customTitle.appendChild(link); + + document.body.appendChild(customTitle); + }); +` + }; SwaggerModule.setup("/", app, document, configUI) From 88531006c95a27b23b193bb11c39750f166b207d Mon Sep 17 00:00:00 2001 From: Miguel Lemos Date: Thu, 22 Feb 2024 18:20:36 +0000 Subject: [PATCH 06/14] docs: update configUI --- apps/api/src/main.ts | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/apps/api/src/main.ts b/apps/api/src/main.ts index 2ebd1480..ec94a0aa 100644 --- a/apps/api/src/main.ts +++ b/apps/api/src/main.ts @@ -62,17 +62,25 @@ async function bootstrap() { // Add a custom title to the right side of the Swagger UI page document.addEventListener('DOMContentLoaded', function() { const customTitle = document.createElement('div'); - customTitle.style.position = 'fixed'; - customTitle.style.top = '130px'; - customTitle.style.right = '40px'; + customTitle.style.position = 'absolute'; + customTitle.style.top = '27px'; customTitle.style.padding = '10px'; customTitle.style.color = 'black'; customTitle.style.fontSize = '18px'; + customTitle.style.padding = '0 20px'; + customTitle.style.maxWidth = '1460px'; + customTitle.style.display = 'flex'; + customTitle.style.justifyContent = 'end'; + customTitle.style.width = '100%'; + // Create a hyperlink element const link = document.createElement('a'); link.href = 'https://github.com/privacy-scaling-explorations/bandada'; + link.rel = 'noreferrer noopener nofollow'; + link.target = '_blank' link.style.color = 'grey'; + link.style.display = 'flex'; // Create a text node for the link text const linkText = document.createTextNode('Github'); @@ -102,10 +110,18 @@ async function bootstrap() { // Append the link to the custom title customTitle.appendChild(link); - document.body.appendChild(customTitle); + const parentDiv = document.createElement('div'); + parentDiv.style.display = 'flex'; + parentDiv.style.justifyContent = 'center'; + parentDiv.style.width = 'auto'; + + + parentDiv.appendChild(customTitle) + + document.body.appendChild(parentDiv); }); ` - }; + } SwaggerModule.setup("/", app, document, configUI) From 7ebce43c57fc507c94fc9505b56928282f8ae3b7 Mon Sep 17 00:00:00 2001 From: Dimitris Apostolou Date: Sun, 25 Feb 2024 07:09:58 +0200 Subject: [PATCH 07/14] fix: fix typos --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 598699ea..d35d66f9 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,7 @@ Please see the latest [documentation](https://pse-team.notion.site/Bandada-82d0d ## 🔧 Configuration -### Prerequisities +### Prerequisites - [NodeJS](https://nodejs.org/en) >= v18.17.0 @@ -236,7 +236,7 @@ yarn test ## 🐳 Running in Docker -### Prerequisities +### Prerequisites - [Docker](https://www.docker.com/) >= 4.26.1 - [docker-compose](https://docs.docker.com/compose/) >= 2.24.2 From 7641946bc5c68bc4168450299fa2539335e2a5dc Mon Sep 17 00:00:00 2001 From: Ryan Waldon Date: Thu, 29 Feb 2024 16:26:11 +1100 Subject: [PATCH 08/14] fix(dashboard): hide danger zone & api key sections for non-admins fix #307 & #306 --- apps/dashboard/src/pages/group.tsx | 164 +++++++++++++++-------------- 1 file changed, 85 insertions(+), 79 deletions(-) diff --git a/apps/dashboard/src/pages/group.tsx b/apps/dashboard/src/pages/group.tsx index 6d7f512e..3a33b44c 100644 --- a/apps/dashboard/src/pages/group.tsx +++ b/apps/dashboard/src/pages/group.tsx @@ -57,6 +57,13 @@ export default function GroupPage(): JSX.Element { const [_removeGroupName, setRemoveGroupName] = useState("") const [_selectedMembers, setSelectedMembers] = useState([]) const { admin } = useContext(AuthContext) + const isGroupAdmin = !!( + admin && + _group && + (groupType === "off-chain" + ? _group.admin === admin.id + : _group.admin === admin.address.toLowerCase()) + ) useEffect(() => { ;(async () => { @@ -349,82 +356,87 @@ ${memberIds.join("\n")} ) - {groupType === "off-chain" && !_group.credentials && ( - - - Use API key - - - onApiAccessToggle(event.target.checked) - } - /> - - - - Connect your app to your group using an API key. - + {groupType === "off-chain" && + !_group.credentials && + isGroupAdmin && ( + + + Use API key + + + onApiAccessToggle( + event.target.checked + ) + } + /> + - {_group.apiEnabled && ( - <> - - + + Connect your app to your group using an API + key. + + + {_group.apiEnabled && ( + <> + + - - - - e.preventDefault() - } - icon={ - + + - - - - - - - )} - - )} + closeOnClick={false} + hasArrow + > + + e.preventDefault() + } + icon={ + + } + /> + + + + + + + )} + + )} - {_group.type === "off-chain" && ( + {_group.type === "off-chain" && isGroupAdmin && (