Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into refine-organization…
Browse files Browse the repository at this point in the history
…-tab
  • Loading branch information
kevkevinpal committed Nov 10, 2023
2 parents 23f0e6f + 4420f1a commit d97cc59
Show file tree
Hide file tree
Showing 93 changed files with 3,745 additions and 1,391 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ Please delete options that are not relevant.
- [ ] I have performed a self-review of my code
- [ ] I have tested on Chrome and Firefox
- [ ] I have tested on a mobile device
- [ ] It has been deployed to people-test.sphinx.chat and tested by others
- [ ] I have provided a screenshot or recording of changes in my PR if there were updates to the frontend
17 changes: 17 additions & 0 deletions .github/workflows/prjob_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Build
on:
pull_request:
branches:
- master
jobs:
build:
name: build
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn --cwd ./frontend/app install
- name: Build
run: CI=false yarn --cwd ./frontend/app run build

17 changes: 17 additions & 0 deletions .github/workflows/prjob_eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Eslint
on:
pull_request:
branches:
- master
jobs:
eslint:
name: eslint
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn --cwd ./frontend/app install
- name: Eslint
run: yarn --cwd ./frontend/app run lint

18 changes: 18 additions & 0 deletions .github/workflows/prjob_prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Prettier
on:
pull_request:
branches:
- master
jobs:

prettier:
name: prettier
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn --cwd ./frontend/app install
- name: Prettier
run: CI=false yarn --cwd ./frontend/app run prettier:check

34 changes: 34 additions & 0 deletions .github/workflows/prjob_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Tests
on:
pull_request:
branches:
- master
jobs:
test:
name: Craco
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn --cwd ./frontend/app install
- name: Tests
run: NODE_OPTIONS="--max_old_space_size=8192" yarn --cwd ./frontend/app run test
- name: Set up Golang
uses: actions/setup-go@v2
with:
go-version: 1.19
- name: Go Test
run: go test -v ./...

test-jest:
name: Jest
runs-on:
- ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn --cwd ./frontend/app install
- name: Tests
run: NODE_OPTIONS="--max_old_space_size=8192" yarn --cwd ./frontend/app run test-jest

54 changes: 0 additions & 54 deletions .github/workflows/pull_request.yml

