Skip to content

Commit

Permalink
Setting the share state without cron
Browse files Browse the repository at this point in the history
  • Loading branch information
Hrishikesh Jadhav committed Jan 25, 2024
1 parent 79d5c1d commit 3b5cf7d
Show file tree
Hide file tree
Showing 18 changed files with 143 additions and 5 deletions.
Binary file removed 1c90cd98-5b00-456a-bd41-78b7b9081d16.prof
Binary file not shown.
Binary file removed 1d761003-f427-4239-8dff-8a85ee21bad9.prof
Binary file not shown.
Binary file removed 1e49eb5d-8b33-4888-8c2e-7686b339baae.prof
Binary file not shown.
Binary file removed 5aa6fe36-4004-445b-bb5e-8eade9cfe4e9.prof
Binary file not shown.
46 changes: 46 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Use an official Python runtime as a parent image
FROM python:alpine

# Set the working directory to /backend
WORKDIR /backend

# Copy the current directory contents into the container at /backend
COPY . .

# Install system dependencies
# RUN apt-get update \
# && apt-get install -y binutils libproj-dev gdal-bin \
# && rm -rf /var/lib/apt/lists/*

RUN apk update

RUN wget https://download.osgeo.org/gdal/3.8.3/gdal-3.8.3.tar.gz
RUN tar xzf gdal-3.8.3.tar.gz
RUN cd gdal-3.8.3
RUN ./configure
RUN make
RUN make install
RUN cd ..

# RUN echo "GDAL_LIBRARY_PATH = '/home/sue/local/lib/libgdal.so'" >> ./backend/settings.py
# Create a virtual environment and activate it
RUN python -m venv venv
ENV PATH="/backend/venv/bin:$PATH"

# Install Python dependencies
RUN pip install --upgrade pip
RUN pip install -r requirements.txt

# Make build.sh executable
# RUN chmod +x build.sh

# # Run the build.sh script
# RUN ./build.sh

RUN python manage.py migrate

# Expose port 8000 for Django application
EXPOSE 8000

# Command to run your application
CMD ["/backend/venv/bin/python", "manage.py", "runserver", "0.0.0.0:8000"]
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash


pip install --upgrade pip
set -o errexit # exit on error

Expand Down
Binary file removed f3583cb4-e5fd-41dd-b659-ff2852335d31.prof
Binary file not shown.
Binary file modified fileoperations/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file modified fileoperations/__pycache__/serializers.cpython-39.pyc
Binary file not shown.
Binary file modified fileoperations/__pycache__/views.cpython-39.pyc
Binary file not shown.
44 changes: 44 additions & 0 deletions fileoperations/migrations/0019_file_info.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Generated by Django 4.2.6 on 2024-01-23 07:11

from django.db import migrations, models
import django.db.models.deletion
import uuid


class Migration(migrations.Migration):
dependencies = [
("logic", "0010_userinfo_is_active"),
("fileoperations", "0018_accesslog_profile_pic"),
]

operations = [
migrations.CreateModel(
name="File_Info",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4, primary_key=True, serialize=False
),
),
("depts", models.ManyToManyField(to="logic.departments")),
(
"file",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="fileoperations.objects",
),
),
(
"org",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
to="logic.organizations",
),
),
],
options={
"db_table": "file_info",
},
),
]
Binary file not shown.
9 changes: 9 additions & 0 deletions fileoperations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ class Meta:
db_table = 'storage"."objects'
unique_together = (('bucket', 'name'),)

class File_Info(models.Model):
id = models.UUIDField(primary_key=True,default=uuid4)
file = models.ForeignKey(Objects,on_delete=models.CASCADE)
org = models.ForeignKey(Organizations,on_delete=models.CASCADE)
depts = models.ManyToManyField(Departments)

class Meta:
db_table = "file_info"



# managed
Expand Down
3 changes: 3 additions & 0 deletions fileoperations/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ def create(self, validated_data):
security_check = validated_data.pop('security_check')
file_name = validated_data['file'].name
expiration_time = validated_data['expiration_time']
# Setting the state of the share to active or due
state = "active" if (int(expiration_time)>259200) else "due"
validated_data["state"] = state
signed_url = supabase.storage.from_(self.BUCKET_NAME).create_signed_url(file_name, expiration_time)['signedURL']
validated_data['signed_url'] = signed_url

Expand Down
1 change: 1 addition & 0 deletions fileoperations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ def share_file(self, request):
return Response(
{"error": "file should be a list"}, status=status.HTTP_400_BAD_REQUEST
)

for file_id in file_ids:
if self.check_file_ownership(request, file_id):
request.data.pop("file")
Expand Down
Binary file modified logic/__pycache__/views.cpython-39.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions logic/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ def get_permissions(self):
return super().get_permissions()



# User Viewset for Normal users
class NUserViewSet(mixins.ListModelMixin, mixins.UpdateModelMixin, GenericViewSet):
authentication_classes = [SupabaseAuthBackend]
Expand Down
43 changes: 38 additions & 5 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,26 +1,59 @@
annotated-types==0.6.0
anyio==4.1.0
asgiref==3.7.2
async-timeout==4.0.3
attrs==23.1.0
autopep8==2.0.4
certifi==2023.11.17
deprecation==2.1.0
Django==4.2.6
django-cors-headers==4.3.0
django-location-field==2.7.2
django-redis==5.4.0
django-rest-framework==0.1.0
djangorestframework-gis==1.0
django-silk==5.0.4
djangorestframework==3.14.0
djangorestframework-gis==1.0
drf-spectacular==0.26.5
exceptiongroup==1.2.0
flake8==6.1.0
gotrue==1.3.1
gprof2dot==2022.7.29
gunicorn==20.1.0
h11==0.14.0
httpcore==0.17.3
httpx==0.24.1
idna==3.6
inflection==0.5.1
jsonschema==4.19.1
jsonschema-specifications==2023.7.1
mccabe==0.7.0
packaging==23.2
postgrest==0.11.0
psycopg2-binary==2.9.9
pycodestyle==2.11.1
pydantic==2.5.2
pydantic_core==2.14.5
pyflakes==3.1.0
PyJWT==2.8.0
python-dateutil==2.8.2
python-decouple==3.8
pytz==2023.3.post1
PyYAML==6.0.1
realtime==1.0.2
redis==5.0.1
referencing==0.30.2
rpds-py==0.10.6
six==1.16.0
sniffio==1.3.0
sqlparse==0.4.4
storage3==0.6.1
StrEnum==0.4.15
supabase==1.2.0
supafunc==0.2.3
tomli==2.0.1
typing_extensions==4.8.0
uritemplate==4.1.1
uuid==1.30
gunicorn==20.1.0
supabase==1.2.0
django-redis==5.4.0
redis==5.0.1
websockets==11.0.3
gunicorn==20.1.0

0 comments on commit 3b5cf7d

Please sign in to comment.