Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

193 Hide myself from the top hunters and activity lists #199

Merged
merged 35 commits into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
264a83c
193 gitignore files added + readme updated
igrishaev Dec 26, 2017
7dbd327
193 makefile added
igrishaev Dec 26, 2017
460eab8
193 sql migrations added
igrishaev Dec 26, 2017
287922d
193 cider plugin removed
igrishaev Dec 26, 2017
58de6ae
193 ignoring dev config
igrishaev Dec 26, 2017
0eba6fe
193 start-end pairs added
igrishaev Dec 26, 2017
e44639a
193 server handler added
igrishaev Dec 27, 2017
b77a231
193 ui widget added
igrishaev Dec 27, 2017
bea4321
193 migrations updated
igrishaev Dec 27, 2017
fea8d4f
193 style added
igrishaev Dec 27, 2017
559f4f4
193 checkbox updated
igrishaev Dec 27, 2017
78d8b28
193 transaction removed
igrishaev Dec 27, 2017
085e8ef
193 rolled back
igrishaev Jan 31, 2018
07bb457
193 user exists query added
igrishaev Feb 6, 2018
50e3045
193 address + hidden routes mixed
igrishaev Feb 6, 2018
8937816
193 query field updated
igrishaev Feb 6, 2018
2b7dff9
193 UI updated
igrishaev Feb 6, 2018
6107fec
193 gitignore fix
igrishaev Feb 6, 2018
fb95fe6
193 print removed
igrishaev Feb 6, 2018
c860db5
193 config.example deleted
igrishaev Feb 6, 2018
b162bba
193 config file restored
igrishaev Feb 6, 2018
a0073b2
Merge branch 'develop' of https://github.com/status-im/open-bounty in…
igrishaev Feb 6, 2018
a61885d
193 get rid of passing user-id
igrishaev Feb 7, 2018
596e6c9
Merge branch 'develop' of https://github.com/status-im/open-bounty in…
igrishaev Feb 8, 2018
c66691c
193 review fixes
igrishaev Feb 8, 2018
56d1425
193 sql fix
igrishaev Feb 8, 2018
21c869a
193 blank line removed
igrishaev Feb 8, 2018
c2d6094
Merge branch 'develop' of https://github.com/status-im/open-bounty in…
igrishaev Feb 9, 2018
4717a1a
193 review fixes
igrishaev Feb 12, 2018
34c1645
Merge branch 'develop' of https://github.com/status-im/open-bounty in…
igrishaev Feb 12, 2018
092713a
193 merge artifacts
igrishaev Feb 12, 2018
9732b7c
193 h3 added
igrishaev Feb 12, 2018
38ecb91
Merge branch 'develop' of https://github.com/status-im/open-bounty in…
igrishaev Feb 16, 2018
a8cdaa4
Merge branch 'develop' into 193-hide-myself
igrishaev Feb 16, 2018
187b748
Merge branch 'develop' into 193-hide-myself
Feb 16, 2018
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
35 changes: 35 additions & 0 deletions resources/migrations/20171226182259-hide-user.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
BEGIN;

-- restore the previous version of the view
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here and below, I had to redefine existing DB view to add non-hidden user clause.

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;
35 changes: 35 additions & 0 deletions resources/migrations/20171226182259-hide-user.up.sql
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions resources/sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion src/clj/commiteth/db/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
:migration-table-name "schema_migrations"
:db db}]
(migratus/migrate migratus-config)
(conman/bind-connection db "sql/queries.sql")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplication line

(conman/connect! {:jdbc-url db})
db))

Expand Down Expand Up @@ -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))
38 changes: 24 additions & 14 deletions src/clj/commiteth/routes/services.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why these blank lines?

(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
Expand Down
39 changes: 22 additions & 17 deletions src/cljs/commiteth/handlers.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
(fn [db [_ path value]]
(assoc-in db path value)))


(reg-event-db
:set-active-page
(fn [db [_ page]]
Expand Down Expand Up @@ -318,32 +317,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
:error
(:response %)]))
:finally #(dispatch [:clear-updating-address])
:params {:user-id user-id :address address}}}))
"Settings saved"]))
:on-error #(dispatch [:set-flash-message
:error
(: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
Expand Down
36 changes: 26 additions & 10 deletions src/cljs/commiteth/update_address.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@
[reagent.crypt :as crypt]
[cljs-web3.eth :as web3-eth]))


(defn update-address-page []
(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"]
Expand All @@ -33,12 +32,29 @@
:auto-correct "off"
:spell-check "false"
:max-length 42}]])]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some blank lines here and below.

[: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"]]]))))
"UPDATE"]

]]))))
13 changes: 10 additions & 3 deletions src/less/style.less
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -1283,5 +1292,3 @@ body {
color: #8d99a4;
padding-top: 20px;
}