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

User portal copyright with images #813

Merged
merged 12 commits into from
Oct 16, 2023
Merged
3 changes: 2 additions & 1 deletion src/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ deployment/aws/
*.sqlite3*
test_data/
celerybeat-schedule.db
*.rdb*
*.rdb*
venv
4 changes: 4 additions & 0 deletions src/api/handlers/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#from types import FunctionType as function
from _main_.utils.context import Context
from api.decorators import admins_only, super_admins_only, login_required
from api.store.common import expect_media_fields


class ActionHandler(RouteHandler):
Expand Down Expand Up @@ -91,6 +92,7 @@ def submit(self, request):
.expect("vendors", list, is_required=False)
.expect("action_id", str, is_required=False)
)
self = expect_media_fields(self)

args, err = self.validator.verify(args)
if err:
Expand Down Expand Up @@ -151,6 +153,8 @@ def update(self, request):
.expect("vendors", list, is_required=False)
)

self = expect_media_fields(self)

args, err = self.validator.verify(args)
if err:
return err
Expand Down
4 changes: 4 additions & 0 deletions src/api/handlers/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from types import FunctionType as function
from _main_.utils.context import Context
from api.decorators import admins_only, super_admins_only, login_required
from api.store.common import expect_media_fields


class EventHandler(RouteHandler):
Expand Down Expand Up @@ -221,6 +222,7 @@ def submit(self, request):
self.validator.expect('rsvp_enabled', bool)
self.validator.expect('rsvp_email', bool)
self.validator.expect('event_id', str)
self = expect_media_fields(self)
args, err = self.validator.verify(args)

if err:
Expand Down Expand Up @@ -310,6 +312,8 @@ def update(self, request):
self.validator.expect("event_type",str)
self.validator.expect("publicity_selections","str_list")
self.validator.expect("shared_to","str_list")

self = expect_media_fields(self)
args, err = self.validator.verify(args)

if err:
Expand Down
33 changes: 11 additions & 22 deletions src/api/handlers/media_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from api.decorators import admins_only
from api.services.media_library import MediaLibraryService
from _main_.utils.massenergize_response import MassenergizeResponse
from api.store.common import expect_media_fields


class MediaLibraryHandler(RouteHandler):
Expand Down Expand Up @@ -37,7 +38,7 @@ def fetch_content(self, request):
return error
return MassenergizeResponse(data=images)

@admins_only
@admins_only
def search(self, request):
"""Filters images and only retrieves content related to a scope(events, testimonials,actions etc). More search types to be added later when requested..."""
context: Context = request.context
Expand All @@ -48,7 +49,7 @@ def search(self, request):
"user_ids", "str_list"
).expect(
"keywords", "str_list"
)
).expect("public", str)
args, err = self.validator.verify(args, strict=True)
if err:
return err
Expand Down Expand Up @@ -80,25 +81,14 @@ def addToGallery(self, request):
args: dict = context.args
self.validator.expect("user_id", str, is_required=True).expect(
"community_ids", list
).expect("title", str).expect("file", "file", is_required=True).expect(
).expect("publicity", str).expect("title", str).expect(
"file", "file", is_required=True
).expect(
"is_universal", bool
).expect(
"tags", "str_list"
).expect(
"size", str
).expect(
"size_text", str
).expect(
"description"
).expect(
"underAge", bool
).expect(
"copyright", bool
).expect(
"copyright_att", str
).expect(
"guardian_info", str
)
self = expect_media_fields(self)
args, err = self.validator.verify(args, strict=True)
if err:
return err
Expand Down Expand Up @@ -137,22 +127,21 @@ def find_images(self, request):
return error
return MassenergizeResponse(data=response)

