Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .chalice/policy-dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"arn:aws:ssm:us-east-1:280776660572:parameter/Zap/MONGO_ADMIN_USER",
"arn:aws:ssm:us-east-1:280776660572:parameter/Zap/MONGO_ADMIN_PASSWORD",
"arn:aws:ssm:us-east-1:280776660572:parameter/Zap/GOOGLE_SERVICE_ACCOUNT_CREDENTIALS",
"arn:aws:ssm:us-east-1:280776660572:parameter/Zap/sentry/dsn",
"arn:aws:ssm:us-east-1:280776660572:parameter/Vault/POSTHOG_API_KEY",
"arn:aws:ssm:us-east-1:280776660572:parameter/Vault/POSTHOG_PROJECT_ID"
]
Expand Down
1 change: 1 addition & 0 deletions .chalice/policy-prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"arn:aws:ssm:us-east-1:280776660572:parameter/Zap/MONGO_ADMIN_USER",
"arn:aws:ssm:us-east-1:280776660572:parameter/Zap/MONGO_ADMIN_PASSWORD",
"arn:aws:ssm:us-east-1:280776660572:parameter/Zap/GOOGLE_SERVICE_ACCOUNT_CREDENTIALS",
"arn:aws:ssm:us-east-1:280776660572:parameter/Zap/sentry/dsn",
"arn:aws:ssm:us-east-1:280776660572:parameter/Vault/POSTHOG_API_KEY",
"arn:aws:ssm:us-east-1:280776660572:parameter/Vault/POSTHOG_PROJECT_ID"
]
Expand Down
27 changes: 27 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# .github/release.yml

changelog:
exclude:
labels:
- ignore-for-release
categories:
- title: New Features 🎉
labels:
- feature
- title: Bug Fixes 🛠️
labels:
- bug
- fix
- issue resolved
- title: Enhancements ✨
labels:
- improvement
- optimization
- performance
- title: Breaking Changes 🔥
labels:
- breaking change
- major update
- title: Deprecations 🚧
labels:
- deprecation
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ google-api-python-client = "*"
google-auth-httplib2 = "*"
google-auth-oauthlib = "*"
thefuzz = "*"
sentry-sdk = {extras = ["chalice"], version = "*"}

[dev-packages]

Expand Down
860 changes: 421 additions & 439 deletions Pipfile.lock

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import os
import boto3
import sentry_sdk
from sentry_sdk.integrations.chalice import ChaliceIntegration

from chalice import Chalice

from chalicelib.api.listings import listings_api
Expand All @@ -9,6 +14,22 @@
from chalicelib.api.accountability import accountability_api
from chalicelib.api.monitoring import monitoring_api

# Configure and initialize sentry
sentry_sdk.init(
dsn=boto3.client("ssm").get_parameter(Name="/Zap/sentry/dsn", WithDecryption=True)[
"Parameter"
]["Value"],
integrations=[ChaliceIntegration()],
# Set traces_sample_rate to 1.0 to capture 100%
# of transactions for performance monitoring.
traces_sample_rate=1.0,
# Set profiles_sample_rate to 1.0 to profile 100%
# of sampled transactions.
# We recommend adjusting this value in production.
profiles_sample_rate=1.0,
environment="production" if os.environ.get("ENV") == "prod" else "development",
)

app = Chalice(app_name="zap")
app.register_blueprint(announcements_api)
app.register_blueprint(listings_api)
Expand Down
8 changes: 8 additions & 0 deletions chalicelib/api/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def delete_event(event_id: str):
def get_rush_events():
return event_service.get_rush_categories_and_events()


@events_api.route("/events/rush/{event_id}", methods=["GET"], cors=True)
def get_rush_event(event_id):
return event_service.get_rush_event(event_id)
Expand All @@ -90,6 +91,13 @@ def create_rush_category():
def create_rush_event():
data = events_api.current_request.json_body
return event_service.create_rush_event(data)


@events_api.route("/events/rush", methods=["PATCH"], cors=True)
@auth(events_api, roles=["admin"])
def modify_rush_event():
data = events_api.current_request.json_body
return event_service.modify_rush_event(data)


@events_api.route("/events/rush/checkin/{event_id}", methods=["POST"], cors=True)
Expand Down
21 changes: 19 additions & 2 deletions chalicelib/modules/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,21 +159,38 @@ def update_document_by_id(
return False

@add_env_suffix
def update_document(self, collection, document_id, query):
def update_document(self, collection, document_id, query, array_filters=None):
"""
Updates a document in the specified collection with the given ID.

Args:
collection (str): The name of the collection to update the document in.
document_id (str): The ID of the document to update.
query (dict): A dictionary containing the update operators.
array_filters (list, optional): A list of filters to apply when updating
elements in an array field of the document.
Each filter in the list is a dictionary
specifying the criteria for selecting
array elements to be updated. Default is None.

Returns:
bool: True if the update was successful, False otherwise.
"""
try:
update_options = {}
if array_filters:
# ensure array_filters is a list
if not isinstance(array_filters, list):
raise ValueError("array_filters must be a list.")
# ensure each item contains a dictionary
for f in array_filters:
if not isinstance(f, dict):
raise ValueError("Each item in array_filters must be a dictionary.")
update_options["array_filters"] = array_filters


result = self.mongo_client.vault[collection].update_one(
{"_id": ObjectId(document_id)}, query
{"_id": ObjectId(document_id)}, query, **update_options
)

if result.matched_count > 0:
Expand Down
57 changes: 57 additions & 0 deletions chalicelib/services/EventService.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ def create_rush_category(self, data: dict):

def create_rush_event(self, data: dict):
data["dateCreated"] = datetime.datetime.now()
data["lastModified"] = data["dateCreated"]

data_copy = data.copy()
data_copy.pop("categoryId", None)

Expand All @@ -273,6 +275,61 @@ def create_rush_event(self, data: dict):
)

return

def modify_rush_event(self, data: dict):

try:
data["lastModified"] = datetime.datetime.now()

eventId = data["eventId"]

# Check if event exists in the rush-event collection
event = mongo_module.get_document_by_id(
f"{self.collection_prefix}rush-event", eventId
)

if not event:
raise Exception("Event does not exist.")

event_category_id = event["categoryId"]

# Merge the existing event data with the new data
updated_event = {**event, **data}

# categoryId not needed on rush collection array elements
updated_event.pop("categoryId")

# Define array update query and filters
update_query = {
"$set": {
"events.$[eventElem]": updated_event
}
}

array_filters = [
{"eventElem.eventId": eventId}
]

# Modify the event in its category (rush collection)
mongo_module.update_document(
f"{self.collection_prefix}rush",
event_category_id,
update_query,
array_filters=array_filters
)

# Modify actual event document (rush-event collection)
mongo_module.update_document(
f"{self.collection_prefix}rush-event",
eventId,
{"$set": data},
)
return


except Exception as e:
print("error is ", e)
raise BadRequestError(e)

def get_rush_event(self, event_id: str, hide_attendees: bool = True):
event = mongo_module.get_document_by_id(
Expand Down