Skip to content

Commit

Permalink
Merge branch 'development' into docsAndTests
Browse files Browse the repository at this point in the history
  • Loading branch information
cweitat authored May 23, 2023
2 parents 939fe11 + 5ca3f9c commit d436963
Show file tree
Hide file tree
Showing 75 changed files with 7,056 additions and 4,257 deletions.
34 changes: 18 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ version: 2
jobs:
dependencies:
docker:
- image: circleci/python:3.8.6-node
- image: quay.io/quan/circleci-python:py3.9
environment:
PIP_EXTRA_INDEX_URL: https://pypi.fury.io/fossasia/

working_directory: ~/code

Expand All @@ -12,16 +14,16 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v1.5-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
- v1.5.1-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1.5-dependencies-
- v1.5.1-dependencies-

- run:
name: Install Python Dependencies
command: |
python3 -m venv venv
. venv/bin/activate
poetry install
poetry export -f requirements.txt --without-hashes --with dev | pip install -r /dev/stdin
- run:
name: Install Node Dependencies
Expand All @@ -33,11 +35,11 @@ jobs:
- ./node_modules
- ~/.cache/yarn
- ~/.yarn/bin
key: v1.5-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
key: v1.5.1-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}

dredd:
docker:
- image: circleci/python:3.8.6-node
- image: quay.io/quan/circleci-python:py3.9
environment:
APP_CONFIG: config.TestingConfig
DATABASE_URL: postgresql://postgres@localhost/test
Expand All @@ -58,9 +60,9 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v1.5-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
- v1.5.1-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1.5-dependencies-
- v1.5.1-dependencies-

- run:
name: Create API blueprint
Expand All @@ -80,7 +82,7 @@ jobs:

pytype:
docker:
- image: circleci/python:3.8.6-node
- image: quay.io/quan/circleci-python:py3.9

working_directory: ~/code

Expand All @@ -90,17 +92,17 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v1.5-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
- v1.5.1-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1.5-dependencies-
- v1.5.1-dependencies-

- restore_cache:
keys:
- v1-pytype

- run:
name: Test pytype
command: . venv/bin/activate && pytype
command: ./venv/bin/pytype

- save_cache:
paths:
Expand All @@ -109,7 +111,7 @@ jobs:

test:
docker:
- image: circleci/python:3.8.6-node
- image: quay.io/quan/circleci-python:py3.9
environment:
APP_CONFIG: config.TestingConfig
DATABASE_URL: postgresql://postgres@localhost/test
Expand All @@ -131,9 +133,9 @@ jobs:
# Download and cache dependencies
- restore_cache:
keys:
- v1.5-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
- v1.5.1-dependencies-{{ checksum "poetry.lock" }}-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1.5-dependencies-
- v1.5.1-dependencies-

- run:
name: Test
Expand All @@ -147,7 +149,7 @@ jobs:
path: test-results

- store_artifacts:
path: test-results
path: test-results

- run:
name: Upload Coverage
Expand Down
40 changes: 24 additions & 16 deletions .github/workflows/docker-hub.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,37 @@ jobs:
runs-on: ubuntu-latest
steps:
-
name: Login to DockerHub
# The job will terminate early if Docker Hub credentials is not set.
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
name: Checkout
uses: actions/checkout@v3
-
name: Set up QEMU
uses: docker/setup-qemu-action@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v2
-
name: Docker meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v4
id: meta
with:
images: eventyay/open-event-server
images: |
eventyay/open-event-server
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
-
name: Build
id: docker_build
uses: docker/build-push-action@v2
name: Login to Docker Hub
uses: docker/login-action@v2
with:
push: true
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v4
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
-
name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
21 changes: 11 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,30 @@ FROM base as builder

RUN apk update && \
apk add --virtual build-deps make git g++ python3-dev musl-dev jpeg-dev zlib-dev libevent-dev file-dev libffi-dev openssl && \
apk add postgresql-dev
apk add postgresql-dev libxml2-dev libxslt-dev
# PDF Generation: weasyprint (libffi-dev jpeg-dev already included above)
RUN apk add --virtual gdk-pixbuf-dev

