Skip to content

Commit

Permalink
add tags to activity feed
Browse files Browse the repository at this point in the history
  • Loading branch information
Mubangizi committed Jul 19, 2024
1 parent 6cf5e9b commit 268c1ad
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 23 deletions.
5 changes: 4 additions & 1 deletion api_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,10 @@ paths:
type: string
project_type:
type: string
tags_add:
type: array
items:
type: string
produces:
- application/json
responses:
Expand Down Expand Up @@ -3703,7 +3707,6 @@ paths:
500:
description: "Internal Server Error"


"/tags":
post:
tags:
Expand Down
27 changes: 20 additions & 7 deletions app/controllers/activity_feed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from app.models.app import App
from app.models.tags import Tag
from app.schemas.app import AppSchema
from app.schemas.project import ProjectSchema
from app.schemas.project import ProjectListSchema
from app.schemas.tags import TagListSchema
from app.schemas.user import UserSchema
from flask import current_app
from flask_restful import Resource, request
Expand All @@ -13,17 +15,17 @@
class ActivityFeedView(Resource):
@jwt_required
def get(self):
current_user_id = get_jwt_identity()
current_user = User.get_by_id(current_user_id)
project_schema = ProjectSchema()
current_user = User.get_by_id(get_jwt_identity())
project_schema = ProjectListSchema()
app_schema = AppSchema()
tag_schema = TagListSchema()
user_schema = UserSchema()

params = {
'general': True,
'operations': ['Create', 'Update', 'Delete', 'Follow'],
'statuses': ['Success'],
'models': ['Project', 'App', 'Database', 'User' ]
'models': ['Project', 'App', 'Database', 'User']
}
user_id = request.args.get('user_id', None)
if user_id:
Expand All @@ -32,12 +34,15 @@ def get(self):
return dict(status='fail', message='User not found'), 404
params['user_id'] = user_id

following = current_user.followed
following = current_user.followed.all()
if following and not user_id:
params['user_ids'] = [user.id for user in following]

LOGGER_APP_URL = current_app.config.get('LOGGER_APP_URL')
tags_followed = current_user.followed_tags
if tags_followed:
params['a_tag_ids'] = [tag.tag_id for tag in tags_followed]

LOGGER_APP_URL = current_app.config.get('LOGGER_APP_URL')
user_feed = requests.get(
f"{LOGGER_APP_URL}/api/activities",
params=params,
Expand All @@ -58,6 +63,14 @@ def get(self):
project = Project.get_by_id(item['a_project_id'])
project_data, _ = project_schema.dump(project)
item['project'] = project_schema.dump(project_data)[0]
tags_list = item.get('a_tag_ids', [])
if tags_list and len(tags_list) > 0:
tags = []
for tag_id in item['a_tag_ids']:
tag = Tag.get_by_id(tag_id)
tag_data, _ = tag_schema.dump(tag)
tags.append(tag_data)
item['tags'] = tags
if item['model'] == 'App':
app = App.get_by_id(item['a_app_id'])
app_data, _ = app_schema.dump(app)
Expand Down
11 changes: 8 additions & 3 deletions app/controllers/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ def post(self):
user_id=project.owner_id
)
project.users.append(new_role)

if validated_project_data['tags_add']:

tags = None
if validated_project_data.get('tags_add'):
tags = validated_project_data['tags']
validated_project_data.pop('tags', None)

Expand Down Expand Up @@ -201,9 +202,13 @@ def post(self):
return dict(status='fail', message=str(e.body)), check_kube_error_code(e.status)

except Exception as err:
try:
err = err.body
except:
err = str(err)
log_activity('Project', status='Failed',
operation='Create',
description=err.body,
description=err,
a_cluster_id=cluster_id)
return dict(status='fail', message=str(err)), 500

Expand Down
14 changes: 5 additions & 9 deletions app/controllers/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@
from app.models.app import App
from app.helpers.crane_app_logger import logger

from app.helpers.email_validator import is_valid_email
from app.helpers.email_validator import is_valid_email

from collections import Counter

class UsersView(Resource):

Expand All @@ -48,16 +47,15 @@ def post(self):
user_data = request.get_json()

validated_user_data, errors = user_schema.load(user_data)

if errors:
return dict(status="fail", message=errors), 400

email = validated_user_data.get('email', None)

if not is_valid_email(email):
return dict(status='fail', message=f'Invalid email address'), 400



client_base_url = os.getenv(
'CLIENT_BASE_URL',
f'https://{request.host}/users'
Expand All @@ -71,8 +69,6 @@ def post(self):
template = "user/verify.html"
subject = "Please confirm your email"



# get the customer role
user_role = Role.find_first(name='customer')

Expand Down Expand Up @@ -1246,7 +1242,7 @@ def get(self, user_id):
user = User.get_by_id(user_id)
user_schema = UserSchema(many=True)

followed = user.followed
followed = user.followed.all()
users_data, errors = user_schema.dumps(followed)

if errors:
Expand Down
2 changes: 0 additions & 2 deletions app/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
from ..models import db

from app.models.model_mixin import ModelMixin
from app.models.credits import Credit
from app.models.credit_assignments import CreditAssignment

class Followers(ModelMixin):
""" followers table definition """
Expand Down
7 changes: 7 additions & 0 deletions app/schemas/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ def get_description(self, obj):
return obj.project.description


class ProjectListSchema(Schema):
id = fields.UUID(dump_only=True)
name = fields.String()
description = fields.String()
tags = fields.Nested("TagsProjectsSchema", many=True, dump_only=True)


class ProjectSchema(Schema):

id = fields.UUID(dump_only=True)
Expand Down
5 changes: 4 additions & 1 deletion app/schemas/tags.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from app.schemas.project import ProjectIndexSchema
from app.schemas.project_users import UserRoleSchema
from marshmallow import Schema, fields

class TagListSchema(Schema):
id = fields.UUID(dump_only=True)
name = fields.String(required=True)
is_super_tag = fields.Boolean()

class TagSchema(Schema):

Expand Down

0 comments on commit 268c1ad

Please sign in to comment.