Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*.dylib
cmswww/cmswww
cmswww/cmd/cmswwwcli/cmswwwcli
cmswww/cmd/cmswwwdataload/cmswwwdataload

# Test binary, build with `go test -c`
*.test
Expand Down
11 changes: 3 additions & 8 deletions cmswww/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@ import (
"net/http"
"os"
"sort"
"strconv"
"strings"
"time"

"github.com/decred/contractor-mgmt/cmswww/api/v1"
"github.com/decred/contractor-mgmt/cmswww/database"
"github.com/gofrs/uuid"
)

func (c *cmswww) getUserByIDStr(userIDStr string) (*database.User, error) {
userID, err := strconv.ParseUint(userIDStr, 10, 64)
if err != nil {
return nil, err
}

func (c *cmswww) getUserByIDStr(userID uuid.UUID) (*database.User, error) {
user, err := c.db.GetUserById(userID)
if err != nil {
return nil, err
Expand Down Expand Up @@ -323,7 +318,7 @@ func (c *cmswww) HandleUsers(
ur.Users = make([]v1.AbridgedUser, 0, len(users))
for _, user := range users {
ur.Users = append(ur.Users, v1.AbridgedUser{
ID: strconv.FormatUint(user.ID, 10),
ID: user.ID.String(),
Email: user.Email,
Username: user.Username,
Admin: user.Admin,
Expand Down
7 changes: 4 additions & 3 deletions cmswww/cmd/cmswwwcli/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"encoding/json"
"fmt"
"log"
"net/http"
"net/http/cookiejar"
"net/url"
Expand Down Expand Up @@ -84,7 +85,7 @@ func (c *Ctx) makeRequest(method, route string, requestJSON interface{}, respons
}

if config.Verbose {
fmt.Printf("Request: %v %v ", method, fullRoute)
log.Printf("Request: %v %v ", method, fullRoute)
if method != http.MethodGet {
prettyPrintJSON(requestJSON)
} else {
Expand Down Expand Up @@ -129,7 +130,7 @@ func (c *Ctx) handleResponse(r *http.Response, responseJSON interface{}) error {

if r.StatusCode != http.StatusOK {
if config.Verbose {
fmt.Printf("Response: %v ", r.Status)
log.Printf("Response: %v ", r.Status)
var errJSON interface{}
err := json.Unmarshal(responseBody, &errJSON)
if err == nil {
Expand Down Expand Up @@ -163,7 +164,7 @@ func (c *Ctx) handleResponse(r *http.Response, responseJSON interface{}) error {
}

if config.Verbose {
fmt.Printf("Response: %v ", r.Status)
log.Printf("Response: %v ", r.Status)
if responseJSON != nil {
prettyPrintJSON(responseJSON)
} else {
Expand Down
3 changes: 2 additions & 1 deletion cmswww/cmd/cmswwwcli/commands/editinvoice.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"

"github.com/decred/contractor-mgmt/cmswww/api/v1"
"github.com/decred/contractor-mgmt/cmswww/cmd/cmswwwcli/config"
Expand Down Expand Up @@ -105,7 +106,7 @@ func (cmd *EditInvoiceCmd) Execute(args []string) error {
}

if !config.JSONOutput {
fmt.Printf("Invoice submitted successfully! The censorship record has"+
log.Printf("Invoice submitted successfully! The censorship record has"+
" been stored in %v for your future reference.",
revisionRecordFilename)
}
Expand Down
4 changes: 2 additions & 2 deletions cmswww/cmd/cmswwwcli/commands/invitenewuser.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package commands

import (
"fmt"
"log"

"github.com/decred/contractor-mgmt/cmswww/api/v1"
"github.com/decred/contractor-mgmt/cmswww/cmd/cmswwwcli/config"
Expand Down Expand Up @@ -30,7 +30,7 @@ func (cmd *InviteNewUserCmd) Execute(args []string) error {
}

if !config.JSONOutput {
fmt.Printf("Invitation created and sent to %v. Their invitation will expire"+
log.Printf("Invitation created and sent to %v. Their invitation will expire"+
" in %v.\n", cmd.Args.Email, v1.VerificationExpiryTime.String())
}
return nil
Expand Down
10 changes: 5 additions & 5 deletions cmswww/cmd/cmswwwcli/commands/invoicedetails.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package commands

import (
"fmt"
"log"
"time"

"github.com/decred/contractor-mgmt/cmswww/api/v1"
Expand Down Expand Up @@ -33,11 +33,11 @@ func (cmd *InvoiceDetailsCmd) Execute(args []string) error {
if !config.JSONOutput {
date := time.Date(int(idr.Invoice.Year), time.Month(idr.Invoice.Month),
1, 0, 0, 0, 0, time.UTC)
fmt.Printf("%v %v\n", idr.Invoice.CensorshipRecord.Token[0:7],
log.Printf("%v %v\n", idr.Invoice.CensorshipRecord.Token[0:7],
idr.Invoice.CensorshipRecord.Token)
fmt.Printf(" Submitted by: %v\n", idr.Invoice.Username)
fmt.Printf(" at: %v\n", time.Unix(idr.Invoice.Timestamp, 0))
fmt.Printf(" For: %v\n", date.Format("January 2006"))
log.Printf(" Submitted by: %v\n", idr.Invoice.Username)
log.Printf(" at: %v\n", time.Unix(idr.Invoice.Timestamp, 0))
log.Printf(" For: %v\n", date.Format("January 2006"))
}

return nil
Expand Down
13 changes: 7 additions & 6 deletions cmswww/cmd/cmswwwcli/commands/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"fmt"
"log"
"strings"
"time"

Expand Down Expand Up @@ -59,18 +60,18 @@ func (cmd *InvoicesCmd) Execute(args []string) error {
}

if !config.JSONOutput {
fmt.Printf("Invoices: ")
log.Printf("Invoices: ")
if len(ir.Invoices) == 0 {
fmt.Printf("none\n")
log.Printf("none\n")
} else {
fmt.Println()
for _, v := range ir.Invoices {
fmt.Printf(" %v\n", v.CensorshipRecord.Token)
fmt.Printf(" Submitted by: %v\n", v.Username)
fmt.Printf(" at: %v\n",
log.Printf(" %v\n", v.CensorshipRecord.Token)
log.Printf(" Submitted by: %v\n", v.Username)
log.Printf(" at: %v\n",
time.Unix(v.Timestamp, 0).String())
if cmd.Status == "" {
fmt.Printf(" Status: %v\n",
log.Printf(" Status: %v\n",
v1.InvoiceStatus[v.Status])
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmswww/cmd/cmswwwcli/commands/login.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package commands

import (
"fmt"
"log"

"github.com/decred/contractor-mgmt/cmswww/api/v1"
"github.com/decred/contractor-mgmt/cmswww/cmd/cmswwwcli/config"
Expand Down Expand Up @@ -33,13 +33,13 @@ func (cmd *LoginCmd) Execute(args []string) error {

config.LoggedInUser = &lr
if !config.JSONOutput {
fmt.Printf("You are now logged in as %v\n", lr.Username)
log.Printf("You are now logged in as %v\n", lr.Username)
}

// Load identity, if available.
_, err = config.LoadUserIdentity(cmd.Args.Email)
if err != nil && !config.JSONOutput {
fmt.Printf("WARNING: Your identity could not be loaded, please generate" +
log.Printf("WARNING: Your identity could not be loaded, please generate" +
" a new one using the newidentity command\n")
}

Expand Down
4 changes: 2 additions & 2 deletions cmswww/cmd/cmswwwcli/commands/logout.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package commands

import (
"fmt"
"log"

"github.com/decred/contractor-mgmt/cmswww/api/v1"
"github.com/decred/contractor-mgmt/cmswww/cmd/cmswwwcli/config"
Expand All @@ -21,7 +21,7 @@ func (cmd *LogoutCmd) Execute(args []string) error {
}

if !config.JSONOutput {
fmt.Printf("You are now logged out\n")
log.Printf("You are now logged out\n")
}
config.LoggedInUser = nil
config.LoggedInUserIdentity = nil
Expand Down
3 changes: 2 additions & 1 deletion cmswww/cmd/cmswwwcli/commands/logwork.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"encoding/csv"
"fmt"
"log"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -55,7 +56,7 @@ func promptForFieldValues() ([]string, error) {
if !field.Required {
optionalStr = " (optional)"
}
fmt.Printf("%v%v: ", field.Name, optionalStr)
log.Printf("%v%v: ", field.Name, optionalStr)
}
valueStr, err := reader.ReadString('\n')
if err != nil {
Expand Down
15 changes: 8 additions & 7 deletions cmswww/cmd/cmswwwcli/commands/myinvoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"encoding/json"
"fmt"
"log"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -166,28 +167,28 @@ func (cmd *MyInvoicesCmd) Execute(args []string) error {
return nil
}

fmt.Printf("Invoices: ")
log.Printf("Invoices: ")
if len(allInvoices) == 0 {
fmt.Printf("none\n")
log.Printf("none\n")
} else {
for _, v := range allInvoices {
fmt.Println()

date := time.Date(int(v.Year), time.Month(v.Month),
1, 0, 0, 0, 0, time.UTC)
fmt.Printf(" %v • ", date.Format("January 2006"))
log.Printf(" %v • ", date.Format("January 2006"))
if v.Token != nil {
fmt.Printf("%v\n", *v.Token)
log.Printf("%v\n", *v.Token)
} else {
fmt.Printf("Draft\n")
log.Printf("Draft\n")
}

if v.Timestamp != nil {
fmt.Printf(" Submitted: %v\n",
log.Printf(" Submitted: %v\n",
time.Unix(*v.Timestamp, 0).String())
}

fmt.Printf(" Status: %v\n", v.Status)
log.Printf(" Status: %v\n", v.Status)
}
}

Expand Down
25 changes: 13 additions & 12 deletions cmswww/cmd/cmswwwcli/commands/payinvoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"fmt"
"log"

"github.com/decred/contractor-mgmt/cmswww/api/v1"
"github.com/decred/contractor-mgmt/cmswww/cmd/cmswwwcli/config"
Expand Down Expand Up @@ -39,26 +40,26 @@ func (cmd *PayInvoicesCmd) Execute(args []string) error {
}

if !config.JSONOutput {
fmt.Printf("Invoices ready to be paid: ")
log.Printf("Invoices ready to be paid: ")
if len(pir.Invoices) == 0 {
fmt.Printf("none\n")
log.Printf("none\n")
} else {
for _, invoice := range pir.Invoices {
fmt.Println()
fmt.Println()

rate := float64(invoice.TotalCostUSD) / float64(invoice.TotalHours)

fmt.Printf(" User ID: %v\n", invoice.UserID)
fmt.Printf(" Username: %v\n", invoice.Username)
fmt.Printf(" Invoice token: %v\n", invoice.Token)
fmt.Printf(" ------------------------------------------\n")
fmt.Printf(" Hours: %v\n", invoice.TotalHours)
fmt.Printf(" Total cost: $%v\n", invoice.TotalCostUSD)
fmt.Printf(" Average Rate: $%.2f / hr\n", rate)
fmt.Printf(" ------------------------------------------\n")
fmt.Printf(" Total cost: %v DCR\n", invoice.TotalCostDCR)
fmt.Printf(" Payment Address: %v\n", invoice.PaymentAddress)
log.Printf(" User ID: %v\n", invoice.UserID)
log.Printf(" Username: %v\n", invoice.Username)
log.Printf(" Invoice token: %v\n", invoice.Token)
log.Printf(" ------------------------------------------\n")
log.Printf(" Hours: %v\n", invoice.TotalHours)
log.Printf(" Total cost: $%v\n", invoice.TotalCostUSD)
log.Printf(" Average Rate: $%.2f / hr\n", rate)
log.Printf(" ------------------------------------------\n")
log.Printf(" Total cost: %v DCR\n", invoice.TotalCostDCR)
log.Printf(" Payment Address: %v\n", invoice.PaymentAddress)
}
}
}
Expand Down
37 changes: 19 additions & 18 deletions cmswww/cmd/cmswwwcli/commands/reviewinvoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package commands

import (
"fmt"
"log"

"github.com/decred/contractor-mgmt/cmswww/api/v1"
"github.com/decred/contractor-mgmt/cmswww/cmd/cmswwwcli/config"
Expand Down Expand Up @@ -37,42 +38,42 @@ func (cmd *ReviewInvoicesCmd) Execute(args []string) error {
}

if !config.JSONOutput {
fmt.Printf("Invoices to review: ")
log.Printf("Invoices to review: ")
if len(rir.Invoices) == 0 {
fmt.Printf("none\n")
log.Printf("none\n")
} else {
for _, invoice := range rir.Invoices {
fmt.Println()
fmt.Println()

totalRate := float64(invoice.TotalCostUSD) / float64(invoice.TotalHours)

fmt.Printf(" User ID: %v\n", invoice.UserID)
fmt.Printf(" Username: %v\n", invoice.Username)
fmt.Printf(" Token: %v\n", invoice.Token)
fmt.Printf(" ------------------------------------------\n")
log.Printf(" User ID: %v\n", invoice.UserID)
log.Printf(" Username: %v\n", invoice.Username)
log.Printf(" Token: %v\n", invoice.Token)
log.Printf(" ------------------------------------------\n")
for lineItemIdx, lineItem := range invoice.LineItems {
if lineItemIdx > 0 {
fmt.Printf(" --------------------------------\n")
log.Printf(" --------------------------------\n")
}

rate := float64(lineItem.TotalCost) / float64(lineItem.Hours)
fmt.Printf(" Type: %v\n", lineItem.Type)
log.Printf(" Type: %v\n", lineItem.Type)
if lineItem.Subtype != "" {
fmt.Printf(" Subtype: %v\n", lineItem.Subtype)
log.Printf(" Subtype: %v\n", lineItem.Subtype)
}
fmt.Printf(" Description: %v\n", lineItem.Description)
log.Printf(" Description: %v\n", lineItem.Description)
if lineItem.Proposal != "" {
fmt.Printf(" Politeia proposal: %v\n", lineItem.Proposal)
log.Printf(" Politeia proposal: %v\n", lineItem.Proposal)
}
fmt.Printf(" Hours: %v\n", lineItem.Hours)
fmt.Printf(" Total cost: $%v\n", lineItem.TotalCost)
fmt.Printf(" Rate: $%.2f / hr\n", rate)
log.Printf(" Hours: %v\n", lineItem.Hours)
log.Printf(" Total cost: $%v\n", lineItem.TotalCost)
log.Printf(" Rate: $%.2f / hr\n", rate)
}
fmt.Printf(" ------------------------------------------\n")
fmt.Printf(" Hours: %v\n", invoice.TotalHours)
fmt.Printf(" Total cost: $%v\n", invoice.TotalCostUSD)
fmt.Printf(" Average Rate: $%.2f / hr\n", totalRate)
log.Printf(" ------------------------------------------\n")
log.Printf(" Hours: %v\n", invoice.TotalHours)
log.Printf(" Total cost: $%v\n", invoice.TotalCostUSD)
log.Printf(" Average Rate: $%.2f / hr\n", totalRate)
}
}
}
Expand Down
Loading