mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
Removed redundant vote code
This commit is contained in:
parent
b1865b2318
commit
5153d49ad7
4 changed files with 0 additions and 91 deletions
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue