Skip to content

Commit

Permalink
Merge branch 'microservice' into email-validator
Browse files Browse the repository at this point in the history
  • Loading branch information
CHRISTOPHERKADOGO committed Jul 16, 2024
2 parents 8974de9 + a7cabeb commit 91cc784
Show file tree
Hide file tree
Showing 23 changed files with 781 additions and 249 deletions.
110 changes: 103 additions & 7 deletions api_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2529,6 +2529,14 @@ paths:
type: string
project_type:
type: string
tags_add:
type: array
items:
type: string
tags_remove:
type: array
items:
type: string
responses:
200:
description: "Success"
Expand Down Expand Up @@ -3641,10 +3649,10 @@ paths:
500:
description: "Internal Server Error"

"/projects/tags/{tag_id}":
"/tags/{tag_id}":
get:
tags:
- projects
- tags
consumes:
- application/json
produces:
Expand All @@ -3670,7 +3678,7 @@ paths:

delete:
tags:
- projects
- tags
consumes:
- application/json
produces:
Expand All @@ -3696,10 +3704,10 @@ paths:
description: "Internal Server Error"


"/projects/tags":
"/tags":
post:
tags:
- projects
- tags
consumes:
- application/json
parameters:
Expand All @@ -3716,7 +3724,7 @@ paths:
- name
items:
type: string

produces:
- application/json
responses:
Expand All @@ -3729,7 +3737,7 @@ paths:

get:
tags:
- projects
- tags
consumes:
- application/json
produces:
Expand All @@ -3752,6 +3760,94 @@ paths:
500:
description: "Internal Server Error"

"/tags/{tag_id}/following":
get:
tags:
- tags
consumes:
- application/json
produces:
- application/json
parameters:
- in: header
name: Authorization
required: true
description: "Bearer [token]"
- in: path
name: tag_id
required: true
type: string
- in: query
name: page
type: integer
description: Page number
- in: query
name: per_page
type: integer
description: Number of items per page
responses:
200:
description: "Success"
404:
description: "Tag not found"
400:
description: "Bad request"
500:
description: "Internal Server Error"

post:
tags:
- tags
consumes:
- application/json
produces:
- application/json
parameters:
- in: header
name: Authorization
required: true
description: "Bearer [token]"
type: string
- in: path
name: tag_id
required: true
type: string
responses:
201:
description: "Success"
404:
description: "Tag not found"
400:
description: "Bad request"
500:
description: "Internal Server Error"

delete:
tags:
- tags
consumes:
- application/json
produces:
- application/json
parameters:
- in: header
name: Authorization
required: true
description: "Bearer [token]"
type: string
- in: path
name: tag_id
required: true
type: string
responses:
200:
description: "Success"
404:
description: "Tag not found"
400:
description: "Bad request"
500:
description: "Internal Server Error"

components:
securitySchemes:
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from .user_role import UserRolesView
from .transactions import TransactionRecordView, TransactionRecordDetailView, CreditTransactionRecordView, CreditPurchaseTransactionRecordView
from .project import (
ProjectsView, ProjectDetailView, UserProjectsView, ProjectGetCostsView, ClusterProjectsView,ProjectPinView,
ProjectsView, ProjectDetailView, UserProjectsView, ProjectGetCostsView, ClusterProjectsView, ProjectPinView,
ProjectDisableView, ProjectEnableView)
from .app import (AppsView, ProjectAppsView, AppDetailView, AppLogsView,
AppRevertView, AppReviseView, AppRedeployView, AppDisableView, AppEnableView, AppDockerWebhookListenerView)
Expand All @@ -30,4 +30,4 @@
from .system_status import SystemSummaryView
from .project_users import ProjectUsersView, ProjectUsersTransferView, ProjectUsersHandleInviteView, ProjectFollowingView
from .activity_feed import ActivityFeedView
from .project_tags import ProjectTagsView, ProjectTagsDetailView
from .tags import TagsView, TagsDetailView, TagFollowingView
10 changes: 8 additions & 2 deletions app/controllers/activity_feed.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from app.models.app import App
from app.schemas.app import AppSchema
from app.schemas.project import ProjectSchema
from app.schemas.user import UserSchema
from flask import current_app
from flask_restful import Resource, request
from app.models.user import User
Expand All @@ -16,12 +17,13 @@ def get(self):
current_user = User.get_by_id(current_user_id)
project_schema = ProjectSchema()
app_schema = AppSchema()
user_schema = UserSchema()