RUN apk --no-cache add postgresql-libs ca-certificates libxslt jpeg zlib file libxml2
# PDF Generation: weasyprint
RUN apk --no-cache add cairo-dev pango-dev ttf-opensans

# Note: The custom PyPI repo is for AlpineOS only, where Python packages are compiled with musl libc. Don't use it on glibc Linux.
ENV POETRY_HOME=/opt/poetry \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1

POETRY_NO_INTERACTION=1 \
PIP_EXTRA_INDEX_URL=https://pypi.fury.io/fossasia/

ENV PATH="$POETRY_HOME/bin:$PATH"

RUN set -eo pipefail; wget -O - https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
RUN set -eo pipefail; wget -O - https://install.python-poetry.org | python -

WORKDIR /opt/pysetup

COPY pyproject.toml ./
COPY poetry.lock ./

RUN poetry install --no-root --no-dev
RUN poetry export -f requirements.txt --without-hashes --only main | poetry run pip install -r /dev/stdin

####

Expand All @@ -33,11 +39,6 @@ COPY --from=builder /opt/pysetup/.venv /opt/pysetup/.venv

ENV PATH="/opt/pysetup/.venv/bin:$PATH"

RUN apk --no-cache add postgresql-libs ca-certificates libxslt jpeg zlib file libxml2
# PDF Generation: weasyprint
RUN apk --no-cache add cairo-dev pango-dev ttf-opensans
RUN fc-cache -f