This file was deleted.

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ If you would like to enable Relay for invoice creation and keysend payment add t
RELAY_AUTH_KEY=
```

### Enable Meme Image Upload

If you would like to enable Meme image upload for organization's add the meme env key and value to the .env file,
Meme image upload works with Relay enabled, so a running Relay is required for Meme to work.

```
MEME_URL=
```

### For Contributions

Read the contribution doc [here](./Contribution.md)
Expand Down
2 changes: 1 addition & 1 deletion auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func EncodeJwt(pubkey string) (string, error) {
func ParseTokenString(t string) (uint32, []byte, []byte, error) {
token := t
forceUtf8 := false
// this signifies its forced utf8 sig (for CLN SignMessage)
// this signifies it's forced utf8 sig (for CLN SignMessage)
if strings.HasPrefix(t, ".") {
token = t[1:]
forceUtf8 = true
Expand Down
82 changes: 82 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package config

import (
"encoding/json"
"fmt"
"io"
"log"
"math/rand"
"net/http"
"os"
"time"
)

var Host string
var JwtKey string
var RelayUrl string
var MemeUrl string
var RelayAuthKey string
var RelayNodeKey string

// these are constants for the store
var InvoiceList = "INVOICELIST"
Expand All @@ -19,15 +26,26 @@ func InitConfig() {
Host = os.Getenv("LN_SERVER_BASE_URL")
JwtKey = os.Getenv("LN_JWT_KEY")
RelayUrl = os.Getenv("RELAY_URL")
MemeUrl = os.Getenv("MEME_URL")
RelayAuthKey = os.Getenv("RELAY_AUTH_KEY")

// only make this call if there is a Relay auth key
if RelayAuthKey != "" {
RelayNodeKey = GetNodePubKey()
}

if Host == "" {
Host = "https://people.sphinx.chat"
}

if MemeUrl == "" {
MemeUrl = "https://memes.sphinx.chat"
}

if JwtKey == "" {
JwtKey = GenerateRandomString()
}

}

func GenerateRandomString() string {
Expand All @@ -45,3 +63,67 @@ func GenerateRandomString() string {

return string(b)
}

type PropertyMap map[string]interface{}

type Feature map[string]PropertyMap

type NodeGetInfoResponse struct {
Uris []string `json:"uris"`
Chains []PropertyMap `json:"chains"`
Features Feature `json:"features"`
IdentityPubkey string `json:"identity_pubkey"`
Alias string `json:"alias"`
NumPendingChannels uint `json:"num_pending_channels"`
NumActiveChannels uint `json:"num_active_channels"`
NumInactiveChannels uint `json:"num_inactive_channels"`
NumPeers uint `json:"num_peers"`
BlockHeight uint `json:"block_height"`
BlockHash string `json:"block_hash"`
SyncedToChain bool `json:"synced_to_chain"`
Testnet bool `json:"testnet"`
BestHeaderTimestamp string `json:"best_header_timestamp"`
Version string `json:"version"`
Color string `json:"color"`
SyncedToGraph bool `json:"synced_to_graph"`
CommitHash string `json:"commit_hash"`
RequireHtlcInterceptor bool `json:"require_htlc_interceptor"`
}

type NodeGetInfo struct {
Success bool `json:"success"`
Response NodeGetInfoResponse `json:"response"`
}

func GetNodePubKey() string {
var pubkey string
url := fmt.Sprintf("%s/getinfo", RelayUrl)

client := &http.Client{}
req, err := http.NewRequest(http.MethodGet, url, nil)

req.Header.Set("x-user-token", RelayAuthKey)
req.Header.Set("Content-Type", "application/json")
res, _ := client.Do(req)

if err != nil {
log.Printf("Request Failed: %s", err)
}

defer res.Body.Close()

body, err := io.ReadAll(res.Body)

nodeInfo := NodeGetInfo{}

// Unmarshal result
err = json.Unmarshal(body, &nodeInfo)

if err != nil {
log.Printf("Reading Relay Node Info body failed: %s", err)
}

pubkey = nodeInfo.Response.IdentityPubkey

return pubkey
}
4 changes: 4 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ func TestInitConfig(t *testing.T) {
t.Error("Could not load default host")
}

if MemeUrl != "https://memes.sphinx.chat" {
t.Error("Could not load default meme url")
}

if JwtKey == "" {
t.Error("Could not load random jwtKey")
}
Expand Down
7 changes: 4 additions & 3 deletions db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func InitDB() {
}

const (
EditOrg = "EDIT ORGANIZATION"
AddBounty = "ADD BOUNTY"
UpdateBounty = "UPDATE BOUNTY"
DeleteBounty = "DELETE BOUNTY"
Expand Down Expand Up @@ -196,12 +197,12 @@ func RolesCheck(userRoles []UserRoles, check string) bool {
rolesMap := GetRolesMap()
userRolesMap := GetUserRolesMap(userRoles)

// check if roles exists in config
// check if roles exist in config
_, ok := rolesMap[check]
_, ok1 := userRolesMap[check]

// if any of the roles does not exists return false
// if any of the roles does not exists user roles return false
// if any of the roles does not exist, return false
// if any of the roles does not exist, user roles return false
if !ok {
return false
} else if !ok1 {
Expand Down
20 changes: 15 additions & 5 deletions db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (db database) CreateChannel(c Channel) (Channel, error) {

}

// check that update owner_pub_key does in fact throw error
// check that update owner_pub_key does in fact throws an error
func (db database) CreateOrEditBot(b Bot) (Bot, error) {
if b.OwnerPubKey == "" {
return Bot{}, errors.New("no pub key")
Expand Down Expand Up @@ -103,7 +103,7 @@ func (db database) CreateOrEditBot(b Bot) (Bot, error) {
return b, nil
}

// check that update owner_pub_key does in fact throw error
// check that update owner_pub_key does in fact throws an error
func (db database) CreateOrEditPerson(m Person) (Person, error) {
if m.OwnerPubKey == "" {
return Person{}, errors.New("no pub key")
Expand Down Expand Up @@ -478,7 +478,7 @@ func (db database) GetOrganizationBounties(r *http.Request, org_uuid string) []B
func (db database) GetAssignedBounties(pubkey string) ([]BountyData, error) {
ms := []BountyData{}

err := db.db.Raw(`SELECT body.*, body.id as bounty_id, body.description as bounty_description, body.created as bounty_created, body.updated as bounty_updated, body.org_uuid, person.*, person.owner_alias as assignee_alias, person.id as assignee_id, person.description as assignee_description, person.created as assignee_created, person.updated as assignee_updated, person.owner_route_hint as assignee_route_hint, owner.id as bounty_owner_id, owner.uuid as owner_uuid, owner.owner_pub_key as owner_key, owner.owner_alias as owner_alias, owner.description as owner_description, owner.price_to_meet as owner_price_to_meet, owner.unique_name as owner_unique_name, owner.tags as owner_tags, owner.img as owner_img, owner.created as owner_created, owner.updated as owner_updated, owner.last_login as owner_last_login, owner.owner_route_hint as owner_route_hint, owner.owner_contact_key as owner_contact_key, org.name as organization_name, org.uuid as organization_uuid, org.img as organization_img FROM public.bounty AS body LEFT OUTER JOIN public.people AS person ON body.assignee = person.owner_pub_key LEFT OUTER JOIN public.people as owner ON body.owner_id = owner.owner_pub_key LEFT OUTER JOIN public.organizations as org ON body.org_uuid = org.uuid WHERE body.assignee = '` + pubkey + `' ORDER BY body.id DESC`).Find(&ms).Error
err := db.db.Raw(`SELECT body.*, body.id as bounty_id, body.description as bounty_description, body.created as bounty_created, body.updated as bounty_updated, body.org_uuid, person.*, person.owner_alias as assignee_alias, person.id as assignee_id, person.description as assignee_description, person.created as assignee_created, person.updated as assignee_updated, person.owner_route_hint as assignee_route_hint, owner.id as bounty_owner_id, owner.uuid as owner_uuid, owner.owner_pub_key as owner_key, owner.owner_alias as owner_alias, owner.description as owner_description, owner.price_to_meet as owner_price_to_meet, owner.unique_name as owner_unique_name, owner.tags as owner_tags, owner.img as owner_img, owner.created as owner_created, owner.updated as owner_updated, owner.last_login as owner_last_login, owner.owner_route_hint as owner_route_hint, owner.owner_contact_key as owner_contact_key, org.name as organization_name, org.uuid as organization_uuid, org.img as organization_img FROM public.bounty AS body LEFT OUTER JOIN public.people AS person ON body.assignee = person.owner_pub_key LEFT OUTER JOIN public.people as owner ON body.owner_id = owner.owner_pub_key LEFT OUTER JOIN public.organizations as org ON body.org_uuid = org.uuid WHERE body.assignee = '` + pubkey + `' AND body.show != false ORDER BY body.id DESC`).Find(&ms).Error

return ms, err
}
Expand All @@ -499,6 +499,14 @@ func (db database) GetBountyById(id string) ([]BountyData, error) {
return ms, err
}

func (db database) GetBountyDataByCreated(created string) ([]BountyData, error) {
ms := []BountyData{}

err := db.db.Raw(`SELECT body.*, body.id as bounty_id, body.description as bounty_description, body.created as bounty_created, body.updated as bounty_updated, body.org_uuid, person.*, person.owner_alias as assignee_alias, person.id as assignee_id, person.description as assignee_description, person.created as assignee_created, person.updated as assignee_updated, person.owner_route_hint as assignee_route_hint, owner.id as bounty_owner_id, owner.uuid as owner_uuid, owner.owner_pub_key as owner_key, owner.owner_alias as owner_alias, owner.description as owner_description, owner.price_to_meet as owner_price_to_meet, owner.unique_name as owner_unique_name, owner.tags as owner_tags, owner.img as owner_img, owner.created as owner_created, owner.updated as owner_updated, owner.last_login as owner_last_login, owner.owner_route_hint as owner_route_hint, owner.owner_contact_key as owner_contact_key, org.name as organization_name, org.uuid as organization_uuid, org.img as organization_img FROM public.bounty AS body LEFT OUTER JOIN public.people AS person ON body.assignee = person.owner_pub_key LEFT OUTER JOIN public.people as owner ON body.owner_id = owner.owner_pub_key LEFT OUTER JOIN public.organizations as org ON body.org_uuid = org.uuid WHERE body.created = '` + created + `' ORDER BY body.id DESC`).Find(&ms).Error

return ms, err
}

func (db database) AddBounty(b Bounty) (Bounty, error) {
db.db.Create(&b)
return b, nil
Expand Down Expand Up @@ -1118,7 +1126,9 @@ func (db database) CreateOrganizationBudget(budget BountyBudget) BountyBudget {
}

func (db database) UpdateOrganizationBudget(budget BountyBudget) BountyBudget {
db.db.Where("org_uuid = ?", budget.OrgUuid).Updates(budget)
db.db.Model(&BountyBudget{}).Where("org_uuid = ?", budget.OrgUuid).Updates(map[string]interface{}{
"total_budget": budget.TotalBudget,
})
return budget
}

Expand Down Expand Up @@ -1202,7 +1212,7 @@ func (db database) WithdrawBudget(sender_pubkey string, org_uuid string, amount
func (db database) AddPaymentHistory(payment PaymentHistory) PaymentHistory {
db.db.Create(&payment)

// get organization budget and substract payment from total budget
// get organization budget and subtract payment from total budget
organizationBudget := db.GetOrganizationBudget(payment.OrgUuid)
totalBudget := organizationBudget.TotalBudget

Expand Down
Loading

0 comments on commit d97cc59

Please sign in to comment.