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

Provider sample data for Cloud onboarding

This commit is contained in:
sauls8t 2019-06-29 15:37:49 +01:00
parent 201d2a339c
commit 69077ce419
7 changed files with 1201 additions and 1100 deletions

View file

@ -13,6 +13,8 @@ package meta
import ( import (
"database/sql" "database/sql"
"fmt"
"github.com/documize/community/model/doc" "github.com/documize/community/model/doc"
"github.com/documize/community/domain" "github.com/documize/community/domain"
@ -29,9 +31,14 @@ type Store struct {
} }
// Documents returns every document ID value stored. // Documents returns every document ID value stored.
// The query runs at the instance level across all tenants. // For global admins, the query runs at the instance level across all tenants.
// For tenant admins, the query is restricted to the tenant.
func (s Store) Documents(ctx domain.RequestContext) (documents []string, err error) { func (s Store) Documents(ctx domain.RequestContext) (documents []string, err error) {
err = s.Runtime.Db.Select(&documents, `SELECT c_refid FROM dmz_doc WHERE c_lifecycle=1`) qry := "SELECT c_refid FROM dmz_doc WHERE c_lifecycle=1"
if !ctx.GlobalAdmin {
qry = fmt.Sprintf("%s AND c_orgid='%s'", qry, ctx.OrgID)
}
err = s.Runtime.Db.Select(&documents, qry)
if err == sql.ErrNoRows { if err == sql.ErrNoRows {
err = nil err = nil

View file

@ -22,6 +22,7 @@ import (
"github.com/documize/community/core/env" "github.com/documize/community/core/env"
"github.com/documize/community/core/response" "github.com/documize/community/core/response"
"github.com/documize/community/core/uniqueid"
"github.com/documize/community/domain" "github.com/documize/community/domain"
indexer "github.com/documize/community/domain/search" indexer "github.com/documize/community/domain/search"
"github.com/documize/community/domain/store" "github.com/documize/community/domain/store"
@ -32,9 +33,10 @@ import (
// Handler contains the runtime information such as logging and database. // Handler contains the runtime information such as logging and database.
type Handler struct { type Handler struct {
Runtime *env.Runtime Runtime *env.Runtime
Store *store.Store Store *store.Store
Indexer indexer.Indexer Indexer indexer.Indexer
MappedID map[string]string
} }
// InstallSample inserts sample data into database. // InstallSample inserts sample data into database.
@ -46,14 +48,15 @@ func (h *Handler) InstallSample(w http.ResponseWriter, r *http.Request) {
response.WriteBadLicense(w) response.WriteBadLicense(w)
return return
} }
if !ctx.Administrator || !ctx.Authenticated || !ctx.GlobalAdmin {
if !ctx.Administrator {
response.WriteForbiddenError(w) response.WriteForbiddenError(w)
return return
} }
// Only proceed if we have no spaces and documents. // Only proceed if we have no spaces and documents.
// This prevents sample data restore inside existing live instance. // This prevents sample data restore inside existing live instance.
spaces, docs := h.Store.Onboard.ContentCounts() spaces, docs := h.Store.Onboard.ContentCounts(ctx.OrgID)
if spaces > 0 || docs > 0 { if spaces > 0 || docs > 0 {
h.Runtime.Log.Info("Unable to install sample data when database contains spaces/docs") h.Runtime.Log.Info("Unable to install sample data when database contains spaces/docs")
response.WriteForbiddenError(w) response.WriteForbiddenError(w)
@ -126,19 +129,39 @@ func (h *Handler) unpackFile(filename string, v interface{}) (err error) {
return nil return nil
} }
// Returns new ID based on old ID.
func (h *Handler) getMappedID(table, old string) string {
// Return mapped ID if we have one.
key := table + "_" + old
if n, ok := h.MappedID[key]; ok {
return n
}
// Generate new ID and send back.
newID := uniqueid.Generate()
h.MappedID[table+"_"+old] = newID
return newID
}
// Insert data into database using sample data loaded from embedded assets. // Insert data into database using sample data loaded from embedded assets.
func (h *Handler) processSampleData(data om.SampleData) (err error) { func (h *Handler) processSampleData(data om.SampleData) (err error) {
data.Context.Transaction, _ = h.Runtime.StartTx(sql.LevelReadUncommitted) data.Context.Transaction, _ = h.Runtime.StartTx(sql.LevelReadUncommitted)
h.MappedID = make(map[string]string)
// Space Label. // Space Label.
h.Runtime.Log.Info(fmt.Sprintf("Installing space label (%d)", len(data.SpaceLabel))) h.Runtime.Log.Info(fmt.Sprintf("Installing (%d) space labels", len(data.SpaceLabel)))
for i := range data.SpaceLabel { for i := range data.SpaceLabel {
_, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(` _, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(`
INSERT INTO dmz_space_label INSERT INTO dmz_space_label
(c_refid, c_orgid, c_name, c_color, c_created, c_revised) (c_refid, c_orgid, c_name, c_color, c_created, c_revised)
VALUES (?, ?, ?, ?, ?, ?)`), VALUES (?, ?, ?, ?, ?, ?)`),
data.SpaceLabel[i].RefID, data.Context.OrgID, data.SpaceLabel[i].Name, h.getMappedID("label", data.SpaceLabel[i].RefID),
data.SpaceLabel[i].Color, data.SpaceLabel[i].Created, data.SpaceLabel[i].Revised) data.Context.OrgID,
data.SpaceLabel[i].Name,
data.SpaceLabel[i].Color,
data.SpaceLabel[i].Created,
data.SpaceLabel[i].Revised)
if err != nil { if err != nil {
h.Runtime.Rollback(data.Context.Transaction) h.Runtime.Rollback(data.Context.Transaction)
@ -148,7 +171,7 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
} }
// Space. // Space.
h.Runtime.Log.Info(fmt.Sprintf("Installing space (%d)", len(data.Space))) h.Runtime.Log.Info(fmt.Sprintf("Installing (%d) spaces", len(data.Space)))
for i := range data.Space { for i := range data.Space {
_, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(` _, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(`
INSERT INTO dmz_space INSERT INTO dmz_space
@ -156,11 +179,19 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
c_likes, c_icon, c_desc, c_count_category, c_count_content, c_likes, c_icon, c_desc, c_count_category, c_count_content,
c_labelid, c_created, c_revised) c_labelid, c_created, c_revised)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`), VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
data.Space[i].RefID, data.Space[i].Name, data.Context.OrgID, h.getMappedID("space", data.Space[i].RefID),
data.Context.UserID, data.Space[i].Type, data.Space[i].Lifecycle, data.Space[i].Name,
data.Space[i].Likes, data.Space[i].Icon, data.Space[i].Description, data.Context.OrgID,
data.Space[i].CountCategory, data.Space[i].CountContent, data.Context.UserID,
data.Space[i].LabelID, data.Space[i].Created, data.Space[i].Revised) data.Space[i].Type,
data.Space[i].Lifecycle,
data.Space[i].Likes,
data.Space[i].Icon,
data.Space[i].Description,
data.Space[i].CountCategory,
data.Space[i].CountContent,
h.getMappedID("label", data.Space[i].LabelID),
data.Space[i].Created, data.Space[i].Revised)
if err != nil { if err != nil {
h.Runtime.Rollback(data.Context.Transaction) h.Runtime.Rollback(data.Context.Transaction)
@ -169,13 +200,18 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
} }
} }
h.Runtime.Log.Info(fmt.Sprintf("Installing category (%d)", len(data.Category))) // Category.
h.Runtime.Log.Info(fmt.Sprintf("Installing (%d) categories", len(data.Category)))
for i := range data.Category { for i := range data.Category {
_, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(` _, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(`
INSERT INTO dmz_category (c_refid, c_orgid, c_spaceid, c_name, c_created, c_revised) INSERT INTO dmz_category (c_refid, c_orgid, c_spaceid, c_name, c_created, c_revised)
VALUES (?, ?, ?, ?, ?, ?)`), VALUES (?, ?, ?, ?, ?, ?)`),
data.Category[i].RefID, data.Context.OrgID, data.Category[i].SpaceID, data.Category[i].Name, h.getMappedID("category", data.Category[i].RefID),
data.Category[i].Created, data.Category[i].Revised) data.Context.OrgID,
h.getMappedID("space", data.Category[i].SpaceID),
data.Category[i].Name,
data.Category[i].Created,
data.Category[i].Revised)
if err != nil { if err != nil {
h.Runtime.Rollback(data.Context.Transaction) h.Runtime.Rollback(data.Context.Transaction)
@ -184,15 +220,20 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
} }
} }
// Category Member.
h.Runtime.Log.Info(fmt.Sprintf("Installing category member (%d)", len(data.CategoryMember))) h.Runtime.Log.Info(fmt.Sprintf("Installing category member (%d)", len(data.CategoryMember)))
for i := range data.CategoryMember { for i := range data.CategoryMember {
_, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(` _, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(`
INSERT INTO dmz_category_member INSERT INTO dmz_category_member
(c_refid, c_orgid, c_categoryid, c_spaceid, c_docid, c_created, c_revised) (c_refid, c_orgid, c_categoryid, c_spaceid, c_docid, c_created, c_revised)
VALUES (?, ?, ?, ?, ?, ?, ?)`), VALUES (?, ?, ?, ?, ?, ?, ?)`),
data.CategoryMember[i].RefID, data.Context.OrgID, data.CategoryMember[i].CategoryID, h.getMappedID("category_member", data.CategoryMember[i].RefID),
data.CategoryMember[i].SpaceID, data.CategoryMember[i].DocumentID, data.Context.OrgID,
data.CategoryMember[i].Created, data.CategoryMember[i].Revised) h.getMappedID("category", data.CategoryMember[i].CategoryID),
h.getMappedID("space", data.CategoryMember[i].SpaceID),
h.getMappedID("document", data.CategoryMember[i].DocumentID),
data.CategoryMember[i].Created,
data.CategoryMember[i].Revised)
if err != nil { if err != nil {
h.Runtime.Rollback(data.Context.Transaction) h.Runtime.Rollback(data.Context.Transaction)
@ -210,7 +251,7 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
perm.Location = permission.LocationSpace perm.Location = permission.LocationSpace
for i := range data.Space { for i := range data.Space {
perm.RefID = data.Space[i].RefID perm.RefID = h.getMappedID("space", data.Space[i].RefID)
perm.Action = "" // we send array for actions below perm.Action = "" // we send array for actions below
err = h.Store.Permission.AddPermissions(data.Context, perm, err = h.Store.Permission.AddPermissions(data.Context, perm,
@ -235,7 +276,7 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
pc.WhoID = data.Context.UserID pc.WhoID = data.Context.UserID
pc.Scope = permission.ScopeRow pc.Scope = permission.ScopeRow
pc.Location = permission.LocationCategory pc.Location = permission.LocationCategory
pc.RefID = data.Category[i].RefID pc.RefID = h.getMappedID("category", data.Category[i].RefID)
pc.Action = permission.CategoryView pc.Action = permission.CategoryView
err = h.Store.Permission.AddPermission(data.Context, pc) err = h.Store.Permission.AddPermission(data.Context, pc)
@ -246,6 +287,7 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
} }
} }
// Document.
h.Runtime.Log.Info(fmt.Sprintf("Installing document (%d)", len(data.Document))) h.Runtime.Log.Info(fmt.Sprintf("Installing document (%d)", len(data.Document)))
for i := range data.Document { for i := range data.Document {
_, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(` _, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(`
@ -254,15 +296,26 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
c_name, c_desc, c_slug, c_tags, c_template, c_protection, c_approval, c_name, c_desc, c_slug, c_tags, c_template, c_protection, c_approval,
c_lifecycle, c_versioned, c_versionid, c_versionorder, c_groupid, c_created, c_revised) c_lifecycle, c_versioned, c_versionid, c_versionorder, c_groupid, c_created, c_revised)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`), VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
data.Document[i].RefID, data.Context.OrgID, data.Document[i].SpaceID, h.getMappedID("document", data.Document[i].RefID),
data.Context.UserID, data.Document[i].Job, data.Context.OrgID,
data.Document[i].Location, data.Document[i].Name, data.Document[i].Excerpt, h.getMappedID("space", data.Document[i].SpaceID),
data.Document[i].Slug, data.Document[i].Tags, data.Context.UserID,
data.Document[i].Template, data.Document[i].Protection, data.Document[i].Job,
data.Document[i].Approval, data.Document[i].Lifecycle, data.Document[i].Location,
data.Document[i].Versioned, data.Document[i].VersionID, data.Document[i].Name,
data.Document[i].VersionOrder, data.Document[i].GroupID, data.Document[i].Excerpt,
data.Document[i].Created, data.Document[i].Revised) data.Document[i].Slug,
data.Document[i].Tags,
data.Document[i].Template,
data.Document[i].Protection,
data.Document[i].Approval,
data.Document[i].Lifecycle,
data.Document[i].Versioned,
data.Document[i].VersionID,
data.Document[i].VersionOrder,
data.Document[i].GroupID,
data.Document[i].Created,
data.Document[i].Revised)
if err != nil { if err != nil {
h.Runtime.Rollback(data.Context.Transaction) h.Runtime.Rollback(data.Context.Transaction)
@ -271,6 +324,7 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
} }
} }
// Document Attachment.
h.Runtime.Log.Info(fmt.Sprintf("Installing document attachment (%d)", len(data.DocumentAttachment))) h.Runtime.Log.Info(fmt.Sprintf("Installing document attachment (%d)", len(data.DocumentAttachment)))
for i := range data.DocumentAttachment { for i := range data.DocumentAttachment {
_, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(` _, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(`
@ -278,12 +332,17 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
(c_refid, c_orgid, c_docid, c_sectionid, c_job, c_fileid, (c_refid, c_orgid, c_docid, c_sectionid, c_job, c_fileid,
c_filename, c_data, c_extension, c_created, c_revised) c_filename, c_data, c_extension, c_created, c_revised)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`), VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
data.DocumentAttachment[i].RefID, data.Context.OrgID, h.getMappedID("document_attachment", data.DocumentAttachment[i].RefID),
data.DocumentAttachment[i].DocumentID, data.DocumentAttachment[i].SectionID, data.Context.OrgID,
data.DocumentAttachment[i].Job, data.DocumentAttachment[i].FileID, h.getMappedID("document", data.DocumentAttachment[i].DocumentID),
h.getMappedID("section", data.DocumentAttachment[i].SectionID),
data.DocumentAttachment[i].Job,
data.DocumentAttachment[i].FileID,
data.DocumentAttachment[i].Filename, data.DocumentAttachment[i].Filename,
data.DocumentAttachment[i].Data, data.DocumentAttachment[i].Extension, data.DocumentAttachment[i].Data,
data.DocumentAttachment[i].Created, data.DocumentAttachment[i].Revised) data.DocumentAttachment[i].Extension,
data.DocumentAttachment[i].Created,
data.DocumentAttachment[i].Revised)
if err != nil { if err != nil {
h.Runtime.Rollback(data.Context.Transaction) h.Runtime.Rollback(data.Context.Transaction)
@ -292,18 +351,36 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
} }
} }
// Document Link.
h.Runtime.Log.Info(fmt.Sprintf("Installing document link (%d)", len(data.DocumentLink))) h.Runtime.Log.Info(fmt.Sprintf("Installing document link (%d)", len(data.DocumentLink)))
for i := range data.DocumentLink { for i := range data.DocumentLink {
targetID := ""
if data.DocumentLink[i].LinkType == "file" {
targetID = h.getMappedID("document_attachment", data.DocumentLink[i].TargetID)
} else if data.DocumentLink[i].LinkType == "document" {
targetID = h.getMappedID("document", data.DocumentLink[i].TargetID)
} else {
targetID = h.getMappedID("section", data.DocumentLink[i].TargetID)
}
_, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(` _, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(`
INSERT INTO dmz_doc_link INSERT INTO dmz_doc_link
(c_refid, c_orgid, c_spaceid, c_userid, c_sourcedocid, c_sourcesectionid, (c_refid, c_orgid, c_spaceid, c_userid, c_sourcedocid, c_sourcesectionid,
c_targetdocid, c_targetid, c_externalid, c_type, c_orphan, c_created, c_revised) c_targetdocid, c_targetid, c_externalid, c_type, c_orphan, c_created, c_revised)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`), VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
data.DocumentLink[i].RefID, data.Context.OrgID, data.DocumentLink[i].SpaceID, h.getMappedID("document_link", data.DocumentLink[i].RefID),
data.Context.UserID, data.DocumentLink[i].SourceDocumentID, data.DocumentLink[i].SourceSectionID, data.Context.OrgID,
data.DocumentLink[i].TargetDocumentID, data.DocumentLink[i].TargetID, data.DocumentLink[i].ExternalID, h.getMappedID("space", data.DocumentLink[i].SpaceID),
data.DocumentLink[i].LinkType, data.DocumentLink[i].Orphan, data.Context.UserID,
data.DocumentLink[i].Created, data.DocumentLink[i].Revised) h.getMappedID("document", data.DocumentLink[i].SourceDocumentID),
h.getMappedID("section", data.DocumentLink[i].SourceSectionID),
h.getMappedID("document", data.DocumentLink[i].TargetDocumentID),
targetID,
data.DocumentLink[i].ExternalID,
data.DocumentLink[i].LinkType,
data.DocumentLink[i].Orphan,
data.DocumentLink[i].Created,
data.DocumentLink[i].Revised)
if err != nil { if err != nil {
h.Runtime.Rollback(data.Context.Transaction) h.Runtime.Rollback(data.Context.Transaction)
@ -312,6 +389,7 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
} }
} }
// Document Section.
h.Runtime.Log.Info(fmt.Sprintf("Installing section (%d)", len(data.Section))) h.Runtime.Log.Info(fmt.Sprintf("Installing section (%d)", len(data.Section)))
for i := range data.Section { for i := range data.Section {
_, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(` _, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(`
@ -319,14 +397,22 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
(c_refid, c_orgid, c_docid, c_userid, c_contenttype, c_type, c_level, c_name, c_body, (c_refid, c_orgid, c_docid, c_userid, c_contenttype, c_type, c_level, c_name, c_body,
c_revisions, c_sequence, c_templateid, c_status, c_relativeid, c_created, c_revised) c_revisions, c_sequence, c_templateid, c_status, c_relativeid, c_created, c_revised)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`), VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`),
data.Section[i].RefID, data.Context.OrgID, data.Section[i].DocumentID, h.getMappedID("section", data.Section[i].RefID),
data.Context.OrgID,
h.getMappedID("document", data.Section[i].DocumentID),
data.Context.UserID, data.Context.UserID,
data.Section[i].ContentType, data.Section[i].Type, data.Section[i].ContentType,
data.Section[i].Level, data.Section[i].Name, data.Section[i].Type,
data.Section[i].Body, data.Section[i].Revisions, data.Section[i].Level,
data.Section[i].Sequence, data.Section[i].TemplateID, data.Section[i].Name,
data.Section[i].Status, data.Section[i].RelativeID, data.Section[i].Body,
data.Section[i].Created, data.Section[i].Revised) data.Section[i].Revisions,
data.Section[i].Sequence,
h.getMappedID("section", data.Section[i].TemplateID),
data.Section[i].Status,
h.getMappedID("section", data.Section[i].RelativeID),
data.Section[i].Created,
data.Section[i].Revised)
if err != nil { if err != nil {
h.Runtime.Rollback(data.Context.Transaction) h.Runtime.Rollback(data.Context.Transaction)
@ -335,6 +421,7 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
} }
} }
// Document Section Meta.
h.Runtime.Log.Info(fmt.Sprintf("Installing section meta (%d)", len(data.SectionMeta))) h.Runtime.Log.Info(fmt.Sprintf("Installing section meta (%d)", len(data.SectionMeta)))
for i := range data.SectionMeta { for i := range data.SectionMeta {
_, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(` _, err = data.Context.Transaction.Exec(h.Runtime.Db.Rebind(`
@ -342,11 +429,15 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
(c_sectionid, c_orgid, c_userid, c_docid, c_rawbody, (c_sectionid, c_orgid, c_userid, c_docid, c_rawbody,
c_config, c_external, c_created, c_revised) c_config, c_external, c_created, c_revised)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`), VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)`),
data.SectionMeta[i].SectionID, data.Context.OrgID, data.Context.UserID, h.getMappedID("section", data.SectionMeta[i].SectionID),
data.SectionMeta[i].DocumentID, data.Context.OrgID,
data.SectionMeta[i].RawBody, data.SectionMeta[i].Config, data.Context.UserID,
h.getMappedID("document", data.SectionMeta[i].DocumentID),
data.SectionMeta[i].RawBody,
data.SectionMeta[i].Config,
data.SectionMeta[i].ExternalSource, data.SectionMeta[i].ExternalSource,
data.SectionMeta[i].Created, data.SectionMeta[i].Revised) data.SectionMeta[i].Created,
data.SectionMeta[i].Revised)
if err != nil { if err != nil {
h.Runtime.Rollback(data.Context.Transaction) h.Runtime.Rollback(data.Context.Transaction)
@ -361,7 +452,5 @@ func (h *Handler) processSampleData(data om.SampleData) (err error) {
return return
} }
// Build search index
return nil return nil
} }

View file

@ -22,7 +22,7 @@ type Store struct {
} }
// ContentCounts returns the number of spaces and documents. // ContentCounts returns the number of spaces and documents.
func (s Store) ContentCounts() (spaces, docs int) { func (s Store) ContentCounts(orgID string) (spaces, docs int) {
// By default we assume there is content in case of error condition. // By default we assume there is content in case of error condition.
spaces = 10 spaces = 10
docs = 10 docs = 10
@ -30,16 +30,20 @@ func (s Store) ContentCounts() (spaces, docs int) {
var m int var m int
var err error var err error
row := s.Runtime.Db.QueryRow("SELECT COUNT(*) FROM dmz_space") row := s.Runtime.Db.QueryRow(s.Bind("SELECT COUNT(*) FROM dmz_space WHERE c_orgid=?"), orgID)
err = row.Scan(&m) err = row.Scan(&m)
if err == nil { if err == nil {
spaces = m spaces = m
} else {
s.Runtime.Log.Error("onboard.ContentCounts", err)
} }
row = s.Runtime.Db.QueryRow("SELECT COUNT(*) FROM dmz_doc") row = s.Runtime.Db.QueryRow(s.Bind("SELECT COUNT(*) FROM dmz_doc WHERE c_orgid=?"), orgID)
err = row.Scan(&m) err = row.Scan(&m)
if err == nil { if err == nil {
docs = m docs = m
} else {
s.Runtime.Log.Error("onboard.ContentCounts", err)
} }
return return

View file

@ -53,7 +53,7 @@ type Store struct {
Setting SettingStorer Setting SettingStorer
Space SpaceStorer Space SpaceStorer
User UserStorer User UserStorer
Onboard OnboardStorer Onboard OnboardStorer
} }
// SpaceStorer defines required methods for space management // SpaceStorer defines required methods for space management
@ -321,5 +321,5 @@ type LabelStorer interface {
// OnboardStorer defines required methods for enterprise customer onboarding process. // OnboardStorer defines required methods for enterprise customer onboarding process.
type OnboardStorer interface { type OnboardStorer interface {
ContentCounts() (spaces, docs int) ContentCounts(orgID string) (spaces, docs int)
} }

View file

@ -42,7 +42,7 @@ func main() {
rt.Product.Major = "3" rt.Product.Major = "3"
rt.Product.Minor = "1" rt.Product.Minor = "1"
rt.Product.Patch = "0" rt.Product.Patch = "0"
rt.Product.Revision = "190625173456" rt.Product.Revision = "190629131646"
rt.Product.Version = fmt.Sprintf("%s.%s.%s", rt.Product.Major, rt.Product.Minor, rt.Product.Patch) rt.Product.Version = fmt.Sprintf("%s.%s.%s", rt.Product.Major, rt.Product.Minor, rt.Product.Patch)
rt.Product.Edition = domain.CommunityEdition rt.Product.Edition = domain.CommunityEdition
rt.Product.Title = fmt.Sprintf("%s Edition", rt.Product.Edition) rt.Product.Title = fmt.Sprintf("%s Edition", rt.Product.Edition)

File diff suppressed because one or more lines are too long

View file

@ -263,6 +263,7 @@ func (m *middleware) preAuthorizeStaticAssets(rt *env.Runtime, r *http.Request)
ctx.GlobalAdmin = false ctx.GlobalAdmin = false
ctx.AppURL = r.Host ctx.AppURL = r.Host
ctx.SSL = request.IsSSL(r) ctx.SSL = request.IsSSL(r)
ctx.OrgID = org.RefID
return true, ctx return true, ctx
} }