Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/gha workflows update #235

Closed
wants to merge 10 commits into from
Closed
2 changes: 1 addition & 1 deletion .github/workflows/black.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Python Linter (Black)
on: [push, pull_request]

jobs:
lint:
lint-backend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build_docker.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
- "dev"

jobs:
docker:
build-docker-dev:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
Expand All @@ -18,11 +18,11 @@ jobs:
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
- name: Build and Push
id: docker_build
uses: docker/build-push-action@v3
with:
file: docker/Dockerfile
platforms: linux/amd64
push: true
tags: membermatters/membermatters:dev
tags: membermatters/membermatters:dev,membermatters/membermatters:${{github.sha}}
27 changes: 27 additions & 0 deletions .github/workflows/build_docker.pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Build Docker Image (DEV Branch)

on:
pull_request:
branches:
- "dev"

jobs:
build-docker-pr:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build Docker Image
id: docker_build
uses: docker/build-push-action@v3
with:
file: docker/Dockerfile
platforms: linux/amd64
push: false
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- "!v[0-9]+.[0-9]+.[0-9]+-*"

jobs:
docker:
build-docker-release:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
Expand Down
60 changes: 30 additions & 30 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ name: "CodeQL"

on:
push:
branches: [ main, dev ]
branches:
- "dev"
pull_request:
# The branches below must be a subset of the branches above
branches: [ main, dev ]
schedule:
- cron: '36 19 * * 4'
branches:
- "dev"

jobs:
analyze:
Expand All @@ -28,40 +28,40 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ 'javascript', 'python' ]
language: ["javascript", "python"]
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
# Learn more:
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed

steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Checkout repository
uses: actions/checkout@v2

# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: ${{ matrix.language }}
# If you wish to specify custom queries, you can do so here or in a config file.
# By default, queries listed here will override any specified in a config file.
# Prefix the list here with "+" to use these queries and those in the config file.
# queries: ./path/to/local/query, your-org/your-repo/queries@main

# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
# If this step fails, then you should remove it and run the build manually (see below)
- name: Autobuild
uses: github/codeql-action/autobuild@v1

# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl
# ℹ️ Command-line programs to run using the OS shell.
# 📚 https://git.io/JvXDl

# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
# and modify them (or add more) to build your code if your project
# uses a compiled language

#- run: |
# make bootstrap
# make release
#- run: |
# make bootstrap
# make release

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
2 changes: 1 addition & 1 deletion .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: JavaScript Linter (eslint)
on: [push, pull_request]
jobs:
build:
lint-frontend:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 5 additions & 0 deletions memberportal/api_admin_tools/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
views.MemberWelcomeEmail.as_view(),
name="MemberWelcomeEmail",
),
path(
"api/admin/members/<int:member_id>/sendsms/",
views.MemberSendSms.as_view(),
name="MemberSendSms",
),
path(
"api/admin/members/<int:member_id>/profile/",
views.MemberProfile.as_view(),
Expand Down
43 changes: 42 additions & 1 deletion memberportal/api_admin_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from memberbucks.models import MemberBucks
from constance import config
from services.emails import send_email_to_admin
from services import sms
import json
import stripe
from sentry_sdk import capture_message
Expand All @@ -16,7 +17,6 @@
from django.db.models import F, Count, Sum, Value, CharField, Count, Max
from django.db.models.functions import Concat
from datetime import timedelta
import humanize
from django.db import connection
from django.db.utils import OperationalError
from sentry_sdk import capture_exception
Expand Down Expand Up @@ -338,6 +338,47 @@ def post(self, request, member_id):
return Response()


class MemberSendSms(APIView):
"""
post: This method sends a custom sms alert to the specified member.
"""

permission_classes = (permissions.IsAdminUser,)

def post(self, request, member_id):
member = User.objects.get(id=member_id)
sms_body = request.data["smsBody"]

if not config.SMS_ENABLE:
return Response(
{"success": False, "message": "SMS functionality not enabled."},
status=status.HTTP_500_INTERNAL_SERVER_ERROR,
)

if not member.profile.phone:
return Response(
{"success": False, "message": "Member does not have a phone number."},
status=status.HTTP_400_BAD_REQUEST,
)

# check if the sms body exists, is at least 1 character, and isn't more than 320 characters
if not sms_body or len(sms_body) < 1 or len(sms_body) > 320:
return Response(
{"success": False, "message": "SMS body is invalid."},
status=status.HTTP_400_BAD_REQUEST,
)

sms_message = sms.SMS()
sms_message.send_custom_notification(
to_number=member.profile.phone,
message=sms_body,
portal_user_sender=request.user,
portal_user_recipient=member,
)

return Response()


class MemberProfile(APIView):
"""
put: This method updates a member's profile.
Expand Down
5 changes: 5 additions & 0 deletions memberportal/api_general/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ def get(self, request):
"siteBanner": config.SITE_BANNER,
"enableSiteSignIn": config.ENABLE_PORTAL_SITE_SIGN_IN,
"enableMembersOnSite": config.ENABLE_PORTAL_MEMBERS_ON_SITE,
"sms": {
"enable": config.SMS_ENABLE,
"senderId": config.SMS_SENDER_ID,
"footer": config.SMS_FOOTER,
},
}

keys = {"stripePublishableKey": config.STRIPE_PUBLISHABLE_KEY}
Expand Down
36 changes: 36 additions & 0 deletions memberportal/profile/migrations/0017_alter_log_logtype.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Generated by Django 3.2.20 on 2024-01-17 03:42

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("profile", "0016_alter_log_data"),
]

operations = [
migrations.AlterField(
model_name="log",
name="logtype",
field=models.CharField(
choices=[
("generic", "Generic Event"),
("stripe", "Stripe Event"),
("memberbucks", "Memberbucks Updated"),
("spacebucks", "Spacebucks Updated"),
("profile", "Member Profile Updated"),
("interlock", "Interlock Event"),
("door", "Door Event"),
("memberbucksdevice", "Memberbucks Event"),
("email", "Email Sent"),
("sms", "SMS Sent"),
("admin", "Admin Action"),
("error", "Unhandled Error"),
("xero", "Xero Event"),
],
default="generic",
max_length=30,
verbose_name="Type of action/event",
),
),
]
26 changes: 13 additions & 13 deletions memberportal/profile/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
utc = pytz.UTC

LOG_TYPES = (
("generic", "Generic log entry"),
("usage", "Generic usage access"),
("stripe", "Stripe related event"),
("memberbucks", "Memberbucks related event"),
("spacebucks", "Spacebucks related event"),
("profile", "Member profile was edited or updated"),
("interlock", "Interlock device related event"),
("door", "Door device related event"),
("memberbucksdevice", "Memberbucks device related event"),
("email", "An email was sent or attempted to be sent"),
("admin", "An admin performed an action"),
("error", "An event or action caused an error"),
("xero", "Generic xero log entry"),
("generic", "Generic Event"),
("stripe", "Stripe Event"),
("memberbucks", "Memberbucks Updated"),
("spacebucks", "Spacebucks Updated"), # the old internal name for memberbucks
("profile", "Member Profile Updated"),
("interlock", "Interlock Event"),
("door", "Door Event"),
("memberbucksdevice", "Memberbucks Event"),
("email", "Email Sent"),
("sms", "SMS Sent"),
("admin", "Admin Action"),
("error", "Unhandled Error"),
("xero", "Xero Event"),
)


Expand Down
3 changes: 1 addition & 2 deletions memberportal/profile/templates/email_welcome.html
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,7 @@ <h1 style="font-size: 48px; font-weight: 400; margin: 0">
<p style="margin: 0">
Sent by
<a href="{{ config.SITE_URL }}">{{ config.SITE_NAME }}</a> on
behalf of {{ config.SITE_OWNER }} at {{
config.SITE_MAIL_ADDRESS }}.
behalf of {{ config.SITE_OWNER }} at {{ config.SITE_MAIL_ADDRESS }}.
</p>
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion memberportal/services/emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def send_single_email(
to_email: object,
subject: object,
template_vars: object,
template_name,
template_name=None,
reply_to=None,
user: object | None = None,
) -> object:
Expand Down
Loading
Loading