@admins_only
@admins_only
def edit_details(self, request):
"""Saves changes to updated image details"""
context: Context = request.context
args: dict = context.args
self.validator.expect("description").expect("underAge", bool).expect(
"copyright", bool
).expect("copyright_att", str).expect("guardian_info", str).expect(
self.validator.expect(
"tags", "str_list"
).expect(
"community_ids", list
).expect(
"media_id", int, is_required=True
).expect(
"user_upload_id", int, is_required=True
)
).expect("publicity", str)
self = expect_media_fields(self)
args, err = self.validator.verify(args, strict=True)
if err:
return err
Expand Down
4 changes: 4 additions & 0 deletions src/api/handlers/testimonial.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from _main_.utils.context import Context
from _main_.utils.validator import Validator
from api.decorators import admins_only, super_admins_only, login_required
from api.store.common import expect_media_fields


class TestimonialHandler(RouteHandler):
Expand Down Expand Up @@ -94,6 +95,7 @@ def submit(self, request):
self.validator.rename('preferredName', 'preferred_name')
self.validator.expect('testimonial_id', str)
self.validator.expect("image", "file", is_required=False)
self = expect_media_fields(self)
args, err = self.validator.verify(args)

if err:
Expand Down Expand Up @@ -144,6 +146,8 @@ def update(self, request):
self.validator.rename('action_id', 'action')
self.validator.rename('vendor_id', 'vendor')
self.validator.expect("image", "str_list")

self = expect_media_fields(self)
args, err = self.validator.verify(args)

if err:
Expand Down
13 changes: 12 additions & 1 deletion src/api/handlers/vendor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from _main_.utils.context import Context
from _main_.utils.validator import Validator
from api.decorators import admins_only, super_admins_only, login_required
from api.store.common import expect_media_fields



Expand Down Expand Up @@ -107,7 +108,16 @@ def submit(self, request):
.expect("location", str, is_required=False)
.expect("vendor_id", str)

)
)
# self.validator.expect("size", str)
# self.validator.expect("size_text", str)
# self.validator.expect("description")
# self.validator.expect("underAge", bool)
# self.validator.expect("copyright", bool)
# self.validator.expect("copyright_att", str)
# self.validator.expect("guardian_info", str)

self = expect_media_fields(self)

args, err = self.validator.verify(args)
if err:
Expand Down Expand Up @@ -160,6 +170,7 @@ def update(self, request):
.expect("location", "location", is_required=False)
)

self = expect_media_fields(self)
args, err = self.validator.verify(args)
if err:
return err
Expand Down
36 changes: 20 additions & 16 deletions src/api/services/media_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ def fetch_content(self, args):
return self.organiseData(data=serialize_all(images, True), args=args), None

def search(self, args, context):
images, error = self.store.search(args,context)
images, meta, error = self.store.search(args, context)
if error:
return None, error
return self.organiseData(data=serialize_all(images), args=args), None
organised = self.organiseData(data=serialize_all(images), args=args)
organised["meta"] = meta
return organised, None

def organiseData(self, **kwargs):
data = kwargs.get("data") or []
Expand All @@ -40,28 +42,30 @@ def organiseData(self, **kwargs):
"images": data,
}

def remove(self, args,context):
response, error = self.store.remove(args,context)
def remove(self, args, context):
response, error = self.store.remove(args, context)
if error:
return None, error
return response, None

def addToGallery(self, args,context):
image, error = self.store.addToGallery(args,context)
def addToGallery(self, args, context):
image, error = self.store.addToGallery(args, context)
if error:
return None, error
return image.simple_json(), None
def edit_details(self, args,context):
media, error = self.store.edit_details(args,context)

def edit_details(self, args, context):
media, error = self.store.edit_details(args, context)
if error:
return None, error
if media:
return self.getImageInfo({"media_id": media.id}) # Refer back to the getinfo routine so that data can be returned in the same structture
if media:
return self.getImageInfo(
{"media_id": media.id}
) # Refer back to the getinfo routine so that data can be returned in the same structture
return {}, None
def find_images(self, args,context):
images, error = self.store.find_images(args,context)

