Skip to content

🍒 Dev #1271

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

Merged
merged 9 commits into from
Apr 9, 2025
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
2 changes: 2 additions & 0 deletions backend/api/models/GroupMessage.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from api.core import Mixin
from sqlalchemy import false
from .base import db
from flask_mongoengine import Document
from mongoengine import *
Expand All @@ -14,6 +15,7 @@ class GroupMessage(Document, Mixin):
hub_user_id = ObjectIdField(required=True)
created_at = DateTimeField(required=True)
parent_message_id = StringField(required=False)
is_deleted = BooleanField(required=False)

def __repr__(self):
return f"<GroupMessage:{self.body} \n Sent by:{self.sender_id}>"
18 changes: 18 additions & 0 deletions backend/api/models/Moderator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from api.core import Mixin
from flask_mongoengine import Document
from mongoengine import *


class Moderator(Document, Mixin):
"""Moderator Collection."""

firebase_uid = StringField(required=True)
email = StringField(required=True)
name = StringField(required=True)
roomName = StringField(required=False)

def __repr__(self):
return f"""<User id:{self.id}
\n firebase_uid:{self.firebase_uid}
\n email:{self.email}
\n name:{self.name}>"""
11 changes: 6 additions & 5 deletions backend/api/models/PartnerProfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ class PartnerProfile(Document, Mixin):
email = StringField(required=True)
text_notifications = BooleanField(required=True)
email_notifications = BooleanField(required=True)
organization = StringField(required=True)
location = StringField(required=True)
organization = StringField(required=False)
title = StringField(required=False)
location = StringField(required=False)
person_name = StringField()
regions = ListField(StringField(), required=True)
regions = ListField(StringField(), required=False)
intro = StringField(required=True)
website = StringField()
linkedin = StringField()
sdgs = ListField(StringField(), required=True)
topics = StringField()
success = StringField(required=False)
open_grants = BooleanField(required=True)
open_projects = BooleanField(required=True)
open_grants = BooleanField(required=False)
open_projects = BooleanField(required=False)
image = EmbeddedDocumentField(Image)
restricted = BooleanField(default=False)
assign_mentors = ListField(DictField(), required=False)
Expand Down
2 changes: 2 additions & 0 deletions backend/api/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from .Specializations import Specializations
from .Guest import Guest
from .Support import Support
from .Moderator import Moderator
from .SignOrigin import SignOrigin
from .SignedDocs import SignedDocs
from .Announcement import Announcement
Expand Down Expand Up @@ -65,6 +66,7 @@
"Specializations",
"Guest",
"Support",
"Moderator",
"SignOrigin",
"SignedDocs",
"GroupMessage",
Expand Down
1 change: 1 addition & 0 deletions backend/api/utils/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Account(Enum):
GUEST = 4
SUPPORT = 5
HUB = 6
MODERATOR = 7

