1
0
Fork 0
mirror of https://github.com/documize/community.git synced 2025-07-19 05:09:42 +02:00

event handlers framework

This commit is contained in:
Harvey Kandola 2017-05-01 12:13:05 +01:00
parent 740c2ca189
commit bcabe494e3
15 changed files with 1091 additions and 5 deletions

View file

@ -110,14 +110,12 @@ func convertDocument(w http.ResponseWriter, r *http.Request, job, folderID strin
// All the commented-out code below should be in following function call
newDocument, err := processDocument(p, filename, job, folderID, fileResult)
if err != nil {
writeServerError(w, method, err)
return
}
json, err := json.Marshal(newDocument)
if err != nil {
writeJSONMarshalError(w, method, "conversion", err)
return

View file

@ -20,6 +20,7 @@ import (
"fmt"
"github.com/documize/community/core/api/request"
"github.com/documize/community/core/api/util"
"github.com/documize/community/core/event"
)
// GetSMTPConfig returns installation-wide SMTP settings
@ -157,6 +158,8 @@ func SaveLicense(w http.ResponseWriter, r *http.Request) {
request.ConfigSet("EDITION-LICENSE", js)
event.Handler().Publish(string(event.TypeSystemLicenseChange))
util.WriteSuccessEmptyJSON(w)
}

View file

@ -28,6 +28,7 @@ import (
"github.com/documize/community/core/api/request"
"github.com/documize/community/core/api/util"
api "github.com/documize/community/core/convapi"
"github.com/documize/community/core/event"
"github.com/documize/community/core/log"
"github.com/documize/community/core/utility"
@ -389,7 +390,6 @@ func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) {
d.Title = docTitle
err = p.AddDocument(d)
if err != nil {
log.IfErr(tx.Rollback())
writeGeneralSQLError(w, method, err)
@ -455,14 +455,14 @@ func StartDocumentFromSavedTemplate(w http.ResponseWriter, r *http.Request) {
log.IfErr(tx.Commit())
newDocument, err := p.GetDocument(documentID)
if err != nil {
writeServerError(w, method, err)
return
}
data, err := json.Marshal(newDocument)
event.Handler().Publish(string(event.TypeAddDocument), newDocument.Title)
data, err := json.Marshal(newDocument)
if err != nil {
writeJSONMarshalError(w, method, "document", err)
return

View file

@ -28,6 +28,7 @@ import (
"github.com/documize/community/core/log"
"github.com/documize/community/core/utility"
"github.com/documize/community/core/event"
"github.com/gorilla/mux"
"strconv"
)
@ -174,6 +175,14 @@ func AddUser(w http.ResponseWriter, r *http.Request) {
inviter, err := p.GetUser(p.Context.UserID)
log.IfErr(err)
if addUser {
event.Handler().Publish(string(event.TypeAddUser))
}
if addAccount {
event.Handler().Publish(string(event.TypeAddAccount))
}
// Prepare invitation email (that contains SSO link)
if addUser && addAccount {
size := len(requestedPassword)
@ -386,6 +395,8 @@ func DeleteUser(w http.ResponseWriter, r *http.Request) {
log.IfErr(tx.Commit())
event.Handler().Publish(string(event.TypeRemoveUser))
writeSuccessString(w, "{}")
}

View file

@ -86,6 +86,23 @@ func (p *Persister) GetAccountsByOrg() (t []entity.Account, err error) {
return
}
// CountOrgAccounts returns the numnber of active user accounts for specified organization.
func (p *Persister) CountOrgAccounts() (c int) {
row := Db.QueryRow("SELECT count(*) FROM account WHERE orgid=? AND active=1", p.Context.OrgID)
err := row.Scan(&c)
if err != nil && err != sql.ErrNoRows {
log.Error(p.Base.SQLSelectError("CountOrgAccounts", p.Context.OrgID), err)
return 0
}
if err == sql.ErrNoRows {
return 0
}
return
}
// UpdateAccount updates the database record for the given account to the given values.
func (p *Persister) UpdateAccount(account entity.Account) (err error) {
account.Revised = time.Now().UTC()

View file

@ -301,3 +301,20 @@ func (p *Persister) ForgotUserPassword(email, token string) (err error) {
return
}
// CountActiveUsers returns the number of active users in the system.
func CountActiveUsers() (c int) {
row := Db.QueryRow("SELECT count(*) FROM user u WHERE u.refid IN (SELECT userid FROM account WHERE active=1)")
err := row.Scan(&c)
if err != nil && err != sql.ErrNoRows {
log.Error("CountActiveUsers", err)
return 0
}
if err == sql.ErrNoRows {
return 0
}
return
}