Merge pull request #199 from igrishaev/193-hide-myself

193 Hide myself from the top hunters and activity lists
This commit is contained in:
Vitaliy Vlasov 2018-02-16 16:00:59 +02:00 committed by GitHub
commit 166c1252a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 164 additions and 43 deletions

View File

@ -0,0 +1,35 @@
BEGIN;
-- restore the previous version of the view
CREATE OR REPLACE VIEW "public"."claims_view" AS
SELECT
i.title AS issue_title,
i.issue_number,
r.repo AS repo_name,
r.owner AS repo_owner,
COALESCE(u.name, u.login) AS user_name,
u.avatar_url AS user_avatar_url,
i.payout_receipt,
p.updated,
i.updated AS issue_updated,
i.balance_eth,
i.tokens,
i.value_usd,
p.state AS pr_state,
i.is_open AS issue_open,
(case when u.address IS NULL THEN false ELSE true END) AS user_has_address
FROM issues i,
users u,
repositories r,
pull_requests p
WHERE r.repo_id = i.repo_id
AND p.issue_id = i.issue_id
AND p.user_id = u.id
AND i.contract_address IS NOT NULL
AND i.comment_id IS NOT NULL
ORDER BY p.updated;
ALTER TABLE users
DROP COLUMN is_hidden_in_hunters;
COMMIT;

View File

@ -0,0 +1,35 @@
BEGIN;
ALTER TABLE users
ADD COLUMN is_hidden_in_hunters BOOLEAN NOT NULL DEFAULT FALSE;
CREATE OR REPLACE VIEW "public"."claims_view" AS
SELECT
i.title AS issue_title,
i.issue_number,
r.repo AS repo_name,
r.owner AS repo_owner,
COALESCE(u.name, u.login) AS user_name,
u.avatar_url AS user_avatar_url,
i.payout_receipt,
p.updated,
i.updated AS issue_updated,
i.balance_eth,
i.tokens,
i.value_usd,
p.state AS pr_state,
i.is_open AS issue_open,
(case when u.address IS NULL THEN false ELSE true END) AS user_has_address
FROM issues i,
users u,
repositories r,
pull_requests p
WHERE r.repo_id = i.repo_id
AND p.issue_id = i.issue_id
AND p.user_id = u.id
AND i.contract_address IS NOT NULL
AND i.comment_id IS NOT NULL
AND NOT u.is_hidden_in_hunters -- added
ORDER BY p.updated;
COMMIT;

View File

@ -17,6 +17,12 @@ WHERE NOT exists(SELECT 1
WHERE id = :id)
RETURNING id, login, name, email, avatar_url, address, created;
-- :name user-exists? :? :1
-- :doc Checks where a user exists in the database.
select 1
from users u
where u.id = :id;
-- :name update-user! :! :n
-- :doc updates an existing user record
UPDATE users
@ -571,6 +577,7 @@ WHERE
pr.commit_sha = i.commit_sha
AND u.id = pr.user_id
AND i.payout_receipt IS NOT NULL
AND NOT u.is_hidden_in_hunters
GROUP BY u.id
ORDER BY total_usd DESC
LIMIT 5;

View File

@ -27,7 +27,6 @@
:migration-table-name "schema_migrations"
:db db}]
(migratus/migrate migratus-config)
(conman/bind-connection db "sql/queries.sql")
(conman/connect! {:jdbc-url db})
db))
@ -85,3 +84,11 @@
(sql-value [value] (to-pg-json value))
IPersistentVector
(sql-value [value] (to-pg-json value)))
(defmacro with-tx [& body]
"Performs a set of queries in transaction."
`(conman/with-transaction [*db*]
~@body))
(defn update! [& args]
(apply jdbc/update! *db* args))

View File

@ -5,6 +5,7 @@
[compojure.api.meta :refer [restructure-param]]
[buddy.auth.accessrules :refer [restrict]]
[buddy.auth :refer [authenticated?]]
[commiteth.db.core :as db]
[commiteth.db.users :as users]
[commiteth.db.usage-metrics :as usage-metrics]
[commiteth.db.repositories :as repositories]
@ -214,26 +215,35 @@
(do
(log/debug "/usage-metrics" user)
(ok (usage-metrics/usage-metrics-by-day))))
(context "/user" []
(GET "/" {:keys [params]}
:auth-rules authenticated?
:current-user user
(ok (handle-get-user user (:token params))))
(POST "/address" []
(POST "/" []
:auth-rules authenticated?
:body-params [user-id :- Long, address :- String]
:summary "Update user address"
(if-not (eth/valid-address? address)
(do
(log/debug "POST /address: invalid input" address)
{:status 400
:body (str "Invalid Ethereum address '" address "'")})
(let [result (users/update-user-address
user-id
address)]
(if (= 1 result)
(ok)
(internal-server-error)))))
:current-user user
:body [body {:address s/Str
:is_hidden_in_hunters s/Bool}]
:summary "Updates user's fields."
(let [user-id (:id user)
{:keys [address]} body]
(when-not (eth/valid-address? address)
(log/debugf "POST /user: Wrong address %s" address)
(bad-request! (format "Invalid Ethereum address: %s" address)))
(db/with-tx
(when-not (db/user-exists? {:id user-id})
(not-found! "No such a user."))
(db/update! :users body ["id = ?" user-id]))
(ok)))
(GET "/repositories" {:keys [params]}
:auth-rules authenticated?
:current-user user

View File

@ -62,7 +62,6 @@
(fn [db [_ path value]]
(assoc-in db path value)))
(reg-event-db
:set-active-page
(fn [db [_ page]]
@ -319,32 +318,38 @@
{:db db
:dispatch [:set-active-page :update-address]}))
(reg-event-db
:update-user
(fn [db [_ fields]]
(update db :user merge fields)))
(reg-event-fx
:save-user-address
(fn [{:keys [db]} [_ user-id address]]
(prn "save-user-address" user-id address)
{:db (assoc db :updating-address true)
:save-user-fields
(fn [{:keys [db]} [_ fields]]
{:dispatch [:set-updating-user]
:http {:method POST
:url "/api/user/address"
:url "/api/user"
:on-success #(do
(dispatch [:assoc-in [:user [:address] address]])
(dispatch [:update-user fields])
(dispatch [:set-flash-message
:success
"Address saved"]))
:on-error #(do
(println %)
(dispatch [:set-flash-message
"Settings saved"]))
:on-error #(dispatch [:set-flash-message
:error
(:response %)]))
:finally #(dispatch [:clear-updating-address])
:params {:user-id user-id :address address}}}))
(:response %)])
:finally #(dispatch [:clear-updating-user])
:params fields}}))
(reg-event-db
:clear-updating-address
:set-updating-user
(fn [db _]
(dissoc db :updating-address)))
(assoc db :updating-user true)))
(reg-event-db
:clear-updating-user
(fn [db _]
(dissoc db :updating-user)))
(reg-event-fx
:save-payout-hash

View File

@ -7,14 +7,14 @@
(defn update-address-page-contents []
(let [db (rf/subscribe [:db])
user (rf/subscribe [:user])
updating-address (rf/subscribe [:get-in [:updating-address]])
address (r/atom @(rf/subscribe [:get-in [:user :address]]))]
updating-user (rf/subscribe [:get-in [:updating-user]])
address (r/atom @(rf/subscribe [:get-in [:user :address]]))
hidden (r/atom @(rf/subscribe [:get-in [:user :is_hidden_in_hunters]]))]
(fn []
(let [web3 (:web3 @db)
web3-accounts (when web3
(web3-eth/accounts web3))]
(println "web3-accounts" web3-accounts)
[:div.ui.container.grid
[:div.ui.form.sixteen.wide.column
[:h3 "Update address"]
@ -32,13 +32,28 @@
:auto-correct "off"
:spell-check "false"
:max-length 42}]])]
[:h3 "Settings"]
[:div
[:input
{:type :checkbox
:disabled @updating-user
:id :input-hidden
:checked @hidden
:on-change
(fn [e]
(let [value (-> e .-target .-checked)]
(reset! hidden value)))}]
[:label {:for :input-hidden} "Disguise myself from the top hunters and activity lists."]]
[:button
(merge {:on-click
#(rf/dispatch [:save-user-address
(:id @user)
@address])
#(rf/dispatch [:save-user-fields {:address @address
:is_hidden_in_hunters @hidden}])
:class (str "ui button small update-address-button"
(when @updating-address
(when @updating-user
" busy loading"))})
"UPDATE"]]]))))

View File

@ -41,17 +41,26 @@
.update-address-button {
background-color: #57a7ed!important;
margin-top: 10px !important;
&:hover {
background-color: #57a7ed!important;
}
}
label[for="input-hidden"] {
padding-left: 8px;
}
#input-hidden {
vertical-align: bottom;
position: relative;
top: -4px;
}
.login-button {
background-color: rgba(255,255,255,0.2)!important;
}
.commiteth-header {
background-color: #57a7ed!important;
border-radius: 0em;
@ -1286,5 +1295,3 @@ body {
color: #8d99a4;
padding-top: 20px;
}