def has_object_permission(self, request, view, obj): return_flag = False authority = get_authority_for_bench_and_user_and_requester( obj, request.user) # Read permissions are allowed to any request, # Write permissions are allowed if the user is a SuperUser. if request.method in permissions.SAFE_METHODS: # A Users Authority must either be Editor, Owner or Admin for Write permission. if authority.is_viewer() == True or authority.is_editor( ) == True or authority.is_owner() == True or authority.is_admin( ) == True: return_flag = True else: if request.user.is_superuser == True: return_flag = True else: # Write permissions are allowed for the owner of the bench/image. if obj.owner == request.user: # A Users must have a Credential record and a Password to write to WordPress. if credential_exists( request.user) == True and credential_apppwd( request.user) != '': return_flag = True else: # A Users Authority must either be Editor, Owner or Admin for Write permission. if authority.is_editor() == True or authority.is_owner( ) == True or authority.is_admin() == True: # A Users must have a Credential record and a Password to write to WordPress. if credential_exists( request.user) == True and credential_apppwd( request.user) != '': return_flag = True return return_flag
def has_permission(self, request, view): return_flag = False # Read permissions are allowed to any request, # Write permissions are allowed if the user is a SuperUser. if request.user.is_superuser == True: return_flag = True else: # A Users must have a Credential record and a Password to write to WordPress. if credential_exists(request.user) == True and credential_apppwd(request.user) != '': return_flag = True return return_flag
def shuffle_rows(request): """ AJAX - Shuffle the Rows """ source = request.POST['source'] target = request.POST['target'] in_source_cell = get_object_or_404(Cell, pk=source) in_target_cell = get_object_or_404(Cell, pk=target) source_ycoordinate = in_source_cell.ycoordinate target_ycoordinate = in_target_cell.ycoordinate matrix = in_source_cell.matrix owner = get_object_or_404(User, pk=matrix.owner_id) user = get_object_or_404(User, pk=request.user.id) if credential_exists(user): authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() or authority.is_none(): data = { 'failure': True, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: source_row_cells = matrix.get_row(source_ycoordinate) if source_ycoordinate < target_ycoordinate: oldCells = Cell.objects.filter(matrix=matrix.id).filter( ycoordinate__gt=source_ycoordinate).filter( ycoordinate__lte=target_ycoordinate) output_cells = list() for oldcell in oldCells: oldcell.decrement_y() output_cells.append(oldcell) for source_cell in source_row_cells: source_cell.set_ycoordinate(target_ycoordinate) output_cells.append(source_cell) for output_cell in output_cells: output_cell.save() if source_ycoordinate > target_ycoordinate: oldCells = Cell.objects.filter(matrix=matrix.id).filter( ycoordinate__gte=target_ycoordinate).filter( ycoordinate__lt=source_ycoordinate) output_cells = list() for oldcell in oldCells: oldcell.increment_y() output_cells.append(oldcell) for source_cell in source_row_cells: source_cell.set_ycoordinate(target_ycoordinate) output_cells.append(source_cell) for output_cell in output_cells: output_cell.save() if matrix.get_max_row() == target_ycoordinate: nextRow = matrix.get_row_count() columns = matrix.get_columns() for i, column in enumerate(columns): cell = Cell.create(matrix, "", "", i, nextRow, "", None) cell.save() matrix.save() data = { 'failure': False, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: data = {'failure': True, 'source': str(source), 'target': str(target)} return JsonResponse(data)
def overwrite_cell(request): """ AJAX - Overwrite Cell - MOVE """ source = request.POST['source'] target = request.POST['target'] source_type = request.POST['source_type'] source_cell = get_object_or_404(Cell, pk=source) target_cell = get_object_or_404(Cell, pk=target) matrix = source_cell.matrix owner = get_object_or_404(User, pk=matrix.owner_id) user = get_object_or_404(User, pk=request.user.id) serverWordpress = get_primary_wordpress_server() if credential_exists(user): authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() or authority.is_none(): data = { 'failure': True, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: if matrix.get_max_row() == target_cell.ycoordinate: nextRow = matrix.get_row_count() columns = matrix.get_columns() for i, column in enumerate(columns): cell = Cell.create(matrix, "", "", i, nextRow, "", None) cell.save() matrix.save() if matrix.get_max_column() == target_cell.xcoordinate: nextColumn = matrix.get_column_count() rows = matrix.get_rows() for i, row in enumerate(rows): cell = Cell.create(matrix, "", "", nextColumn, i, "", None) cell.save() matrix.save() if target_cell.has_blogpost(): credential = get_credential_for_user(request.user) if credential.has_apppwd(): response = serverWordpress.delete_wordpress_post( credential, target_cell.blogpost) if target_cell.has_image(): if not exists_collections_for_image(target_cell.image): cell_list = get_cells_for_image(target_cell.image) delete_flag = True for otherCell in cell_list: if otherCell.matrix.id != matrix.id: delete_flag = False if delete_flag == True: image = target_cell.image target_cell.image = None target_cell.save() image.delete() source_xcoordinate = source_cell.xcoordinate source_ycoordinate = source_cell.ycoordinate target_xcoordinate = target_cell.xcoordinate target_ycoordinate = target_cell.ycoordinate source_cell.xcoordinate = target_xcoordinate source_cell.ycoordinate = target_ycoordinate target_cell.xcoordinate = source_xcoordinate target_cell.ycoordinate = source_ycoordinate target_cell.title = "" target_cell.description = "" target_cell.blogpost = "" target_cell.image = None source_cell.save() target_cell.save() data = { 'failure': False, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: data = {'failure': True, 'source': str(source), 'target': str(target)} return JsonResponse(data)
def overwrite_cell_leave(request): """ AJAX - Overwrite Cell """ source = request.POST['source'] target = request.POST['target'] source_type = request.POST['source_type'] source_cell = get_object_or_404(Cell, pk=source) target_cell = get_object_or_404(Cell, pk=target) matrix = source_cell.matrix owner = get_object_or_404(User, pk=matrix.owner_id) user = get_object_or_404(User, pk=request.user.id) serverWordpress = get_primary_wordpress_server() if credential_exists(user): authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() or authority.is_none(): data = { 'failure': True, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: if matrix.get_max_row() == target_cell.ycoordinate: nextRow = matrix.get_row_count() columns = matrix.get_columns() for i, column in enumerate(columns): cell = Cell.create(matrix, "", "", i, nextRow, "", None) cell.save() matrix.save() if matrix.get_max_column() == target_cell.xcoordinate: nextColumn = matrix.get_column_count() rows = matrix.get_rows() for i, row in enumerate(rows): cell = Cell.create(matrix, "", "", nextColumn, i, "", None) cell.save() matrix.save() if target_cell.has_blogpost(): credential = get_credential_for_user(request.user) if credential.has_apppwd(): response = serverWordpress.delete_wordpress_post( credential, target_cell.blogpost) if target_cell.has_image(): if not exists_collections_for_image(target_cell.image): cell_list = get_cells_for_image(target_cell.image) delete_flag = True for otherCell in cell_list: if otherCell.matrix.id != matrix.id: delete_flag = False if delete_flag == True: image = target_cell.image target_cell.image = None target_cell.save() image.delete() target_cell.title = source_cell.title target_cell.description = source_cell.description if source_cell.has_image(): imageOld = Image.objects.get(pk=source_cell.image.id) imageNew = Image.create(imageOld.identifier, imageOld.name, imageOld.server, imageOld.viewer_url, imageOld.birdseye_url, imageOld.roi, imageOld.owner) imageNew.save() target_cell.image = imageNew target_cell.blogpost = source_cell.blogpost if source_cell.has_blogpost(): credential = get_credential_for_user(request.user) post_id = '' if credential.has_apppwd(): returned_blogpost = serverWordpress.post_wordpress_post( credential, source_cell.title, source_cell.description) if returned_blogpost['status'] == WORDPRESS_SUCCESS: post_id = returned_blogpost['id'] source_cell.set_blogpost(post_id) source_cell.save() target_cell.save() data = { 'failure': False, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: data = {'failure': True, 'source': str(source), 'target': str(target)} return JsonResponse(data)
def swap_columns(request): """ AJAX - Swap Columns """ source = request.POST['source'] target = request.POST['target'] in_source_cell = get_object_or_404(Cell, pk=source) in_target_cell = get_object_or_404(Cell, pk=target) matrix = in_source_cell.matrix owner = get_object_or_404(User, pk=matrix.owner_id) user = get_object_or_404(User, pk=request.user.id) if credential_exists(user): authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() or authority.is_none(): data = { 'failure': True, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: source_column_cells = matrix.get_column(in_source_cell.xcoordinate) target_column_cells = matrix.get_column(in_target_cell.xcoordinate) source_xcoordinate = in_source_cell.xcoordinate target_xcoordinate = in_target_cell.xcoordinate output_cells = list() for target_cell in target_column_cells: target_cell.set_xcoordinate(source_xcoordinate) output_cells.append(target_cell) for source_cell in source_column_cells: source_cell.set_xcoordinate(target_xcoordinate) output_cells.append(source_cell) for output_cell in output_cells: output_cell.save() if matrix.get_max_column() == in_target_cell.xcoordinate: nextColumn = matrix.get_column_count() rows = matrix.get_rows() for i, row in enumerate(rows): cell = Cell.create(matrix, "", "", nextColumn, i, "", None) cell.save() matrix.save() data = { 'failure': False, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: data = {'failure': True, 'source': str(source), 'target': str(target)} return JsonResponse(data)
def import_image(request): """ AJAX - Import Image """ source = request.POST['source'] target = request.POST['target'] source_type = request.POST['source_type'] source_image = get_object_or_404(Image, pk=source) target_cell = get_object_or_404(Cell, pk=target) matrix = target_cell.matrix owner = get_object_or_404(User, pk=matrix.owner_id) user = get_object_or_404(User, pk=request.user.id) serverWordpress = get_primary_wordpress_server() if credential_exists(user): authority = get_authority_for_bench_and_user_and_requester( matrix, request.user) if authority.is_viewer() or authority.is_none(): data = { 'failure': True, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: if matrix.get_max_row() == target_cell.ycoordinate: nextRow = matrix.get_row_count() columns = matrix.get_columns() for i, column in enumerate(columns): cell = Cell.create(matrix, "", "", i, nextRow, "", None) cell.save() matrix.save() if matrix.get_max_column() == target_cell.xcoordinate: nextColumn = matrix.get_column_count() rows = matrix.get_rows() for i, row in enumerate(rows): cell = Cell.create(matrix, "", "", nextColumn, i, "", None) cell.save() matrix.save() post_id = '' target_cell.title = source_image.name target_cell.description = source_image.name target_cell.image = source_image if target_cell.has_no_blogpost(): credential = get_credential_for_user(request.user) if credential.has_apppwd(): returned_blogpost = serverWordpress.post_wordpress_post( credential, target_cell.title, target_cell.description) if returned_blogpost['status'] == WORDPRESS_SUCCESS: post_id = returned_blogpost['id'] target_cell.set_blogpost(post_id) target_cell.save() data = { 'failure': False, 'source': str(source), 'target': str(target) } return JsonResponse(data) else: data = {'failure': True, 'source': str(source), 'target': str(target)} return JsonResponse(data)