Add private metapurse for users
This commit is contained in:
parent
4313eed64e
commit
e960f7edad
@ -3,7 +3,7 @@ class MetapursesController < ApplicationController
|
||||
|
||||
# GET /metapurses or /metapurses.json
|
||||
def index
|
||||
authorize @metapurses = Metapurse.all
|
||||
authorize @metapurses = policy_scope(Metapurse)
|
||||
end
|
||||
|
||||
# GET /metapurses/1 or /metapurses/1.json
|
||||
@ -84,6 +84,6 @@ kz5t3-pyaaa-aaaap-ab2qq-cai 5000000 iVishnu"
|
||||
|
||||
# Only allow a list of trusted parameters through.
|
||||
def metapurse_params
|
||||
params.require(:metapurse).permit(:name, :data, :user_id)
|
||||
params.require(:metapurse).permit(:name, :data, :user_id, :is_private)
|
||||
end
|
||||
end
|
||||
|
||||
@ -16,7 +16,8 @@ class MetapursePolicy
|
||||
if user.admin?
|
||||
scope.all
|
||||
else
|
||||
scope.all
|
||||
scope.where(user_id: nil).or(scope.where(is_private: false)).or(scope.where(user_id: user.id))
|
||||
# scope.first
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -4,6 +4,14 @@
|
||||
.form-inputs
|
||||
= f.hidden_field :user_id
|
||||
= f.input :name
|
||||
- if @metapurse.user_id
|
||||
= f.input :is_private
|
||||
- else
|
||||
- @metapurse.is_private = false
|
||||
= f.input :is_private, disabled: true
|
||||
= link_to "Sign in", new_user_session_path
|
||||
to enable Private MetaPurse only you can see
|
||||
|
||||
= f.input :data, placeholder: "canister-id amount\niozql-7iaaa-aaaah-advvq-cai 88.0"
|
||||
|
||||
.form-actions
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
class AddIsPrivateToMetapurses < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :metapurses, :is_private, :boolean, default: true, null: false
|
||||
end
|
||||
end
|
||||
@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_03_25_135707) do
|
||||
ActiveRecord::Schema[7.1].define(version: 2024_03_25_142502) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
@ -113,6 +113,7 @@ ActiveRecord::Schema[7.1].define(version: 2024_03_25_135707) do
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "user_id"
|
||||
t.boolean "is_private", default: true, null: false
|
||||
t.index ["user_id"], name: "index_metapurses_on_user_id"
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user