WORKDIR /data/app
ADD . .
RUN ["sh", "scripts/l10n.sh", "generate"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![GitHub release](https://img.shields.io/github/release/fossasia/open-event-server.svg)](https://github.com/fossasia/open-event-server/releases/latest)
[![Build Status](https://travis-ci.org/fossasia/open-event-server.svg?branch=development)](https://travis-ci.org/fossasia/open-event-server)
[![CircleCI Build Staus Badge](https://img.shields.io/circleci/build/github/fossasia/open-event-server?label=CircleCI%20Build)](https://www.circleci.com/gh/fossasia/open-event-server)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/1ac554483fac462797ffa5a8b9adf2fa?style=flat-square)](https://www.codacy.com/app/fossasia/open-event-server)
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/f5036c0e23b44270ad24397e338b8412)](https://www.codacy.com/gh/fossasia/open-event-server/dashboard?utm_source=github.com&utm_medium=referral&utm_content=fossasia/open-event-server&utm_campaign=Badge_Grade)
[![Codecov branch](https://codecov.io/gh/fossasia/open-event-server/branch/development/graph/badge.svg?style=flat-square)](https://codecov.io/gh/fossasia/open-event-server)
[![Gitter](https://img.shields.io/badge/chat-on%20gitter-ff006f.svg?style=flat-square)](https://gitter.im/fossasia/open-event-server)
[![Reviewed by Hound](https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg)](https://houndci.com)
Expand Down Expand Up @@ -199,7 +199,7 @@ Clone the repo and set up the server according to the steps listed. Make sure yo

```
# Install Poetry
curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -
curl -sSL https://install.python-poetry.org | python -
source ~/.profile
# Install Python dependencies
Expand Down
68 changes: 30 additions & 38 deletions app/api/custom/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
from app.api.helpers.db import safe_query, save_to_db
from app.api.helpers.errors import ForbiddenError, NotFoundError, UnprocessableEntityError
from app.api.helpers.mail import send_email_to_attendees
from app.api.helpers.order import calculate_order_amount, create_pdf_tickets_for_holder, on_order_completed, delete_related_attendees_for_order
from app.api.helpers.order import calculate_order_amount, create_pdf_tickets_for_holder, on_order_completed
from app.api.helpers.permission_manager import has_access
from app.api.orders import validate_attendees
from app.api.schema.orders import OrderSchema
from app.extensions.limiter import limiter
from app.models import db
from app.models.order import Order
from app.models.order import OrderTicket
from app.models.ticket import Ticket
from app.models.ticket_holder import TicketHolder
from app.api.helpers.payment import StripePaymentsManager
Expand Down Expand Up @@ -122,19 +123,6 @@ def create_order():
try:
attendees = []
for ticket in tickets:
if 'price' in data['tickets'][0]:
if (
'price' in data['tickets'][0]
and "donation" in ticket.type
and (
data['tickets'][0]['price'] < ticket.min_price
or data['tickets'][0]['price'] > ticket.max_price
)
):
raise UnprocessableEntityError(
{'source': 'tickets'},
f"Donation ticket price should be between {ticket.min_price} and {ticket.max_price}",
)
for _ in range(ticket_map[ticket.id]['quantity']):
ticket.raise_if_unavailable()
attendees.append(
Expand Down Expand Up @@ -162,6 +150,12 @@ def create_order():
db.session.commit()
order.populate_and_save()

order_tickets = OrderTicket.query.filter_by(order_id=order.id).all()
for order_ticket in order_tickets:
ticket_info = ticket_map[order_ticket.ticket.id]
order_ticket.price = ticket_info.get('price')
save_to_db(order_ticket)

return OrderSchema().dump(order)


Expand Down Expand Up @@ -195,27 +189,25 @@ def verify_order_payment(order_identifier):

order = Order.query.filter_by(identifier=order_identifier).first()

try:
session = StripePaymentsManager.retrieve_session(order.event, order.stripe_session_id)
payment_intent = StripePaymentsManager.retrieve_payment_intent(order.event, session.payment_intent)
except Exception as e:
raise e

if session['payment_status'] == 'paid':
order.status = 'completed'
order.completed_at = datetime.utcnow()
order.paid_via = payment_intent['charges']['data'][0]['payment_method_details']['type']
order.transaction_id = payment_intent['charges']['data'][0]['balance_transaction']
save_to_db(order)

on_order_completed(order)

else:
order.status = 'expired'

db.session.commit()
# delete related attendees to unlock the tickets
delete_related_attendees_for_order(order)


return jsonify({ 'payment_status': session['payment_status']})
if order.payment_mode == 'stripe':
try:
payment_intent = StripePaymentsManager.retrieve_payment_intent(order.event, order.stripe_payment_intent_id)
except Exception as e:
raise e

if payment_intent['status'] == 'succeeded':
order.status = 'completed'
order.completed_at = datetime.utcnow()
order.paid_via = payment_intent['charges']['data'][0]['payment_method_details']['type']
order.transaction_id = payment_intent['charges']['data'][0]['balance_transaction']
if payment_intent['charges']['data'][0]['payment_method_details']['type'] == 'card' :
order.brand = payment_intent['charges']['data'][0]['payment_method_details']['card']['brand']
order.exp_month = payment_intent['charges']['data'][0]['payment_method_details']['card']['exp_month']
order.exp_year = payment_intent['charges']['data'][0]['payment_method_details']['card']['exp_year']
order.last4 = payment_intent['charges']['data'][0]['payment_method_details']['card']['last4']
save_to_db(order)

on_order_completed(order)


return jsonify({ 'payment_status': order.status})
2 changes: 1 addition & 1 deletion app/api/custom/schema/order_amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
class TicketSchema(Schema):
id = fields.Integer(required=True)
quantity = fields.Integer(default=1)
price = fields.Float()
price = fields.Float(allow_none=True)


class OrderAmountInputSchema(Schema):
Expand Down
2 changes: 1 addition & 1 deletion app/api/data_layers/ChargesLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def create_object(self, data, view_kwargs):
{'': ''}, "This event doesn't accept payments by Stripe"
)

success, response = TicketingManager.charge_stripe_order_payment(
success, response = TicketingManager.create_payment_intent_for_order_stripe(
order
)
data['status'] = success
Expand Down
Loading

0 comments on commit d436963

Please sign in to comment.