Skip to content
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

Fix/package visible #368

Merged
merged 10 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
10 changes: 8 additions & 2 deletions backend/src/zango/api/platform/packages/v1/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import requests

from django.core import signing

from zango.apps.shared.tenancy.models import Domain, TenantModel
Expand Down Expand Up @@ -35,14 +37,18 @@ def get(self, request, app_uuid, *args, **kwargs):
url = get_package_configuration_url(
request, tenant, request.GET.get("package_name")
)
response = requests.get(url)
resp = {"url": f"{url}?token={token}"}
status = 200
except TypeError:
resp = {"message": "Package does not have configuration page"}
status = 404
except Exception as e:
resp = {"message": str(e)}
status = 500
return get_api_response(True, resp, status)
return get_api_response(True if status == 200 else False, resp, status)
try:
packages = get_all_packages(tenant.name)
packages = get_all_packages(request, tenant)
if search:
packages = [
obj for obj in packages if search.lower() in obj["name"].lower()
Expand Down
3 changes: 1 addition & 2 deletions backend/src/zango/apps/permissions/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from django.utils import timezone

from django.db import models
from django.db.models import JSONField, Q
from django.utils import timezone

from zango.apps.auditlogs.registry import auditlog
from zango.core.model_mixins import FullAuditMixin
Expand Down
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this file
@adhiraj23zelthy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Empty file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adhiraj23zelthy Please revert this change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@adhiraj23zelthy we can keep the file, you can copy it from the main branch and add it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

This file was deleted.

2 changes: 1 addition & 1 deletion backend/src/zango/assets/error_pages/css/error403.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@ button[type='submit'] {
}
.each-button {
margin: 10px;
}
}
2 changes: 1 addition & 1 deletion backend/src/zango/assets/error_pages/css/error404.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,4 @@
}
.each-button {
margin: 10px;
}
}
2 changes: 1 addition & 1 deletion backend/src/zango/assets/error_pages/css/error500.css
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,4 @@ button[type='submit'] {
}
.each-button {
margin: 10px;
}
}
1 change: 1 addition & 0 deletions backend/src/zango/config/urls_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from zango.core.decorators import internal_access_only


urlpatterns = [
re_path(
r"^auth/",
Expand Down
23 changes: 19 additions & 4 deletions backend/src/zango/core/internal_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import requests

from django.db import connection
from django.http.response import HttpResponse
from django.test import RequestFactory


Expand Down Expand Up @@ -37,6 +38,8 @@ def process_internal_request(fake_request, tenant, **kwargs):
ws = ws_klass(tenant, fake_request)
ws.ready()
view, resolve = ws.match_view(fake_request)
if not view:
return HttpResponse(status=404)
response = view(fake_request, (), **kwargs)
return response

Expand Down Expand Up @@ -74,7 +77,10 @@ def internal_request_post(url, **kwargs):
# Convert Django response to something that mimics requests.Response
class InternalResponse:
def __init__(self, django_response):
self.content = django_response.content
try:
self.content = getattr(django_response, "content", None)
except Exception:
self.content = None
self.status_code = django_response.status_code

def json(self):
Expand Down Expand Up @@ -111,7 +117,10 @@ def internal_request_put(url, **kwargs):
# Convert Django response to something that mimics requests.Response
class InternalResponse:
def __init__(self, django_response):
self.content = django_response.content
try:
self.content = getattr(django_response, "content", None)
except Exception:
self.content = None
self.status_code = django_response.status_code

def json(self):
Expand All @@ -138,7 +147,10 @@ def internal_request_get(url, **kwargs):
# Convert Django response to something that mimics requests.Response
class InternalResponse:
def __init__(self, django_response):
self.content = django_response.content
try:
self.content = getattr(django_response, "content", None)
except Exception:
self.content = None
self.status_code = django_response.status_code

def json(self):
Expand Down Expand Up @@ -175,7 +187,10 @@ def internal_request_delete(url, **kwargs):
# Convert Django response to something that mimics requests.Response
class InternalResponse:
def __init__(self, django_response):
self.content = django_response.content
try:
self.content = getattr(django_response, "content", None)
except Exception:
self.content = None
self.status_code = django_response.status_code

def json(self):
Expand Down
14 changes: 12 additions & 2 deletions backend/src/zango/core/package_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
import zipfile

import boto3
import requests

from botocore import UNSIGNED
from botocore.config import Config
from packaging.version import Version

from django.conf import settings
from django.core import signing
from django.db import connection

from zango.core.utils import get_current_request_url
Expand All @@ -29,10 +31,10 @@ def get_installed_packages(tenant):
return {package["name"]: package["version"] for package in packages}


def get_all_packages(tenant=None):
def get_all_packages(request, tenant=None):
installed_packages = {}
if tenant is not None:
installed_packages = get_installed_packages(tenant)
installed_packages = get_installed_packages(tenant.name)
packages = {}
s3 = boto3.client(
"s3",
Expand Down Expand Up @@ -66,6 +68,7 @@ def get_all_packages(tenant=None):
packages[package]["versions"] = [
str(version) for version in packages[package]["versions"]
]
packages[package]["config_url"] = None
for package, data in packages.items():
resp_data.append({"name": package, **data})
for local_package in installed_packages.keys():
Expand All @@ -77,6 +80,13 @@ def get_all_packages(tenant=None):
"installed_version": installed_packages[local_package],
}
)
for package in resp_data:
url = get_package_configuration_url(request, tenant, package["name"])
resp = requests.get(url)
if resp.status_code == 200:
package["config_url"] = f"{url}?token={signing.dumps(request.user.id)}"
else:
package["config_url"] = None
return resp_data


Expand Down
2 changes: 1 addition & 1 deletion backend/src/zango/templates/403.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
</div>
</div>

{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion backend/src/zango/templates/404.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
</div>
</div>

{% endblock %}
{% endblock %}
2 changes: 1 addition & 1 deletion backend/src/zango/templates/500.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
</div>
</div>

{% endblock %}
{% endblock %}
82 changes: 54 additions & 28 deletions frontend/src/mocks/appPackagesManagementHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ const range = (len) => {
return arr;
};

const newPackage = () => {
const newPackage = () => {
return {
name: 'Package ' + faker.number.int({ min: 1, max: 10 }),
name: 'Package' + faker.number.int({ min: 1, max: 10 }),
versions: ['0.1.0', '0.2.0'],
status: faker.helpers.shuffle(['Installed', 'Not Installed'])[0],
installed_version: faker.number.int({ min: 1, max: 10 }),
config_url: null
};
};

Expand Down Expand Up @@ -46,7 +47,7 @@ export const appPackagesManagementHandlers = [
(pageIndex + 1) * pageSize
);

if (action === 'config_url') {
if (action === 'config_url' && !req.url.searchParams.get('package_name')) {
return res(
ctx.delay(500),
ctx.status(200),
Expand All @@ -57,33 +58,58 @@ export const appPackagesManagementHandlers = [
},
})
);
}

return res(
ctx.delay(500),
ctx.status(200),
ctx.json({
success: true,
response: {
packages: {
total_records: totalData,
total_pages: Math.ceil(data.length / pageSize),
next: 'http://localhost:8000/api/v1/auth/platform-users/?page=2',
previous: null,
records: searchValue ? [] : slicedData,
}else if(action === 'config_url' && req.url.searchParams.get('package_name')){
if (req.url.searchParams.get('package_name') === 'Package1') {
return res(
ctx.delay(500),
ctx.status(200),
ctx.json({
success: true,
response: {
message: 'Package do have a configuration page',
},
dropdown_options: {
policies: [
{ id: 1, label: 'Policy 1' },
{ id: 2, label: 'Policy 2' },
{ id: 3, label: 'Policy 3' },
{ id: 4, label: 'Policy 4' },
],
})
);
}else{
return res(
ctx.delay(500),
ctx.status(200),
ctx.json({
success: false,
response: {
message: 'Package does not have configuration page',
},
})
);
}
}
else{
return res(
ctx.delay(500),
ctx.status(200),
ctx.json({
success: true,
response: {
packages: {
total_records: totalData,
total_pages: Math.ceil(data.length / pageSize),
next: 'http://localhost:8000/api/v1/auth/platform-users/?page=2',
previous: null,
records: searchValue ? [] : slicedData,
},
dropdown_options: {
policies: [
{ id: 1, label: 'Policy 1' },
{ id: 2, label: 'Policy 2' },
{ id: 3, label: 'Policy 3' },
{ id: 4, label: 'Policy 4' },
],
},
message: 'Success',
},
message: 'Success',
},
})
);
})
);
}
}),

rest.post('/api/v1/apps/:appId/packages/', (req, res, ctx) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ export default function RowMenu({ rowData }) {
dispatch(openIsInstallPackageModalOpen(rowData));
};

if(rowData.config_url==null && rowData.status?.toLowerCase()=='installed'){
return null;
}

return (
<Menu as="div" className="relative flex">
<Menu.Button
Expand Down Expand Up @@ -94,9 +98,6 @@ export default function RowMenu({ rowData }) {
<span className="text-start font-lato text-[14px] font-bold leading-[20px] tracking-[0.2px] text-[#212429]">
Configure Package
</span>
{/* <span className="text-start font-lato text-[12px] leading-[16px] tracking-[0.2px] text-[#6C747D]">
configure
</span> */}
</div>
</button>
)}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { useState, useEffect } from "react";
import { ReactComponent as DetailEyeIcon } from '../../../../assets/images/svg/detail-eye-icon.svg';
import { openIsConfigurePackageModalOpen } from "../../slice";

const ViewDetailButton = ({info,dispatch})=>{
let configUrl = info.row.original.config_url
const [disable,setDisable] = useState(true)
useEffect(()=>{
setDisable(configUrl!==null)
},[])

return <div className="flex h-full flex-col border-b border-[#F0F3F4] px-[20px] py-[14px]">
<button
className="flex items-center gap-[12px] disabled:opacity-25"
onClick={() => {
dispatch(openIsConfigurePackageModalOpen(info.row.original));
}}
disabled={!disable}
>
<span
className={`w-fit min-w-max rounded-[15px] text-center font-lato text-[14px] font-normal capitalize leading-[20px] tracking-[0.2px] text-[#5048ED]`}
>
View Details
</span>
<DetailEyeIcon />
</button>
</div>

}

export default ViewDetailButton;
Loading
Loading