def find_images(self, args, context):
images, error = self.store.find_images(args, context)
if error:
return None, error
images = serialize_all(images)
Expand All @@ -79,7 +83,7 @@ def getImageInfo(self, args):
events = serialize_all(media.events.all())
actions = serialize_all(media.actions.all())
testimonials = serialize_all(media.testimonials.all())
vendors = serialize_all(media.vender_logo.all()) # yhup, thats right. lmfao!
vendors = serialize_all(media.vender_logo.all()) # yhup, thats right. lmfao!
media_json = get_json_if_not_none(media, True)
return {
**media_json,
Expand All @@ -88,6 +92,6 @@ def getImageInfo(self, args):
"event": events,
"action": actions,
"testimonial": testimonials,
"vendor": vendors
"vendor": vendors,
},
}, None
34 changes: 27 additions & 7 deletions src/api/store/action.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from _main_.utils.footage.FootageConstants import FootageConstants
from _main_.utils.footage.spy import Spy
from api.tests.common import RESET
from _main_.utils.utils import Console
from api.store.common import get_media_info, make_media_info
from api.tests.common import RESET, makeUserUpload
from api.utils.api_utils import is_admin_of_community
from api.utils.filter_functions import get_actions_filter_params
from database.models import Action, UserProfile, Community, Media
Expand Down Expand Up @@ -72,6 +74,7 @@ def create_action(self, context: Context, args, user_submitted) -> Tuple[dict, M
calculator_action = args.pop('calculator_action', None)
title = args.get('title', None)
user_email = args.pop('user_email', context.user_email)
image_info = make_media_info(args)

# check if there is an existing action with this name and community
actions = Action.objects.filter(title=title, community__id=community_id, is_deleted=False)
Expand All @@ -90,6 +93,9 @@ def create_action(self, context: Context, args, user_submitted) -> Tuple[dict, M
if user_submitted:
name = f'ImageFor {new_action.title} Action'
media = Media.objects.create(name=name, file=images)
# create user media upload here
user_media_upload = makeUserUpload(media = media,info=image_info, communities=[community])

else:
media = Media.objects.filter(pk = images[0]).first()
new_action.image = media
Expand All @@ -104,6 +110,9 @@ def create_action(self, context: Context, args, user_submitted) -> Tuple[dict, M
user = UserProfile.objects.filter(email=user_email).first()
if user:
new_action.user = user
if user_media_upload:
user_media_upload.user = user
user_media_upload.save()

#save so you set an id
new_action.save()
Expand Down Expand Up @@ -192,6 +201,7 @@ def copy_action(self, context: Context, args) -> Tuple[Action, MassEnergizeAPIEr

def update_action(self, context: Context, args, user_submitted) -> Tuple[dict, MassEnergizeAPIError]:
try:
image_info = make_media_info(args)
action_id = args.pop('action_id', None)
actions = Action.objects.filter(id=action_id)
if not actions:
Expand Down Expand Up @@ -233,20 +243,35 @@ def update_action(self, context: Context, args, user_submitted) -> Tuple[dict, M
actions.update(**args)
action = actions.first() # refresh after update


if community_id and not args.get('is_global', False):
community = Community.objects.filter(id=community_id).first()
if community:
action.community = community
else:
action.community = None

if image: #now, images will always come as an array of ids, or "reset" string
if user_submitted:
if "ImgToDel" in image:
action.image = None
else:
image= Media.objects.create(file=image, name=f'ImageFor {action.title} Action')
action.image = image
makeUserUpload(media = image,info=image_info, user = action.user, communities=[community])
else:
if image[0] == RESET: #if image is reset, delete the existing image
action.image = None
else:
media = Media.objects.filter(id = image[0]).first()
action.image = media

if action.image:
old_image_info, can_save_info = get_media_info(action.image)
if can_save_info:
action.image.user_upload.info.update({**old_image_info,**image_info})
action.image.user_upload.save()

action.steps_to_take = steps_to_take
action.deep_dive = deep_dive

Expand All @@ -256,12 +281,7 @@ def update_action(self, context: Context, args, user_submitted) -> Tuple[dict, M
if vendors:
action.vendors.set(vendors)

if community_id and not args.get('is_global', False):
community = Community.objects.filter(id=community_id).first()
if community:
action.community = community
else:
action.community = None


if calculator_action:
ccAction = CCAction.objects.filter(pk=calculator_action).first()
Expand Down
Loading