From 5153d49ad718ab6e1f8c90aeb1b77e005451d67d Mon Sep 17 00:00:00 2001 From: McMatts Date: Tue, 13 Nov 2018 18:53:29 +0000 Subject: [PATCH] Removed redundant vote code --- domain/document/endpoint.go | 70 ------------------------------------- domain/document/store.go | 19 ---------- domain/store/storer.go | 1 - server/routing/routes.go | 1 - 4 files changed, 91 deletions(-) diff --git a/domain/document/endpoint.go b/domain/document/endpoint.go index 3ae67138..6e437a0c 100644 --- a/domain/document/endpoint.go +++ b/domain/document/endpoint.go @@ -24,7 +24,6 @@ import ( "github.com/documize/community/core/response" "github.com/documize/community/core/streamutil" "github.com/documize/community/core/stringutil" - "github.com/documize/community/core/uniqueid" "github.com/documize/community/domain" "github.com/documize/community/domain/organization" "github.com/documize/community/domain/permission" @@ -662,75 +661,6 @@ type BulkDocumentData struct { Versions []doc.Version `json:"versions"` } -// Vote records document content vote, Yes, No. -// Anonymous users should be assigned a temporary ID -func (h *Handler) Vote(w http.ResponseWriter, r *http.Request) { - method := "document.Vote" - ctx := domain.GetRequestContext(r) - - // Deduce ORG because public API call. - ctx.Subdomain = organization.GetSubdomainFromHost(r) - org, err := h.Store.Organization.GetOrganizationByDomain(ctx.Subdomain) - if err != nil { - response.WriteServerError(w, method, err) - h.Runtime.Log.Error(method, err) - return - } - ctx.OrgID = org.RefID - - documentID := request.Param(r, "documentID") - if len(documentID) == 0 { - response.WriteMissingDataError(w, method, "documentID") - return - } - - defer streamutil.Close(r.Body) - body, err := ioutil.ReadAll(r.Body) - if err != nil { - response.WriteBadRequestError(w, method, err.Error()) - h.Runtime.Log.Error(method, err) - return - } - - var payload struct { - UserID string `json:"userId"` - Vote int `json:"vote"` - } - - err = json.Unmarshal(body, &payload) - if err != nil { - response.WriteBadRequestError(w, method, err.Error()) - h.Runtime.Log.Error(method, err) - return - } - - ctx.Transaction, err = h.Runtime.Db.Beginx() - if err != nil { - response.WriteServerError(w, method, err) - h.Runtime.Log.Error(method, err) - return - } - - doc, err := h.Store.Document.Get(ctx, documentID) - if err != nil { - response.WriteServerError(w, method, err) - h.Runtime.Log.Error(method, err) - return - } - - err = h.Store.Document.Vote(ctx, uniqueid.Generate(), doc.OrgID, documentID, payload.UserID, payload.Vote) - if err != nil { - ctx.Transaction.Rollback() - response.WriteServerError(w, method, err) - h.Runtime.Log.Error(method, err) - return - } - - ctx.Transaction.Commit() - - response.WriteEmpty(w) -} - // Export returns content as self-enclosed HTML file. func (h *Handler) Export(w http.ResponseWriter, r *http.Request) { method := "document.Export" diff --git a/domain/document/store.go b/domain/document/store.go index 5a0bb271..d140e8db 100644 --- a/domain/document/store.go +++ b/domain/document/store.go @@ -318,22 +318,3 @@ func (s Store) GetVersions(ctx domain.RequestContext, groupID string) (v []doc.V return } - -// Vote records document content vote. -// Any existing vote by the user is replaced. -func (s Store) Vote(ctx domain.RequestContext, refID, orgID, documentID, userID string, vote int) (err error) { - _, err = s.DeleteWhere(ctx.Transaction, - fmt.Sprintf("DELETE FROM dmz_doc_vote WHERE c_orgid='%s' AND c_docid='%s' AND c_voter='%s'", - orgID, documentID, userID)) - if err != nil { - s.Runtime.Log.Error("store.Vote", err) - } - - _, err = ctx.Transaction.Exec(s.Bind(`INSERT INTO dmz_doc_vote (c_refid, c_orgid, c_docid, c_voter, c_vote) VALUES (?, ?, ?, ?, ?)`), - refID, orgID, documentID, userID, vote) - if err != nil { - err = errors.Wrap(err, "execute insert vote") - } - - return -} diff --git a/domain/store/storer.go b/domain/store/storer.go index f0489d46..fe74009b 100644 --- a/domain/store/storer.go +++ b/domain/store/storer.go @@ -183,7 +183,6 @@ type DocumentStorer interface { DeleteBySpace(ctx domain.RequestContext, spaceID string) (rows int64, err error) GetVersions(ctx domain.RequestContext, groupID string) (v []doc.Version, err error) MoveActivity(ctx domain.RequestContext, documentID, oldSpaceID, newSpaceID string) (err error) - Vote(ctx domain.RequestContext, refID, orgID, documentID, userID string, vote int) (err error) } // SettingStorer defines required methods for persisting global and user level settings diff --git a/server/routing/routes.go b/server/routing/routes.go index b686552d..563a606a 100644 --- a/server/routing/routes.go +++ b/server/routing/routes.go @@ -91,7 +91,6 @@ func RegisterEndpoints(rt *env.Runtime, s *store.Store) { AddPublic(rt, "reset/{token}", []string{"POST", "OPTIONS"}, nil, user.ResetPassword) AddPublic(rt, "share/{spaceID}", []string{"POST", "OPTIONS"}, nil, space.AcceptInvitation) AddPublic(rt, "attachments/{orgID}/{attachmentID}", []string{"GET", "OPTIONS"}, nil, attachment.Download) - AddPublic(rt, "document/{documentID}/vote", []string{"POST", "OPTIONS"}, nil, document.Vote) //************************************************** // Secured private routes (require authentication)