mirror of
https://github.com/documize/community.git
synced 2025-08-02 20:15:26 +02:00
Enable custom logo upload and rendering
This commit is contained in:
parent
a211ba051a
commit
036f36ba1d
36 changed files with 574 additions and 211 deletions
|
@ -46,7 +46,6 @@ import (
|
|||
"github.com/documize/community/model/doc"
|
||||
"github.com/documize/community/model/group"
|
||||
"github.com/documize/community/model/link"
|
||||
"github.com/documize/community/model/org"
|
||||
"github.com/documize/community/model/page"
|
||||
"github.com/documize/community/model/permission"
|
||||
"github.com/documize/community/model/pin"
|
||||
|
@ -231,14 +230,14 @@ func (b backerHandler) dmzOrg(files *[]backupItem) (err error) {
|
|||
w = fmt.Sprintf(" WHERE c_refid='%s' ", b.Spec.OrgID)
|
||||
}
|
||||
|
||||
o := []org.Organization{}
|
||||
o := []orgExtended{}
|
||||
err = b.Runtime.Db.Select(&o, `SELECT id, c_refid AS refid,
|
||||
c_title AS title, c_message AS message, c_domain AS domain,
|
||||
c_service AS conversionendpoint, c_email AS email, c_serial AS serial, c_active AS active,
|
||||
c_anonaccess AS allowanonymousaccess, c_authprovider AS authprovider,
|
||||
c_anonaccess AS allowanonymousaccess, c_authprovider AS authprovider,
|
||||
coalesce(c_sub,`+b.Runtime.StoreProvider.JSONEmpty()+`) AS subscription,
|
||||
coalesce(c_authconfig,`+b.Runtime.StoreProvider.JSONEmpty()+`) AS authconfig, c_maxtags AS maxtags,
|
||||
c_created AS created, c_revised AS revised
|
||||
c_theme AS theme, c_logo AS logo, c_created AS created, c_revised AS revised
|
||||
FROM dmz_org`+w)
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -255,10 +254,6 @@ func (b backerHandler) dmzOrg(files *[]backupItem) (err error) {
|
|||
|
||||
// Config, User Config.
|
||||
func (b backerHandler) dmzConfig(files *[]backupItem) (err error) {
|
||||
type config struct {
|
||||
ConfigKey string `json:"key"`
|
||||
ConfigValue string `json:"config"`
|
||||
}
|
||||
c := []config{}
|
||||
err = b.Runtime.Db.Select(&c, `SELECT c_key AS configkey, c_config AS configvalue FROM dmz_config`)
|
||||
if err != nil {
|
||||
|
@ -279,14 +274,7 @@ func (b backerHandler) dmzConfig(files *[]backupItem) (err error) {
|
|||
w = fmt.Sprintf(" where c_orgid='%s' ", b.Spec.OrgID)
|
||||
}
|
||||
|
||||
type userConfig struct {
|
||||
OrgID string `json:"orgId"`
|
||||
UserID string `json:"userId"`
|
||||
ConfigKey string `json:"key"`
|
||||
ConfigValue string `json:"config"`
|
||||
}
|
||||
uc := []userConfig{}
|
||||
|
||||
err = b.Runtime.Db.Select(&uc, `select c_orgid AS orgid, c_userid AS userid,
|
||||
c_key AS configkey, c_config AS configvalue FROM dmz_user_config`+w)
|
||||
if err != nil {
|
||||
|
@ -475,6 +463,8 @@ func (b backerHandler) dmzSpace(files *[]backupItem) (err error) {
|
|||
err = b.Runtime.Db.Select(&sp, `SELECT id, c_refid AS refid,
|
||||
c_name AS name, c_orgid AS orgid, c_userid AS userid,
|
||||
c_type AS type, c_lifecycle AS lifecycle, c_likes AS likes,
|
||||
c_icon AS icon, c_labelid AS labelid, c_desc AS description,
|
||||
c_count_category As countcategory, c_count_content AS countcontent,
|
||||
c_created AS created, c_revised AS revised
|
||||
FROM dmz_space`+w)
|
||||
if err != nil {
|
||||
|
@ -671,16 +661,6 @@ func (b backerHandler) dmzDocument(files *[]backupItem) (err error) {
|
|||
*files = append(*files, backupItem{Filename: "dmz_doc.json", Content: content})
|
||||
|
||||
// Vote
|
||||
type vote struct {
|
||||
RefID string `json:"refId"`
|
||||
OrgID string `json:"orgId"`
|
||||
DocumentID string `json:"documentId"`
|
||||
VoterID string `json:"voterId"`
|
||||
Vote int `json:"vote"`
|
||||
Created time.Time `json:"created"`
|
||||
Revised time.Time `json:"revised"`
|
||||
}
|
||||
|
||||
vt := []vote{}
|
||||
err = b.Runtime.Db.Select(&vt, `
|
||||
SELECT c_refid AS refid, c_orgid AS orgid,
|
||||
|
@ -716,16 +696,6 @@ func (b backerHandler) dmzDocument(files *[]backupItem) (err error) {
|
|||
*files = append(*files, backupItem{Filename: "dmz_doc_link.json", Content: content})
|
||||
|
||||
// Comment
|
||||
type comment struct {
|
||||
RefID string `json:"feedbackId"`
|
||||
OrgID string `json:"orgId"`
|
||||
DocumentID string `json:"documentId"`
|
||||
UserID string `json:"userId"`
|
||||
Email string `json:"email"`
|
||||
Feedback string `json:"feedback"`
|
||||
Created time.Time `json:"created"`
|
||||
}
|
||||
|
||||
cm := []comment{}
|
||||
err = b.Runtime.Db.Select(&cm, `
|
||||
SELECT c_refid AS refid, c_orgid AS orgid, c_docid AS documentid,
|
||||
|
@ -743,20 +713,6 @@ func (b backerHandler) dmzDocument(files *[]backupItem) (err error) {
|
|||
*files = append(*files, backupItem{Filename: "dmz_doc_comment.json", Content: content})
|
||||
|
||||
// Share
|
||||
type share struct {
|
||||
ID uint64 `json:"id"`
|
||||
OrgID string `json:"orgId"`
|
||||
UserID string `json:"userId"`
|
||||
DocumentID string `json:"documentId"`
|
||||
Email string `json:"email"`
|
||||
Message string `json:"message"`
|
||||
Viewed string `json:"viewed"` // recording each view as |date-viewed|date-viewed|
|
||||
Secret string `json:"secret"` // secure token used to access document
|
||||
Expires string `json:"expires"` // number of days from creation, value of 0 means never
|
||||
Active bool `json:"active"`
|
||||
Created time.Time `json:"created"`
|
||||
}
|
||||
|
||||
sh := []share{}
|
||||
err = b.Runtime.Db.Select(&sh, `
|
||||
SELECT id AS id, c_orgid AS orgid, c_docid AS documentid,
|
||||
|
|
78
domain/backup/models.go
Normal file
78
domain/backup/models.go
Normal file
|
@ -0,0 +1,78 @@
|
|||
// Copyright 2016 Documize Inc. <legal@documize.com>. All rights reserved.
|
||||
//
|
||||
// This software (Documize Community Edition) is licensed under
|
||||
// GNU AGPL v3 http://www.gnu.org/licenses/agpl-3.0.en.html
|
||||
//
|
||||
// You can operate outside the AGPL restrictions by purchasing
|
||||
// Documize Enterprise Edition and obtaining a commercial license
|
||||
// by contacting <sales@documize.com>.
|
||||
//
|
||||
// https://documize.com
|
||||
|
||||
// Package backup handle data backup/restore to/from ZIP format.
|
||||
package backup
|
||||
|
||||
// Existing data models do not necessarily have fields to hold
|
||||
// all data when loaded from the database.
|
||||
// So we extend the existing models to hold additional fields
|
||||
// for a complete backup and restore process.
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/documize/community/model/org"
|
||||
)
|
||||
|
||||
type orgExtended struct {
|
||||
org.Organization
|
||||
Logo []byte `json:"logo"`
|
||||
}
|
||||
|
||||
type config struct {
|
||||
ConfigKey string `json:"key"`
|
||||
ConfigValue string `json:"config"`
|
||||
}
|
||||
|
||||
type userConfig struct {
|
||||
OrgID string `json:"orgId"`
|
||||
UserID string `json:"userId"`
|
||||
ConfigKey string `json:"key"`
|
||||
ConfigValue string `json:"config"`
|
||||
}
|
||||
|
||||
// Vote
|
||||
type vote struct {
|
||||
RefID string `json:"refId"`
|
||||
OrgID string `json:"orgId"`
|
||||
DocumentID string `json:"documentId"`
|
||||
VoterID string `json:"voterId"`
|
||||
Vote int `json:"vote"`
|
||||
Created time.Time `json:"created"`
|
||||
Revised time.Time `json:"revised"`
|
||||
}
|
||||
|
||||
// Comment
|
||||
type comment struct {
|
||||
RefID string `json:"feedbackId"`
|
||||
OrgID string `json:"orgId"`
|
||||
DocumentID string `json:"documentId"`
|
||||
UserID string `json:"userId"`
|
||||
Email string `json:"email"`
|
||||
Feedback string `json:"feedback"`
|
||||
Created time.Time `json:"created"`
|
||||
}
|
||||
|
||||
// Share
|
||||
type share struct {
|
||||
ID uint64 `json:"id"`
|
||||
OrgID string `json:"orgId"`
|
||||
UserID string `json:"userId"`
|
||||
DocumentID string `json:"documentId"`
|
||||
Email string `json:"email"`
|
||||
Message string `json:"message"`
|
||||
Viewed string `json:"viewed"` // recording each view as |date-viewed|date-viewed|
|
||||
Secret string `json:"secret"` // secure token used to access document
|
||||
Expires string `json:"expires"` // number of days from creation, value of 0 means never
|
||||
Active bool `json:"active"`
|
||||
Created time.Time `json:"created"`
|
||||
}
|
|
@ -39,7 +39,6 @@ import (
|
|||
"github.com/documize/community/model/doc"
|
||||
"github.com/documize/community/model/group"
|
||||
"github.com/documize/community/model/link"
|
||||
"github.com/documize/community/model/org"
|
||||
"github.com/documize/community/model/page"
|
||||
"github.com/documize/community/model/permission"
|
||||
"github.com/documize/community/model/pin"
|
||||
|
@ -332,7 +331,7 @@ func (r *restoreHandler) readZip(filename string) (found bool, b []byte, err err
|
|||
func (r *restoreHandler) dmzOrg() (err error) {
|
||||
filename := "dmz_org.json"
|
||||
|
||||
org := []org.Organization{}
|
||||
org := []orgExtended{}
|
||||
err = r.fileJSON(filename, &org)
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("failed to load %s", filename))
|
||||
|
@ -363,12 +362,14 @@ func (r *restoreHandler) dmzOrg() (err error) {
|
|||
_, err = r.Context.Transaction.Exec(r.Runtime.Db.Rebind(`
|
||||
INSERT INTO dmz_org (c_refid, c_company, c_title, c_message,
|
||||
c_domain, c_service, c_email, c_anonaccess, c_authprovider, c_authconfig,
|
||||
c_maxtags, c_verified, c_serial, c_sub, c_active, c_created, c_revised)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
|
||||
c_maxtags, c_verified, c_serial, c_sub, c_active,
|
||||
c_theme, c_logo, c_created, c_revised)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
|
||||
org[i].RefID, org[i].Company, org[i].Title, org[i].Message,
|
||||
strings.ToLower(org[i].Domain), org[i].ConversionEndpoint, strings.ToLower(org[i].Email),
|
||||
org[i].AllowAnonymousAccess, org[i].AuthProvider, org[i].AuthConfig,
|
||||
org[i].MaxTags, true, org[i].Serial, org[i].Subscription,
|
||||
org[i].Theme, org[i].Logo,
|
||||
org[i].Active, org[i].Created, org[i].Revised)
|
||||
if err != nil {
|
||||
r.Context.Transaction.Rollback()
|
||||
|
@ -402,6 +403,7 @@ func (r *restoreHandler) dmzOrg() (err error) {
|
|||
org[0].Serial = r.Spec.Org.Serial
|
||||
org[0].Title = r.Spec.Org.Title
|
||||
org[0].Subscription = r.Spec.Org.Subscription
|
||||
org[0].Theme = r.Spec.Org.Theme
|
||||
}
|
||||
|
||||
_, err = r.Context.Transaction.NamedExec(`UPDATE dmz_org SET
|
||||
|
@ -612,8 +614,16 @@ func (r *restoreHandler) dmzSpace() (err error) {
|
|||
}
|
||||
|
||||
for i := range sp {
|
||||
_, err = r.Context.Transaction.Exec(r.Runtime.Db.Rebind("INSERT INTO dmz_space (c_refid, c_name, c_orgid, c_userid, c_type, c_lifecycle, c_likes, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
||||
sp[i].RefID, sp[i].Name, r.remapOrg(sp[i].OrgID), r.remapUser(sp[i].UserID), sp[i].Type, sp[i].Lifecycle, sp[i].Likes, sp[i].Created, sp[i].Revised)
|
||||
_, err = r.Context.Transaction.Exec(r.Runtime.Db.Rebind(`
|
||||
INSERT INTO dmz_space
|
||||
(c_refid, c_name, c_orgid, c_userid, c_type, c_lifecycle,
|
||||
c_likes, c_icon, c_desc, c_count_category, c_count_content,
|
||||
c_labelid, c_created, c_revised)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
|
||||
sp[i].RefID, sp[i].Name, r.remapOrg(sp[i].OrgID),
|
||||
r.remapUser(sp[i].UserID), sp[i].Type, sp[i].Lifecycle,
|
||||
sp[i].Likes, sp[i].Icon, sp[i].Description, sp[i].CountCategory,
|
||||
sp[i].CountContent, sp[i].LabelID, sp[i].Created, sp[i].Revised)
|
||||
|
||||
if err != nil {
|
||||
r.Context.Transaction.Rollback()
|
||||
|
|
|
@ -13,6 +13,7 @@ package meta
|
|||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
@ -301,3 +302,41 @@ func (h *Handler) Themes(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
response.WriteJSON(w, th)
|
||||
}
|
||||
|
||||
// Logo returns site logo based upon request domain (e.g. acme.documize.com).
|
||||
// The default Documize logo is returned if organization has not uploaded
|
||||
// their own logo.
|
||||
func (h *Handler) Logo(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := domain.GetRequestContext(r)
|
||||
d := organization.GetSubdomainFromHost(r)
|
||||
|
||||
logo, err := h.Store.Organization.Logo(ctx, d)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Infof("unable to fetch logo for domain %s", d)
|
||||
response.WriteNotFound(w)
|
||||
return
|
||||
}
|
||||
|
||||
if len(string(logo)) == 0 {
|
||||
logo, err = base64.StdEncoding.DecodeString(defaultLogo)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("unable to decode default logo", err)
|
||||
response.WriteEmpty(w)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/octet-stream")
|
||||
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(logo)))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
_, err = w.Write(logo)
|
||||
if err != nil {
|
||||
h.Runtime.Log.Error("failed to write org logo", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
var defaultLogo = `
|
||||
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
|
||||
`
|
||||
|
|
|
@ -12,8 +12,11 @@
|
|||
package organization
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"github.com/documize/community/model/audit"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
|
||||
|
@ -99,3 +102,50 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
response.WriteJSON(w, org)
|
||||
}
|
||||
|
||||
// UploadLogo stores log for organization.
|
||||
func (h *Handler) UploadLogo(w http.ResponseWriter, r *http.Request) {
|
||||
method := "organization.UploadLogo"
|
||||
ctx := domain.GetRequestContext(r)
|
||||
|
||||
if !ctx.Administrator {
|
||||
response.WriteForbiddenError(w)
|
||||
return
|
||||
}
|
||||
|
||||
// We use default logo if body is empty.
|
||||
logo := []byte{}
|
||||
|
||||
filedata, _, err := r.FormFile("attachment")
|
||||
if err == nil {
|
||||
b := new(bytes.Buffer)
|
||||
_, err = io.Copy(b, filedata)
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
} else {
|
||||
logo = b.Bytes()
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||
if err != nil {
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = h.Store.Organization.UploadLogo(ctx, logo)
|
||||
if err != nil {
|
||||
ctx.Transaction.Rollback()
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Log.Error(method, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Transaction.Commit()
|
||||
|
||||
h.Store.Audit.Record(ctx, audit.EventTypeOrganizationLogo)
|
||||
|
||||
response.WriteEmpty(w)
|
||||
}
|
||||
|
|
|
@ -52,7 +52,7 @@ func (s Store) GetOrganization(ctx domain.RequestContext, id string) (org org.Or
|
|||
c_anonaccess AS allowanonymousaccess, c_authprovider AS authprovider,
|
||||
coalesce(c_authconfig,`+s.EmptyJSON()+`) AS authconfig,
|
||||
coalesce(c_sub,`+s.EmptyJSON()+`) AS subscription,
|
||||
c_maxtags AS maxtags, c_created AS created, c_revised AS revised, c_theme AS theme
|
||||
c_maxtags AS maxtags, c_theme AS theme, c_created AS created, c_revised AS revised
|
||||
FROM dmz_org
|
||||
WHERE c_refid=?`),
|
||||
id)
|
||||
|
@ -176,3 +176,31 @@ func (s Store) CheckDomain(ctx domain.RequestContext, domain string) string {
|
|||
|
||||
return ""
|
||||
}
|
||||
|
||||
// Logo fetchs stored image from store or NULL.
|
||||
func (s Store) Logo(ctx domain.RequestContext, domain string) (l []byte, err error) {
|
||||
row := s.Runtime.Db.QueryRow(s.Bind("SELECT c_logo FROM dmz_org WHERE c_domain=? AND c_active=true"), domain)
|
||||
|
||||
err = row.Scan(&l)
|
||||
if err == sql.ErrNoRows {
|
||||
err = nil
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return l, nil
|
||||
}
|
||||
|
||||
// UploadLogo saves custom logo to the organization record.
|
||||
func (s Store) UploadLogo(ctx domain.RequestContext, logo []byte) (err error) {
|
||||
_, err = ctx.Transaction.Exec(s.Bind("UPDATE dmz_org SET c_logo=?, c_revised=? WHERE c_refid=?"),
|
||||
logo, time.Now().UTC(), ctx.OrgID)
|
||||
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("unable to save custom logo for org %s", ctx.OrgID))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
@ -99,6 +99,9 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
var sp space.Space
|
||||
sp.Name = model.Name
|
||||
sp.Description = model.Description
|
||||
sp.Icon = model.Icon
|
||||
sp.LabelID = model.LabelID
|
||||
sp.RefID = uniqueid.Generate()
|
||||
sp.OrgID = ctx.OrgID
|
||||
sp.UserID = ctx.UserID
|
||||
|
@ -675,52 +678,52 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
ok := true
|
||||
ctx.Transaction, ok = h.Runtime.StartTx()
|
||||
if !ok {
|
||||
if !ok {
|
||||
response.WriteError(w, method)
|
||||
return
|
||||
}
|
||||
|
||||
_, err := h.Store.Document.DeleteBySpace(ctx, id)
|
||||
if err != nil {
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = h.Store.Permission.DeleteSpacePermissions(ctx, id)
|
||||
if err != nil {
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
// remove category permissions
|
||||
_, err = h.Store.Permission.DeleteSpaceCategoryPermissions(ctx, id)
|
||||
if err != nil {
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = h.Store.Pin.DeletePinnedSpace(ctx, id)
|
||||
if err != nil && err != sql.ErrNoRows {
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
// remove category and members for space
|
||||
_, err = h.Store.Category.DeleteBySpace(ctx, id)
|
||||
if err != nil {
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
_, err = h.Store.Space.Delete(ctx, id)
|
||||
if err != nil {
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
response.WriteServerError(w, method, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -728,22 +731,22 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
|||
h.Runtime.Commit(ctx.Transaction)
|
||||
|
||||
// Record this action.
|
||||
ctx.Transaction, ok = h.Runtime.StartTx()
|
||||
if !ok {
|
||||
response.WriteError(w, method)
|
||||
return
|
||||
}
|
||||
ctx.Transaction, ok = h.Runtime.StartTx()
|
||||
if !ok {
|
||||
response.WriteError(w, method)
|
||||
return
|
||||
}
|
||||
|
||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||
SpaceID: id,
|
||||
SourceType: activity.SourceTypeSpace,
|
||||
ActivityType: activity.TypeDeleted})
|
||||
if err != nil {
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
response.WriteServerError(w, method, err)
|
||||
h.Runtime.Rollback(ctx.Transaction)
|
||||
response.WriteServerError(w, method, err)
|
||||
}
|
||||
|
||||
h.Runtime.Commit(ctx.Transaction)
|
||||
h.Runtime.Commit(ctx.Transaction)
|
||||
|
||||
h.Store.Audit.Record(ctx, audit.EventTypeSpaceDelete)
|
||||
|
||||
|
|
|
@ -30,7 +30,12 @@ type Store struct {
|
|||
|
||||
// Add adds new folder into the store.
|
||||
func (s Store) Add(ctx domain.RequestContext, sp space.Space) (err error) {
|
||||
_, err = ctx.Transaction.Exec(s.Bind("INSERT INTO dmz_space (c_refid, c_name, c_orgid, c_userid, c_type, c_lifecycle, c_likes, c_icon, c_desc, c_count_category, c_count_content, c_labelid, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"),
|
||||
_, err = ctx.Transaction.Exec(s.Bind(`
|
||||
INSERT INTO dmz_space
|
||||
(c_refid, c_name, c_orgid, c_userid, c_type, c_lifecycle,
|
||||
c_likes, c_icon, c_desc, c_count_category, c_count_content,
|
||||
c_labelid, c_created, c_revised)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
|
||||
sp.RefID, sp.Name, sp.OrgID, sp.UserID, sp.Type, sp.Lifecycle, sp.Likes,
|
||||
sp.Icon, sp.Description, sp.CountCategory, sp.CountContent, sp.LabelID,
|
||||
sp.Created, sp.Revised)
|
||||
|
|
|
@ -154,6 +154,8 @@ type OrganizationStorer interface {
|
|||
RemoveOrganization(ctx domain.RequestContext, orgID string) (err error)
|
||||
UpdateAuthConfig(ctx domain.RequestContext, org org.Organization) (err error)
|
||||
CheckDomain(ctx domain.RequestContext, domain string) string
|
||||
Logo(ctx domain.RequestContext, domain string) (l []byte, err error)
|
||||
UploadLogo(ctx domain.RequestContext, l []byte) (err error)
|
||||
}
|
||||
|
||||
// PinStorer defines required methods for pin management
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue