Skip to content

Commit

Permalink
frontend updates, csv, multiple fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
alecxcode committed Jan 30, 2023
1 parent 7fa2837 commit f7cbafe
Show file tree
Hide file tree
Showing 64 changed files with 1,891 additions and 1,527 deletions.
11 changes: 8 additions & 3 deletions cmd/edm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"edm/pkg/memdb"
"edm/pkg/ramdb"
"edm/pkg/redisdb"
"fmt"
"log"
"net/http"
"os"
Expand Down Expand Up @@ -61,7 +62,11 @@ func main() {
// Reading command-line arguments
filldb := false
consolelog := false
cfg.CreateDB, filldb, cfg.RunBrowser, consolelog = processCmdLineArgs(cfg.CreateDB, filldb, cfg.RunBrowser, consolelog)
cfg.CreateDB, filldb, cfg.RunBrowser, consolelog, err = processCmdLineArgs(cfg.CreateDB, filldb, cfg.RunBrowser, consolelog)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

// Server root path:
if accs.FileExists(cfg.ServerRoot) != true {
Expand Down Expand Up @@ -262,8 +267,8 @@ func main() {

if accs.StrToBool(cfg.UseTLS) {
log.Fatal(http.ListenAndServeTLS(cfg.ServerHost+":"+cfg.ServerPort,
filepath.Join(cfg.ServerRoot, cfg.SSLCertFile),
filepath.Join(cfg.ServerRoot, cfg.SSLKeyFile),
accs.GetAbsoluteOrRelativePath(cfg.ServerRoot, cfg.SSLCertFile),
accs.GetAbsoluteOrRelativePath(cfg.ServerRoot, cfg.SSLKeyFile),
nil))
} else {
log.Fatal(http.ListenAndServe(cfg.ServerHost+":"+cfg.ServerPort, nil))
Expand Down
12 changes: 9 additions & 3 deletions cmd/edm/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"edm/internal/config"
"edm/pkg/accs"
"errors"
"html/template"
"os"
"path/filepath"
Expand Down Expand Up @@ -51,8 +52,10 @@ func getTemplates(templatesPath string) *template.Template {
))
}

func processCmdLineArgs(createdb string, filldb bool, runbrowser string, consolelog bool) (string, bool, string, bool) {
for _, a := range os.Args {
func processCmdLineArgs(createdb string, filldb bool, runbrowser string, consolelog bool) (string, bool, string, bool, error) {
validArgs := []string{"--createdb", "--filldb", "--nobrowser", "--consolelog"}
var err error = nil
for i, a := range os.Args {
if a == "--createdb" {
createdb = "true"
}
Expand All @@ -65,6 +68,9 @@ func processCmdLineArgs(createdb string, filldb bool, runbrowser string, console
if a == "--consolelog" {
consolelog = true
}
if i > 0 && !accs.SliceContainsStr(validArgs, a) {
err = errors.New("wrong command line argument: the program finished with no action")
}
}
return createdb, filldb, runbrowser, consolelog
return createdb, filldb, runbrowser, consolelog, err
}
2 changes: 1 addition & 1 deletion internal/core/consts.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package core

// AppVersion is this application version
const AppVersion = "2.0.0"
const AppVersion = "2.1.0"

// Undefined is for any unknown category, type, etc.
const Undefined = 0
Expand Down
17 changes: 13 additions & 4 deletions internal/core/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ func AuthVerify(w http.ResponseWriter, r *http.Request, memorydb memdb.ObjectsIn
func AuthVerifyAPI(w http.ResponseWriter, r *http.Request, memorydb memdb.ObjectsInMemory) (res bool, id int) {
thecookie, err := r.Cookie("sessionid")
if err == http.ErrNoCookie {
accs.ThrowAccessDeniedAPI(w, r.URL.Path, 0)
accs.ThrowAccessDenied(w, r.URL.Path, 0, 0)
return
}
allow, id := memorydb.CheckSession(thecookie.Value)
if !allow {
accs.ThrowAccessDeniedAPI(w, r.URL.Path, id)
accs.ThrowAccessDenied(w, r.URL.Path, id, 0)
return
}
return true, id
Expand All @@ -75,16 +75,18 @@ func (cb *CoreBase) IndexHandler(w http.ResponseWriter, r *http.Request) {
return
}
if cb.validURLs.FindStringSubmatch(r.URL.Path) == nil {
http.NotFound(w, r)
accs.ThrowObjectNotFound(w, r)
return
}
switch cb.cfg.startPage {
case "docs":
http.Redirect(w, r, "/docs/", http.StatusSeeOther)
case "tasks":
http.Redirect(w, r, "/tasks/", http.StatusSeeOther)
http.Redirect(w, r, "/tasks/?anyparticipants=my&from=core", http.StatusSeeOther)
case "team":
http.Redirect(w, r, "/team/", http.StatusSeeOther)
case "projs":
http.Redirect(w, r, "/projs/?projstatuses=0&from=core", http.StatusSeeOther)
case "portal":
http.Redirect(w, r, "/portal/", http.StatusSeeOther)
default:
Expand Down Expand Up @@ -119,3 +121,10 @@ func (cb *CoreBase) ServeUploads(w http.ResponseWriter, r *http.Request) {
}
cb.uploads.ServeHTTP(w, r)
}

func IfAddJSON(r *http.Request) string {
if r.URL.Query().Get("api") == "json" || r.FormValue("api") == "json" {
return "?api=json"
}
return ""
}
6 changes: 3 additions & 3 deletions internal/core/themes.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

// GetThemeList loads a list of available frontend themes
func GetThemeList(serverSystem string) []string {
files, err := ioutil.ReadDir(filepath.Join(serverSystem, "static"))
files, err := ioutil.ReadDir(filepath.Join(serverSystem, "static", "themes"))
if err != nil {
log.Println(accs.CurrentFunction()+":", err)
return []string{}
Expand All @@ -19,8 +19,8 @@ func GetThemeList(serverSystem string) []string {
var fname string
for _, file := range files {
fname = file.Name()
if ext := filepath.Ext(fname); ext == ".css" && strings.HasPrefix(fname, "theme-") {
fname = fname[6 : len(fname)-len(ext)]
if ext := filepath.Ext(fname); ext == ".css" && !strings.HasPrefix(fname, "system-") {
fname = fname[0 : len(fname)-len(ext)]
res = append(res, fname)
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/docs/docspage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"edm/pkg/currencies"
"edm/pkg/datetime"
"encoding/json"
"fmt"
"log"
"net/http"
"path/filepath"
Expand Down Expand Up @@ -49,7 +50,7 @@ func (dd *DocsBase) DocsHandler(w http.ResponseWriter, r *http.Request) {
}

if dd.validURLs.FindStringSubmatch(r.URL.Path) == nil {
http.NotFound(w, r)
accs.ThrowObjectNotFound(w, r)
return
}

Expand Down Expand Up @@ -272,8 +273,7 @@ func (dd *DocsBase) DocsHandler(w http.ResponseWriter, r *http.Request) {
}()

if err != nil {
log.Println(accs.CurrentFunction()+":", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
accs.ThrowServerError(w, fmt.Sprintf(accs.CurrentFunction()+":", err), Page.LoggedinID, 0)
return
}

Expand Down
8 changes: 4 additions & 4 deletions internal/docs/documentpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (dd *DocsBase) DocumentHandler(w http.ResponseWriter, r *http.Request) {
}

if dd.validURLs.FindStringSubmatch(r.URL.Path) == nil {
http.NotFound(w, r)
accs.ThrowObjectNotFound(w, r)
return
}

Expand All @@ -78,7 +78,7 @@ func (dd *DocsBase) DocumentHandler(w http.ResponseWriter, r *http.Request) {
err = Page.Document.load(dd.db, dd.dbType)
if err != nil {
log.Println(accs.CurrentFunction()+":", err)
http.NotFound(w, r)
accs.ThrowObjectNotFound(w, r)
return
}
Page.Approvals, err = Page.Document.loadApprovals(dd.db, dd.dbType)
Expand Down Expand Up @@ -152,9 +152,9 @@ func (dd *DocsBase) DocumentHandler(w http.ResponseWriter, r *http.Request) {
filepath.Join(dd.cfg.serverRoot, "files", "docs", strconv.Itoa(d.ID)),
d.FileList)
if Page.UserConfig.ReturnAfterCreation {
http.Redirect(w, r, "/docs/", http.StatusSeeOther)
http.Redirect(w, r, "/docs/"+core.IfAddJSON(r), http.StatusSeeOther)
} else {
http.Redirect(w, r, fmt.Sprintf("/docs/document/%d", d.ID), http.StatusSeeOther)
http.Redirect(w, r, fmt.Sprintf("/docs/document/%d"+core.IfAddJSON(r), d.ID), http.StatusSeeOther)
}
return
} else {
Expand Down
4 changes: 2 additions & 2 deletions internal/projs/getproj.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (pb *ProjsBase) GetProjAPI(w http.ResponseWriter, r *http.Request) {
var reqObj reqProj
err = json.NewDecoder(r.Body).Decode(&reqObj)
if err != nil {
accs.ThrowServerErrorAPI(w, accs.CurrentFunction()+": decoding json request", loggedinID, reqObj.Proj)
accs.ThrowServerError(w, accs.CurrentFunction()+": decoding json request", loggedinID, reqObj.Proj)
return
}
proj := Project{ID: reqObj.Proj}
Expand All @@ -33,7 +33,7 @@ func (pb *ProjsBase) GetProjAPI(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"error":804,"description":"object not found"}`)
return
} else if err != nil {
accs.ThrowServerErrorAPI(w, accs.CurrentFunction()+": loading project", loggedinID, reqObj.Proj)
accs.ThrowServerError(w, accs.CurrentFunction()+": loading project", loggedinID, reqObj.Proj)
return
}
json.NewEncoder(w).Encode(proj)
Expand Down
8 changes: 4 additions & 4 deletions internal/projs/projectpage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func (pb *ProjsBase) ProjectHandler(w http.ResponseWriter, r *http.Request) {
}

if pb.validURLs.FindStringSubmatch(r.URL.Path) == nil {
http.NotFound(w, r)
accs.ThrowObjectNotFound(w, r)
return
}

Expand All @@ -66,7 +66,7 @@ func (pb *ProjsBase) ProjectHandler(w http.ResponseWriter, r *http.Request) {
err = Page.Project.load(pb.db, pb.dbType)
if err != nil {
log.Println(accs.CurrentFunction()+":", err)
http.NotFound(w, r)
accs.ThrowObjectNotFound(w, r)
return
}
if err != nil {
Expand Down Expand Up @@ -110,9 +110,9 @@ func (pb *ProjsBase) ProjectHandler(w http.ResponseWriter, r *http.Request) {
p.ID, created = p.Create(pb.db, pb.dbType)
if created > 0 {
if Page.UserConfig.ReturnAfterCreation {
http.Redirect(w, r, "/projs/", http.StatusSeeOther)
http.Redirect(w, r, "/projs/?projstatuses=0"+core.IfAddJSON(r), http.StatusSeeOther)
} else {
http.Redirect(w, r, fmt.Sprintf("/projs/project/%d", p.ID), http.StatusSeeOther)
http.Redirect(w, r, fmt.Sprintf("/projs/project/%d"+core.IfAddJSON(r), p.ID), http.StatusSeeOther)
}
return
} else {
Expand Down
6 changes: 3 additions & 3 deletions internal/projs/projspage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"edm/pkg/datetime"
"edm/pkg/memdb"
"encoding/json"
"fmt"
"log"
"net/http"
"strconv"
Expand Down Expand Up @@ -43,7 +44,7 @@ func (pb *ProjsBase) ProjsHandler(w http.ResponseWriter, r *http.Request) {
}

if pb.validURLs.FindStringSubmatch(r.URL.Path) == nil {
http.NotFound(w, r)
accs.ThrowObjectNotFound(w, r)
return
}

Expand Down Expand Up @@ -188,8 +189,7 @@ func (pb *ProjsBase) ProjsHandler(w http.ResponseWriter, r *http.Request) {
}()

if err != nil {
log.Println(accs.CurrentFunction()+":", err)
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
accs.ThrowServerError(w, fmt.Sprintf(accs.CurrentFunction()+":", err), Page.LoggedinID, 0)
return
}

Expand Down
10 changes: 5 additions & 5 deletions internal/projs/setprojstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (pb *ProjsBase) SetProjStatusAPI(w http.ResponseWriter, r *http.Request) {
var reqObj reqProjStatus
err = json.NewDecoder(r.Body).Decode(&reqObj)
if err != nil {
accs.ThrowServerErrorAPI(w, accs.CurrentFunction()+": decoding json request", loggedinID, reqObj.Proj)
accs.ThrowServerError(w, accs.CurrentFunction()+": decoding json request", loggedinID, reqObj.Proj)
return
}
proj := Project{ID: reqObj.Proj}
Expand All @@ -37,22 +37,22 @@ func (pb *ProjsBase) SetProjStatusAPI(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"error":804,"description":"object not found"}`)
return
} else if err != nil {
accs.ThrowServerErrorAPI(w, accs.CurrentFunction()+": loading project", loggedinID, reqObj.Proj)
accs.ThrowServerError(w, accs.CurrentFunction()+": loading project", loggedinID, reqObj.Proj)
return
}
user := team.UnmarshalToProfile(pb.memorydb.GetByID(loggedinID))
var res int
if user.UserRole == team.ADMIN || proj.GiveCreatorID() == loggedinID {
res = sqla.UpdateSingleInt(pb.db, pb.dbType, "projects", "ProjStatus", reqObj.Status, proj.ID)
res = sqla.UpdateSingleInt(pb.db, pb.dbType, "projects", "ProjStatus", reqObj.Status, reqObj.Proj)
} else {
accs.ThrowAccessDeniedAPI(w, r.URL.Path, loggedinID)
accs.ThrowAccessDenied(w, r.URL.Path, loggedinID, reqObj.Proj)
return
}
if res > 0 {
proj.ProjStatus = reqObj.Status
json.NewEncoder(w).Encode(proj)
return
}
accs.ThrowServerErrorAPI(w, accs.CurrentFunction()+": updating project", loggedinID, proj.ID)
accs.ThrowServerError(w, accs.CurrentFunction()+": updating project", loggedinID, reqObj.Proj)
return
}
6 changes: 3 additions & 3 deletions internal/tasks/assigntask.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (tb *TasksBase) AssignTaskAPI(w http.ResponseWriter, r *http.Request) {
var reqObj reqAssignTask
err = json.NewDecoder(r.Body).Decode(&reqObj)
if err != nil {
accs.ThrowServerErrorAPI(w, accs.CurrentFunction()+": decoding json request", loggedinID, reqObj.Task)
accs.ThrowServerError(w, accs.CurrentFunction()+": decoding json request", loggedinID, reqObj.Task)
return
}
task := Task{ID: reqObj.Task}
Expand All @@ -40,7 +40,7 @@ func (tb *TasksBase) AssignTaskAPI(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"error":804,"description":"object not found"}`)
return
} else if err != nil {
accs.ThrowServerErrorAPI(w, accs.CurrentFunction()+": loading task before", loggedinID, reqObj.Task)
accs.ThrowServerError(w, accs.CurrentFunction()+": loading task before", loggedinID, reqObj.Task)
return
}
user := team.UnmarshalToProfile(tb.memorydb.GetByID(loggedinID))
Expand Down Expand Up @@ -75,6 +75,6 @@ func (tb *TasksBase) AssignTaskAPI(w http.ResponseWriter, r *http.Request) {
json.NewEncoder(w).Encode(task)
return
}
accs.ThrowAccessDeniedAPI(w, r.URL.Path, loggedinID)
accs.ThrowAccessDenied(w, r.URL.Path, loggedinID, reqObj.Task)
return
}
Loading

0 comments on commit f7cbafe

Please sign in to comment.