Add private metapurse for users
This commit is contained in:
parent
4ae78edc49
commit
afe858ade9
@ -3,7 +3,7 @@ class MetapursesController < ApplicationController
|
|||||||
|
|
||||||
# GET /metapurses or /metapurses.json
|
# GET /metapurses or /metapurses.json
|
||||||
def index
|
def index
|
||||||
authorize @metapurses = Metapurse.all
|
authorize @metapurses = policy_scope(Metapurse)
|
||||||
end
|
end
|
||||||
|
|
||||||
# GET /metapurses/1 or /metapurses/1.json
|
# 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.
|
# Only allow a list of trusted parameters through.
|
||||||
def metapurse_params
|
def metapurse_params
|
||||||
params.require(:metapurse).permit(:name, :data, :user_id)
|
params.require(:metapurse).permit(:name, :data, :user_id, :is_private)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -16,7 +16,8 @@ class MetapursePolicy
|
|||||||
if user.admin?
|
if user.admin?
|
||||||
scope.all
|
scope.all
|
||||||
else
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -4,6 +4,14 @@
|
|||||||
.form-inputs
|
.form-inputs
|
||||||
= f.hidden_field :user_id
|
= f.hidden_field :user_id
|
||||||
= f.input :name
|
= 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"
|
= f.input :data, placeholder: "canister-id amount\niozql-7iaaa-aaaah-advvq-cai 88.0"
|
||||||
|
|
||||||
.form-actions
|
.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.
|
# 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
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
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 "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.integer "user_id"
|
t.integer "user_id"
|
||||||
|
t.boolean "is_private", default: true, null: false
|
||||||
t.index ["user_id"], name: "index_metapurses_on_user_id"
|
t.index ["user_id"], name: "index_metapurses_on_user_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user