def __eq__(self, other):
return self.value == other
Expand Down
8 changes: 5 additions & 3 deletions backend/api/utils/profile_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ def new_profile(data: dict = {}, profile_type: int = -1):
new_profile = PartnerProfile(
firebase_uid=data["firebase_uid"],
email=data["email"],
organization=data["organization"],
location=data["location"],
regions=data["regions"],
organization=data.get("organization"),
title=data.get("title"),
location=data.get("location"),
regions=data.get("regions"),
intro=data["intro"],
open_grants=data.get("open_grants"),
open_projects=data.get("open_projects"),
Expand Down Expand Up @@ -153,6 +154,7 @@ def edit_profile(data: dict = {}, profile: object = None):
if isinstance(profile, PartnerProfile):
# Edit fields or keep original data if no added data
profile.organization = data.get("organization", profile.organization)
profile.title = data.get("title", profile.title)
profile.location = data.get("location", profile.location)
profile.email = data.get("email", profile.email)
profile.regions = data.get("regions", profile.regions)
Expand Down
9 changes: 6 additions & 3 deletions backend/api/utils/request_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
MenteeProfile,
Admin,
Guest,
Moderator,
PartnerProfile,
MenteeApplication,
NewMentorApplication,
Expand Down Expand Up @@ -75,10 +76,10 @@ class MenteeForm(Form):
class PartnerForm(Form):
firebase_uid = StringField(validators=[InputRequired()])
email = StringField(validators=[InputRequired()])
organization = StringField(validators=[InputRequired()])
location = StringField(validators=[InputRequired()])
# organization = StringField(validators=[InputRequired()])
# location = StringField(validators=[InputRequired()])
intro = StringField(validators=[InputRequired()])
regions = FieldList(StringField(), validators=[validators.DataRequired()])
# regions = FieldList(StringField(), validators=[validators.DataRequired()])
sdgs = FieldList(StringField(), validators=[validators.DataRequired()])


Expand Down Expand Up @@ -274,6 +275,8 @@ def get_profile_model(role):
return Guest
elif role == Account.SUPPORT:
return Support
elif role == Account.MODERATOR:
return Moderator
elif role == Account.HUB:
return Hub
else:
Expand Down
13 changes: 11 additions & 2 deletions backend/api/views/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from api.models.Moderator import Moderator
from api.views.messages import invite
from flask import Blueprint, request
from firebase_admin import auth as firebase_admin_auth
Expand Down Expand Up @@ -226,7 +227,7 @@ def upload_account_emailText():
messageText = request.form["messageText"]
password = request.form["password"]
name = request.form["name"]
if role == Account.GUEST or role == Account.SUPPORT:
if role == Account.GUEST or role == Account.SUPPORT or role == Account.MODERATOR:
email = messageText
email = email.replace(" ", "")
duplicates = VerifiedEmail.objects(email=email, role=str(role), password="")
Expand All @@ -247,9 +248,12 @@ def upload_account_emailText():
if role == Account.GUEST:
guest = Guest(email=email, name=name, firebase_uid=firebase_uid)
guest.save()
else:
elif role == Account.SUPPORT:
support = Support(email=email, name=name, firebase_uid=firebase_uid)
support.save()
elif role == Account.MODERATOR:
moderator = Moderator(email=email, name=name, firebase_uid=firebase_uid)
moderator.save()

verified_email = VerifiedEmail(email=email, role=str(role), password="")
verified_email.save()
Expand Down Expand Up @@ -361,5 +365,10 @@ def editEmailPassword():
for ex_item in ex_data:
ex_item.email = email
ex_item.save()
ex_data = Moderator.objects.filter(email=ex_email)
if len(ex_data) > 0:
for ex_item in ex_data:
ex_item.email = email
ex_item.save()

return create_response(status=200, message="successful edited")
1 change: 1 addition & 0 deletions backend/api/views/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def login():
role != Account.ADMIN
and role != Account.GUEST
and role != Account.SUPPORT
and role != Account.MODERATOR
and role != Account.HUB
):
# user failed to create profile during registration phase
Expand Down
21 changes: 16 additions & 5 deletions backend/api/views/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
MentorApplication,
MentorProfile,
MenteeProfile,
Moderator,
Support,
Users,
Image,
Expand Down Expand Up @@ -108,9 +109,9 @@ def get_accounts(account_type):
if partner_account.assign_mentees:
for mentee_item in partner_account.assign_mentees:
if "id" in mentee_item:
partners_by_assign_mentee[str(mentee_item["id"])] = (
partner_account
)
partners_by_assign_mentee[
str(mentee_item["id"])
] = partner_account
for account in mentees_data:
if str(account.id) in partners_by_assign_mentee:
pair_partner = partners_by_assign_mentee[str(account.id)]
Expand Down Expand Up @@ -184,6 +185,8 @@ def get_accounts(account_type):
accounts = Guest.objects()
elif account_type == Account.SUPPORT:
accounts = Support.objects()
elif account_type == Account.MODERATOR:
accounts = Moderator.objects()
elif account_type == Account.HUB:
accounts = Hub.objects()
elif account_type == Account.ADMIN:
Expand Down Expand Up @@ -228,6 +231,8 @@ def get_account(id):
account = Guest.objects.get(id=id)
elif account_type == Account.SUPPORT:
account = Support.objects.get(id=id)
elif account_type == Account.MODERATOR:
account = Moderator.objects.get(id=id)
elif account_type == Account.HUB:
account = Hub.objects.get(id=id)
else:
Expand Down Expand Up @@ -448,7 +453,10 @@ def create_mentor_profile():
txt_role = "Mentee"
if account_type == Account.PARTNER:
txt_role = "Partner"
txt_name = data["organization"]
if "organization" in data:
txt_name = data["organization"]
else:
txt_name = data["title"]
else:
txt_name = data["name"]
success, msg = send_email(
Expand Down Expand Up @@ -584,7 +592,10 @@ def create_profile_existing_account():
txt_role = "Mentee"
if account_type == Account.PARTNER:
txt_role = "Partner"
txt_name = data["organization"]
if "organization" in data:
txt_name = data["organization"]
else:
txt_name = data["title"]
else:
txt_name = data["name"]
success, msg = send_email(
Expand Down
40 changes: 34 additions & 6 deletions backend/api/views/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,16 @@ def get_sidebar(user_id):
continue
otherUser = json.loads(otherUser.to_json())
if user_type == Account.PARTNER.value:
otherUserObj = {
"name": otherUser["organization"],
"user_type": user_type,
}
if "organization" in otherUser:
otherUserObj = {
"name": otherUser["organization"],
"user_type": user_type,
}
else:
otherUserObj = {
"name": otherUser["title"],
"user_type": user_type,
}
else:
otherUserObj = {
"name": otherUser["name"],
Expand Down Expand Up @@ -563,14 +569,35 @@ def get_sidebar_mentors(page_number):
)


@messages.route("/group_delete/<string:message_id>", methods=["DELETE"])
@all_users
def delete_group_message(message_id):
try:
message = GroupMessage.objects.get(id=message_id)
except:
msg = "Invalid message id"
logger.info(msg)
return create_response(status=422, message=msg)
try:
message.is_deleted = True
message.save()
return create_response(
status=200, message=f"message_id: {message_id} deleted successfully"
)
except:
msg = "Failed to delete message"
logger.info(msg)
return create_response(status=422, message=msg)


@messages.route("/group/", methods=["GET"])
@all_users
def get_group_messages():
try:
hub_user_id = request.args.get("hub_user_id", None)
if hub_user_id is not None and hub_user_id != "":
messages = GroupMessage.objects(
Q(hub_user_id=request.args.get("hub_user_id"))
Q(hub_user_id=request.args.get("hub_user_id")) & Q(is_deleted__ne=True)
)
else:
messages = PartnerGroupMessage.objects()
Expand Down Expand Up @@ -605,10 +632,11 @@ def get_direct_messages():


@socketio.on("editGroupMessage")
def editGroupMessage(id, hub_user_id, message_body, methods=["POST"]):
def editGroupMessage(id, hub_user_id, message_title, message_body, methods=["POST"]):
try:
if hub_user_id is not None:
message = GroupMessage.objects.get(id=id)
message.title = message_title
message.body = message_body
message.message_edited = True

Expand Down
2 changes: 1 addition & 1 deletion backend/requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pylint>=2.1.1
black>=18.9b0
black==18.9b0
mypy
pytest>=3.7.1
5 changes: 5 additions & 0 deletions frontend/public/locales/ar/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"common": {
"admin": "مسؤل",
"support": "مؤيد، مشجع، داعم",
"moderator": "المشرف",
"hub": "شريك المحور",
"powered_by":"مدعوم من",
"apply": "تطبيق",
Expand Down Expand Up @@ -549,9 +550,13 @@
},
"partnerProfile": {
"briefIntro": "مقدمة موجزة عن منظمتك / مؤسستك / شركتك",
"AUAFbriefIntro":"نبذة مختصرة عن نفسك",
"collaborationGrants": "منفتح على التعاون في المنح",
"collaborationProjects": "مفتوح للتعاون في المشاريع",
"contactFullName": "الاسم الكامل لجهة الاتصال (الاسم واللقب)",
"AUAFcontactFullName":"أدخل اسمك الكامل",
"title":"أدخل عنوانك",
"requiredTitle":"يرجى إدخال العنوان",
"developmentGoals": "أهداف التنمية المستدامة التي يدعمها عملك",
"location": "موقع المقر (المدينة ، الدولة)",
"organizationName": "اسم المنظمة / المؤسسة / الشركة بالكامل",
Expand Down
5 changes: 5 additions & 0 deletions frontend/public/locales/en-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"common": {
"admin": "Admin",
"support": "Supporter",
"moderator": "Moderator",
"hub": "Hub Partner",
"powered_by":"powered by",
"apply": "Apply",
Expand Down Expand Up @@ -551,9 +552,13 @@
},
"partnerProfile": {
"briefIntro": "Brief Introduction to Your Org/Inst/Corp",
"AUAFbriefIntro":"Brief Introduction of Yourself",
"collaborationGrants": "Open to Collaboration on Grants",
"collaborationProjects": "Open to Collaboration on Projects",
"contactFullName": "Contact Person's Full Name (First Last)",
"AUAFcontactFullName":"Enter your Full Name",
"title":"Enter your Title",
"requiredTitle":"Please input title",
"developmentGoals": "Sustainable Development Goals Your Work Supports",
"location": "Headquarters Location (City, Country)",
"organizationName": "Organization/Institution/Corporation Full Name",
Expand Down
5 changes: 5 additions & 0 deletions frontend/public/locales/es-US/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"common": {
"admin": "Administrador",
"support": "Seguidor",
"moderator": "Moderador",
"hub": "Socio central",
"powered_by":"impulsado por",
"apply": "Aplicar",
Expand Down Expand Up @@ -549,9 +550,13 @@
},
"partnerProfile": {
"briefIntro": "Breve introducción a su organización/institución/corporación",
"AUAFbriefIntro":"Breve presentación personal",
"collaborationGrants": "Abierto a la colaboración en subvenciones",
"collaborationProjects": "Abierto a la colaboración en proyectos",
"contactFullName": "Nombre completo de la persona de contacto (nombre y apellido)",
"AUAFcontactFullName":"Ingrese su nombre completo",
"title":"Ingrese su título",
"requiredTitle":"Por favor, ingrese el título",
"developmentGoals": "Objetivos de desarrollo sostenible que apoya su trabajo",
"location": "Ubicación de la sede (ciudad, país)",
"organizationName": "Organización/Institución/Corporación Nombre Completo",
Expand Down
Loading
Loading