params = {
'general': True,
'operations': ['Create', 'Update', 'Delete'],
'operations': ['Create', 'Update', 'Delete', 'Follow'],
'statuses': ['Success'],
'models': ['Project', 'App', 'Database', ]
'models': ['Project', 'App', 'Database', 'User' ]
}
user_id = request.args.get('user_id', None)
if user_id:
Expand Down Expand Up @@ -60,6 +62,10 @@ def get(self):
app = App.get_by_id(item['a_app_id'])
app_data, _ = app_schema.dump(app)
item['app'] = app_schema.dump(app_data)[0]
if item['model'] == 'User' and item['a_user_id'] != None:
user = User.get_by_id(item['a_user_id'])
user_data, _ = user_schema.dump(user)
item['a_user'] = user_schema.dump(user_data)[0]
elif item['model'] == 'Database':
pass
user_feed['data']['activity'] = user_activities
Expand Down
25 changes: 22 additions & 3 deletions app/controllers/project.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import datetime
import json
from types import SimpleNamespace
import uuid
from app.helpers.cost_modal import CostModal
from app.helpers.alias import create_alias
from app.helpers.admin import is_authorised_project_user, is_owner_or_admin, is_current_or_admin, is_admin
from app.helpers.role_search import has_role
from app.helpers.activity_logger import log_activity
from app.helpers.kube import create_kube_clients, delete_cluster_app, disable_project, enable_project, check_kube_error_code
from app.helpers.tags import add_tags_to_project, create_tags, remove_tags_from_project
from app.models.billing_invoice import BillingInvoice
from app.models.project_users import ProjectUser
from app.models.user import User
Expand All @@ -15,6 +17,7 @@
from app.schemas import ProjectSchema, AppSchema, ProjectUserSchema, ClusterSchema
from app.helpers.decorators import admin_required
import datetime
from app.schemas.tags import TagSchema
from flask_restful import Resource, request
from kubernetes import client
from flask_jwt_extended import jwt_required, get_jwt_identity, get_jwt_claims
Expand Down Expand Up @@ -57,6 +60,7 @@ def post(self):
message=f'''project with name {
validated_project_data["name"]} already exists'''
), 409

try:
validated_project_data['alias'] =\
create_alias(validated_project_data['name'])
Expand Down Expand Up @@ -131,6 +135,10 @@ def post(self):
)
project.users.append(new_role)

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

saved = project.save()

if not saved:
Expand All @@ -143,6 +151,8 @@ def post(self):
kube_client.kube.delete_namespace(namespace_name)

return dict(status="fail", message="Internal Server Error"), 500
if tags:
add_tags_to_project(tags, project)

# create a billing invoice on project creation
new_invoice = BillingInvoice(project_id=project.id)
Expand Down Expand Up @@ -491,7 +501,7 @@ def patch(self, project_id):
current_user_roles = get_jwt_claims()['roles']

project_schema = ProjectSchema(
only=("name", "description", "organisation", "project_type"), partial=True)
only=("name", "description", "organisation", "project_type", "tags_add", "tags_remove"), partial=True)

project_data = request.get_json()

Expand Down Expand Up @@ -523,6 +533,15 @@ def patch(self, project_id):
if not is_authorised_project_user(project, current_user_id, 'admin'):
return dict(status='fail', message='unauthorised'), 403

if validate_project_data.get('tags_add'):
add_tags_to_project(
validate_project_data['tags_add'], project)
validate_project_data.pop('tags_add', None)
if validate_project_data.get('tags_remove'):
remove_tags_from_project(
validate_project_data['tags_remove'], project)
validate_project_data.pop('tags_remove', None)

updated = Project.update(project, **validate_project_data)

if not updated:
Expand Down Expand Up @@ -577,7 +596,7 @@ def get(self, user_id):
).all()

pagination_meta_data, projects = paginate(
user.projects, per_page, page)
user.projects[::-1], per_page, page)

user_projects, errors = project_schema.dumps(
projects)
Expand All @@ -591,7 +610,7 @@ def get(self, user_id):
status='success',
data=dict(
pagination={**pagination_meta_data,
'pinned_count': len(pinned_projects)},
'pinned_count': len(json.loads(pinned_projects))},
pinned=json.loads(pinned_projects),
projects=json.loads(user_projects),
)
Expand Down
88 changes: 0 additions & 88 deletions app/controllers/project_tags.py

This file was deleted.

Loading

0 comments on commit 91cc784

Please sign in to comment.