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

Hm 02 products privacy #5389

Closed
Closed
Show file tree
Hide file tree
Changes from all 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
Binary file added backend/app/assets/images/bookarley-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,12 @@ body.admin-nav-hidden .admin-nav:not(.fits) {
overflow: hidden;

img {
max-height: 100%;
max-width: 100%;
max-height: 70%;
max-width: 70%;
}
}

.product_varient span {
background: none !important;
color: white !important;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# app/controllers/spree/admin/approved_posts_controller.rb
module Spree
module Admin
class ApprovedPostsController < Spree::Admin::BaseController
def index
@approved_posts = Spree::Product.all.where(is_approved: true)
end

def reject
product = Spree::Product.find(params[:id])
if product.update(is_rejected: true, is_approved: false, is_pending: false, reason: params[:reason])
render json: { success: true }
else
render json: { success: false, errors: product.errors.full_messages }, status: :unprocessable_entity
end
end

def withdraw
product = Spree::Product.find(params[:id])
if product.destroy
render json: { success: true }
else
render json: { success: false }, status: :unprocessable_entity
end
end
end
end
end
37 changes: 37 additions & 0 deletions backend/app/controllers/spree/admin/pending_posts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# app/controllers/spree/admin/pending_posts_controller.rb
module Spree
module Admin
class PendingPostsController < Spree::Admin::BaseController
def index
@pending_posts = Spree::Product.all.where(is_pending: true)
end

def approve
product = Spree::Product.find(params[:id])
if product.update(is_approved: true, is_pending: false, reason: nil)
render json: { success: true }
else
render json: { success: false, errors: product.errors.full_messages }, status: :unprocessable_entity
end
end

def reject
product = Spree::Product.find(params[:id])
if product.update(is_rejected: true, is_approved: false, is_pending: false, reason: params[:reason])
render json: { success: true }
else
render json: { success: false, errors: product.errors.full_messages }, status: :unprocessable_entity
end
end

def withdraw
product = Spree::Product.find(params[:id])
if product.destroy
render json: { success: true }
else
render json: { success: false }, status: :unprocessable_entity
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# app/controllers/spree/admin/rejected_posts_controller.rb
module Spree
module Admin
class RejectedPostsController < Spree::Admin::BaseController
def index
@rejected_posts = Spree::Product.all.where(is_rejected: true)
end

def approve
product = Spree::Product.find(params[:id])
if product.update(is_rejected: false, is_approved: true, is_pending: false, reason: nil)
render json: { success: true }
else
render json: { success: false, errors: product.errors.full_messages }, status: :unprocessable_entity
end
end

def pending
product = Spree::Product.find(params[:id])
if product.update(is_rejected: false, is_approved: false, is_pending: true, reason: params[:reason])
render json: { success: true }
else
render json: { success: false, errors: product.errors.full_messages }, status: :unprocessable_entity
end
end

def withdraw
product = Spree::Product.find(params[:id])
if product.destroy
render json: { success: true }
else
render json: { success: false }, status: :unprocessable_entity
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ def create
@object.attributes = permitted_resource_params
if @object.save
invoke_callbacks(:create, :after)
flash[:success] = flash_message_for(@object, :successfully_created)
if params[:product].present? && params[:product].key?("is_pending") && params[:product]["is_pending"] == "true"
flash[:success] = "Your Post has been sent for approval"
else
flash[:success] = flash_message_for(@object, :successfully_created)
end
respond_with(@object) do |format|
format.html { redirect_to location_after_save }
format.js { render layout: false }
Expand Down
51 changes: 51 additions & 0 deletions backend/app/controllers/spree/admin/roles_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# frozen_string_literal: true

module Spree
module Admin
class RolesController < ResourceController


before_action :load_role, only: [:edit, :update, :destroy]

def index
@roles = Spree::Role.all
end

def new
@role = Spree::Role.new
end

def create
@role = Spree::Role.new(role_params)
if @role.save
redirect_to admin_roles_path, notice: 'Role created successfully'
else
render :new
end
end

def edit
# The 'load_role' before_action loads the role to be edited
end

def update
if @role.update(role_params)
redirect_to admin_roles_path, notice: 'Role updated successfully'
else
render :edit
end
end

private

def role_params
params.require(:role).permit(:name)
end

def load_role
@role = Spree::Role.find(params[:id])
end

end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

module Spree
module Admin
module Taxonomies
class AttachmentController < Spree::Admin::BaseController
def destroy
taxonomy = Spree::Taxonomy.find(params[:taxonomy_id])
if taxonomy.destroy_attachment(params[:attachment_definition])
flash[:success] = t('spree.successfully_removed', resource: params[:attachment_definition].titleize)
else
flash[:error] = t('spree.taxon_attachment_removal_error')
end
redirect_to edit_admin_taxonomy_path(taxonomy)
end
end
end
end
end






138 changes: 138 additions & 0 deletions backend/app/views/spree/admin/approved_posts/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<% admin_breadcrumb("Approved Posts") %>

<table class="index" id="listing_products">
<thead>
<tr data-hook="admin_products_index_headers">
<th class="text-center">ID</th>
<th class="text-center">Image</th>
<th class="text-center">Title</th>
<th class="text-center" class="align-right">Master Price</th>
<% if !spree_current_user.has_spree_role?("seller") %>
<th class="text-center" class="align-right">Seller</th>
<% end %>
<th class="text-center">Action</th>
</tr>
</thead>
<tbody>
<% if spree_current_user.has_spree_role?("seller") %>
<% @approved_posts_list = @approved_posts.where(spree_user_id: spree_current_user.id) %>
<% else %>
<% @approved_posts_list = @approved_posts %>
<% end %>

<% @approved_posts_list.each do |product| %>
<tr data-product-id=<%= product.id %>>
<td class="text-center"><%= product.id %></td>
<td class="align-center">
<%= render 'spree/admin/shared/image', image: product.gallery.images.first, size: :mini %>
</td>
<td class="text-center"><%= link_to product.try(:name), edit_admin_product_path(product) %></td>
<td class="text-center align-right"><%= product.display_price&.to_html %></td>
<% if !spree_current_user.has_spree_role?("seller") %>
<td class="text-center" class="align-right">
<% product_seller = Spree::User.find_by(id: product.spree_user_id) %>
<% if product_seller&.full_name.present? %>
<%= product_seller&.full_name %>
<% else %>
<%= "Admin" %>
<% end %>
</td>
<% end %>
<td>
<div class="d-flex justify-content-center">
<% if !spree_current_user.has_spree_role?("seller") %>
<div class="mr-2">
<button class="reject-button" data-product-id="<%= product.id %>">Reject</button>
</div>
<% end %>
<div>
<button class="withdraw-button" data-product-id="<%= product.id %>">Withdraw</button>
</div>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>

<!-- Modal -->
<div class="modal fade" id="reasonModal" tabindex="-1" role="dialog" aria-labelledby="reasonModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="reasonModalLabel">Enter Reason</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<form id="reasonForm">
<div class="form-group">
<label for="reasonInput">Reason:</label>
<input type="text" class="form-control" id="reasonInput" required>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</div>
</div>


<script>
$(document).on("click", ".reject-button", function() {
var productId = $(this).data("product-id");

// Show the modal
$("#reasonModal").modal("show");

$("#reasonForm").submit(function(e) {
e.preventDefault();

var reason = $("#reasonInput").val();

$.ajax({
type: "PATCH",
contentType: "application/json; charset=utf-8",
url: "/admin/approved_posts/" + productId + "/reject",
data: JSON.stringify({ reason: reason }),
dataType: "json",
success: function(result) {
if (result.success) {
// Remove the approved product row from the table
$("tr[data-product-id='" + productId + "']").remove();
// Close the modal
$("#reasonModal").modal("hide");
} else {
window.alert("Approval failed!");
}
},
error: function() {
window.alert("Something went wrong!");
}
});
});
});

$(document).on("click", ".withdraw-button", function() {
var productId = $(this).data("product-id");

$.ajax({
type: "PATCH",
contentType: "application/json; charset=utf-8",
url: "/admin/approved_posts/" + productId + "/withdraw",
dataType: "json",
success: function(result) {
if (result.success) {
// Remove the approved product row from the table
$("tr[data-product-id='" + productId + "']").remove();
} else {
window.alert("Approval failed!");
}
},
error: function() {
window.alert("Something went wrong!");
}
});
});
</script>
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/option_types/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<% admin_breadcrumb(link_to plural_resource_name(Spree::Product), spree.admin_products_path) %>
<% admin_breadcrumb(link_to plural_resource_name(Spree::OptionType), spree.admin_option_types_path) %>
<% admin_breadcrumb(link_to 'Product Variants', spree.admin_option_types_path) %>
<% admin_breadcrumb(@option_type.name) %>

<% content_for :page_actions do %>
Expand Down
Loading