mirror of
https://github.com/documize/community.git
synced 2025-07-19 05:09:42 +02:00
Make API work with new schema
This commit is contained in:
parent
28342fcf5e
commit
4f0cc2f616
48 changed files with 1218 additions and 1097 deletions
|
@ -73,7 +73,7 @@ func Check(runtime *env.Runtime) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // if there are no rows in the database, enter set-up mode
|
// if there are no rows in the database, enter set-up mode
|
||||||
var flds []string
|
var flds []string
|
||||||
if err := runtime.Db.Select(&flds, runtime.StoreProvider.QueryTableList()); err != nil {
|
if err := runtime.Db.Select(&flds, runtime.StoreProvider.QueryTableList()); err != nil {
|
||||||
msg := fmt.Sprintf("Database: unable to get database table list ")
|
msg := fmt.Sprintf("Database: unable to get database table list ")
|
||||||
|
@ -88,22 +88,6 @@ func Check(runtime *env.Runtime) bool {
|
||||||
runtime.Flags.SiteMode = env.SiteModeSetup
|
runtime.Flags.SiteMode = env.SiteModeSetup
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Ensure no missing tables.
|
|
||||||
var tables = []string{"account", "attachment", "document",
|
|
||||||
"label", "organization", "page", "revision", "search", "user"}
|
|
||||||
|
|
||||||
for _, table := range tables {
|
|
||||||
var result []string
|
|
||||||
if err := runtime.Db.Select(&result, fmt.Sprintf("SELECT COUNT(*) FROM %s ;", table)); err != nil {
|
|
||||||
msg := fmt.Sprintf("Database: missing table %s", table)
|
|
||||||
runtime.Log.Error(msg, err)
|
|
||||||
web.SiteInfo.Issue = msg
|
|
||||||
runtime.Flags.SiteMode = env.SiteModeBadDB
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// We have good database, so proceed with app boot process.
|
// We have good database, so proceed with app boot process.
|
||||||
runtime.Flags.SiteMode = env.SiteModeNormal
|
runtime.Flags.SiteMode = env.SiteModeNormal
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
// "time"
|
||||||
|
|
||||||
"github.com/documize/community/core/env"
|
"github.com/documize/community/core/env"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
|
@ -24,7 +24,7 @@ import (
|
||||||
|
|
||||||
// InstallUpgrade creates new database or upgrades existing database.
|
// InstallUpgrade creates new database or upgrades existing database.
|
||||||
func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) {
|
func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) {
|
||||||
amLeader := false
|
// amLeader := false
|
||||||
|
|
||||||
// Get all SQL scripts.
|
// Get all SQL scripts.
|
||||||
scripts, err := LoadScripts()
|
scripts, err := LoadScripts()
|
||||||
|
@ -62,51 +62,77 @@ func InstallUpgrade(runtime *env.Runtime, existingDB bool) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if existingDB {
|
// For MySQL type there was major new schema introduced in v24.
|
||||||
var err error
|
// We check for this release and bypass usual locking code
|
||||||
amLeader, err = Lock(runtime, len(toProcess))
|
// because tables have changed.
|
||||||
if err != nil {
|
legacyMigration := runtime.StoreProvider.Type() == env.StoreTypeMySQL &&
|
||||||
runtime.Log.Error("Database: failed to lock existing database for processing", err)
|
currentVersion > 0 && currentVersion < 25 && len(toProcess) >= 26 && toProcess[len(toProcess)-1].Version == 25
|
||||||
}
|
|
||||||
} else {
|
if legacyMigration {
|
||||||
// New installation hopes that you are only spinning up one instance of Documize.
|
// Bypass all DB locking/checking processes as these look for new schema
|
||||||
// Assumption: nobody will perform the intial setup in a clustered environment.
|
// which we are about to install.
|
||||||
amLeader = true
|
toProcess = toProcess[len(toProcess)-1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := runtime.Db.Beginx()
|
tx, err := runtime.Db.Beginx()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Unlock(runtime, tx, err, amLeader)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If currently running process is database leader then we perform upgrade.
|
|
||||||
if amLeader {
|
|
||||||
runtime.Log.Info(fmt.Sprintf("Database: %d SQL scripts to process", len(toProcess)))
|
|
||||||
|
|
||||||
err = runScripts(runtime, tx, toProcess)
|
err = runScripts(runtime, tx, toProcess)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
runtime.Log.Error("Database: error processing SQL script", err)
|
runtime.Log.Error("Database: error processing SQL scripts", err)
|
||||||
}
|
|
||||||
|
|
||||||
return Unlock(runtime, tx, err, amLeader)
|
|
||||||
}
|
|
||||||
|
|
||||||
// If currently running process is a slave instance then we wait for migration to complete.
|
|
||||||
targetVersion := toProcess[len(toProcess)-1].Version
|
|
||||||
|
|
||||||
for targetVersion != currentVersion {
|
|
||||||
time.Sleep(time.Second)
|
|
||||||
runtime.Log.Info("Database: slave instance polling for upgrade process completion")
|
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
|
|
||||||
// Get database version and check again.
|
|
||||||
currentVersion, err = CurrentVersion(runtime)
|
|
||||||
if err != nil {
|
|
||||||
return Unlock(runtime, tx, err, amLeader)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return Unlock(runtime, tx, nil, amLeader)
|
tx.Commit()
|
||||||
|
|
||||||
|
return nil
|
||||||
|
|
||||||
|
// New style schema
|
||||||
|
// if existingDB {
|
||||||
|
// amLeader, err = Lock(runtime, len(toProcess))
|
||||||
|
// if err != nil {
|
||||||
|
// runtime.Log.Error("Database: failed to lock existing database for processing", err)
|
||||||
|
// }
|
||||||
|
// } else {
|
||||||
|
// // New installation hopes that you are only spinning up one instance of Documize.
|
||||||
|
// // Assumption: nobody will perform the intial setup in a clustered environment.
|
||||||
|
// amLeader = true
|
||||||
|
// }
|
||||||
|
|
||||||
|
// tx, err := runtime.Db.Beginx()
|
||||||
|
// if err != nil {
|
||||||
|
// return Unlock(runtime, tx, err, amLeader)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // If currently running process is database leader then we perform upgrade.
|
||||||
|
// if amLeader {
|
||||||
|
// runtime.Log.Info(fmt.Sprintf("Database: %d SQL scripts to process", len(toProcess)))
|
||||||
|
|
||||||
|
// err = runScripts(runtime, tx, toProcess)
|
||||||
|
// if err != nil {
|
||||||
|
// runtime.Log.Error("Database: error processing SQL script", err)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return Unlock(runtime, tx, err, amLeader)
|
||||||
|
// }
|
||||||
|
|
||||||
|
// // If currently running process is a slave instance then we wait for migration to complete.
|
||||||
|
// targetVersion := toProcess[len(toProcess)-1].Version
|
||||||
|
|
||||||
|
// for targetVersion != currentVersion {
|
||||||
|
// time.Sleep(time.Second)
|
||||||
|
// runtime.Log.Info("Database: slave instance polling for upgrade process completion")
|
||||||
|
// tx.Rollback()
|
||||||
|
|
||||||
|
// // Get database version and check again.
|
||||||
|
// currentVersion, err = CurrentVersion(runtime)
|
||||||
|
// if err != nil {
|
||||||
|
// return Unlock(runtime, tx, err, amLeader)
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// return Unlock(runtime, tx, nil, amLeader)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run SQL scripts to instal or upgrade this database.
|
// Run SQL scripts to instal or upgrade this database.
|
||||||
|
@ -117,12 +143,23 @@ func runScripts(runtime *env.Runtime, tx *sqlx.Tx, scripts []Script) (err error)
|
||||||
|
|
||||||
err = executeSQL(tx, runtime.StoreProvider.Type(), runtime.StoreProvider.TypeVariant(), script.Script)
|
err = executeSQL(tx, runtime.StoreProvider.Type(), runtime.StoreProvider.TypeVariant(), script.Script)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
runtime.Log.Error(fmt.Sprintf("error executing script version %d", script.Version), err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Record the fact we have processed this database script version.
|
// Record the fact we have processed this database script version.
|
||||||
_, err = tx.Exec(runtime.StoreProvider.QueryRecordVersionUpgrade(script.Version))
|
_, err = tx.Exec(runtime.StoreProvider.QueryRecordVersionUpgrade(script.Version))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
// For MySQL we try the legacy DB checks.
|
||||||
|
if runtime.StoreProvider.Type() == env.StoreTypeMySQL {
|
||||||
|
runtime.Log.Error(fmt.Sprintf("Database: attempting legacy fallback for script version %d", script.Version), err)
|
||||||
|
|
||||||
|
_, err = tx.Exec(runtime.StoreProvider.QueryRecordVersionUpgradeLegacy(script.Version))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,6 +180,7 @@ func executeSQL(tx *sqlx.Tx, st env.StoreType, variant string, SQLfile []byte) e
|
||||||
|
|
||||||
_, err := tx.Exec(stmt)
|
_, err := tx.Exec(stmt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
fmt.Println("sql statement error:", stmt)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -175,12 +213,16 @@ func getStatements(bytes []byte) (stmts []string) {
|
||||||
// CurrentVersion returns number that represents the current database version number.
|
// CurrentVersion returns number that represents the current database version number.
|
||||||
// For example 23 represents the 23rd iteration of the database.
|
// For example 23 represents the 23rd iteration of the database.
|
||||||
func CurrentVersion(runtime *env.Runtime) (version int, err error) {
|
func CurrentVersion(runtime *env.Runtime) (version int, err error) {
|
||||||
row := runtime.Db.QueryRow(runtime.StoreProvider.QueryGetDatabaseVersion())
|
currentVersion := "0"
|
||||||
|
|
||||||
var currentVersion string
|
row := runtime.Db.QueryRow(runtime.StoreProvider.QueryGetDatabaseVersion())
|
||||||
err = row.Scan(¤tVersion)
|
err = row.Scan(¤tVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
currentVersion = "0"
|
// For MySQL we try the legacy DB checks.
|
||||||
|
if runtime.StoreProvider.Type() == env.StoreTypeMySQL {
|
||||||
|
row := runtime.Db.QueryRow(runtime.StoreProvider.QueryGetDatabaseVersionLegacy())
|
||||||
|
err = row.Scan(¤tVersion)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return extractVersionNumber(currentVersion), nil
|
return extractVersionNumber(currentVersion), nil
|
||||||
|
|
|
@ -29,10 +29,11 @@ RENAME TABLE
|
||||||
`userevent` TO dmz_audit_log,
|
`userevent` TO dmz_audit_log,
|
||||||
`useraction` TO dmz_action;
|
`useraction` TO dmz_action;
|
||||||
|
|
||||||
|
|
||||||
-- field renaming
|
-- field renaming
|
||||||
ALTER TABLE `dmz_org`
|
ALTER TABLE dmz_org
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `company` `c_refid` VARCHAR(500) NOT NULL,
|
CHANGE `company` `c_company` VARCHAR(500) NOT NULL,
|
||||||
CHANGE `title` `c_title` VARCHAR(500) NOT NULL,
|
CHANGE `title` `c_title` VARCHAR(500) NOT NULL,
|
||||||
CHANGE `message` `c_message` VARCHAR(500) NOT NULL,
|
CHANGE `message` `c_message` VARCHAR(500) NOT NULL,
|
||||||
CHANGE `domain` `c_domain` VARCHAR(200) NOT NULL DEFAULT '',
|
CHANGE `domain` `c_domain` VARCHAR(200) NOT NULL DEFAULT '',
|
||||||
|
@ -48,7 +49,7 @@ ALTER TABLE `dmz_org`
|
||||||
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_space`
|
ALTER TABLE dmz_space
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `userid` `c_userid` CHAR(16) NOT NULL DEFAULT '',
|
CHANGE `userid` `c_userid` CHAR(16) NOT NULL DEFAULT '',
|
||||||
|
@ -59,7 +60,7 @@ ALTER TABLE `dmz_space`
|
||||||
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_category`
|
ALTER TABLE dmz_category
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `labelid` `c_spaceid` CHAR(16) NOT NULL,
|
CHANGE `labelid` `c_spaceid` CHAR(16) NOT NULL,
|
||||||
|
@ -67,7 +68,7 @@ ALTER TABLE `dmz_category`
|
||||||
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_category_member`
|
ALTER TABLE dmz_category_member
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `labelid` `c_spaceid` CHAR(16) NOT NULL,
|
CHANGE `labelid` `c_spaceid` CHAR(16) NOT NULL,
|
||||||
|
@ -76,7 +77,7 @@ ALTER TABLE `dmz_category_member`
|
||||||
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_group`
|
ALTER TABLE dmz_group
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `role` `c_name` VARCHAR(50) NOT NULL DEFAULT '',
|
CHANGE `role` `c_name` VARCHAR(50) NOT NULL DEFAULT '',
|
||||||
|
@ -84,12 +85,13 @@ ALTER TABLE `dmz_group`
|
||||||
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_group_member`
|
ALTER TABLE dmz_group_member
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `roleid` `c_groupid` CHAR(16) NOT NULL,
|
CHANGE `roleid` `c_groupid` CHAR(16) NOT NULL,
|
||||||
CHANGE `userid` `c_userid` CHAR(16) NOT NULL;
|
CHANGE `userid` `c_userid` CHAR(16) NOT NULL;
|
||||||
|
|
||||||
ALTER TABLE `dmz_permission`
|
|
||||||
|
ALTER TABLE dmz_permission
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `who` `c_who` VARCHAR(30) NOT NULL,
|
CHANGE `who` `c_who` VARCHAR(30) NOT NULL,
|
||||||
CHANGE `whoid` `c_whoid` CHAR(16) NOT NULL DEFAULT '',
|
CHANGE `whoid` `c_whoid` CHAR(16) NOT NULL DEFAULT '',
|
||||||
|
@ -99,7 +101,8 @@ ALTER TABLE `dmz_permission`
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_doc`
|
|
||||||
|
ALTER TABLE dmz_doc
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `labelid` `c_spaceid` CHAR(16) NOT NULL,
|
CHANGE `labelid` `c_spaceid` CHAR(16) NOT NULL,
|
||||||
|
@ -121,7 +124,7 @@ ALTER TABLE `dmz_doc`
|
||||||
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_doc_share`
|
ALTER TABLE dmz_doc_share
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
||||||
CHANGE `userid` `c_userid` CHAR(16) DEFAULT '',
|
CHANGE `userid` `c_userid` CHAR(16) DEFAULT '',
|
||||||
|
@ -133,7 +136,7 @@ ALTER TABLE `dmz_doc_share`
|
||||||
CHANGE `active` `c_active` BOOL NOT NULL DEFAULT 1,
|
CHANGE `active` `c_active` BOOL NOT NULL DEFAULT 1,
|
||||||
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_doc_vote`
|
ALTER TABLE dmz_doc_vote
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
||||||
|
@ -142,7 +145,7 @@ ALTER TABLE `dmz_doc_vote`
|
||||||
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_doc_comment`
|
ALTER TABLE dmz_doc_comment
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
||||||
|
@ -151,7 +154,7 @@ ALTER TABLE `dmz_doc_comment`
|
||||||
CHANGE `feedback` `c_feedback` LONGTEXT,
|
CHANGE `feedback` `c_feedback` LONGTEXT,
|
||||||
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `created` `c_created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_doc_attachment`
|
ALTER TABLE dmz_doc_attachment
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
||||||
|
@ -163,7 +166,7 @@ ALTER TABLE `dmz_doc_attachment`
|
||||||
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_doc_link`
|
ALTER TABLE dmz_doc_link
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `folderid` `c_spaceid` CHAR(16) NOT NULL,
|
CHANGE `folderid` `c_spaceid` CHAR(16) NOT NULL,
|
||||||
|
@ -178,7 +181,7 @@ ALTER TABLE `dmz_doc_link`
|
||||||
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_section`
|
ALTER TABLE dmz_section
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
||||||
|
@ -196,7 +199,7 @@ ALTER TABLE `dmz_section`
|
||||||
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_section_meta`
|
ALTER TABLE dmz_section_meta
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
||||||
CHANGE `userid` `c_userid` CHAR(16) NOT NULL DEFAULT '',
|
CHANGE `userid` `c_userid` CHAR(16) NOT NULL DEFAULT '',
|
||||||
|
@ -207,7 +210,7 @@ ALTER TABLE `dmz_section_meta`
|
||||||
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_section_template`
|
ALTER TABLE dmz_section_template
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `labelid` `c_spaceid` CHAR(16) DEFAULT '',
|
CHANGE `labelid` `c_spaceid` CHAR(16) DEFAULT '',
|
||||||
|
@ -224,7 +227,7 @@ ALTER TABLE `dmz_section_template`
|
||||||
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_section_revision`
|
ALTER TABLE dmz_section_revision
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
||||||
|
@ -240,7 +243,7 @@ ALTER TABLE `dmz_section_revision`
|
||||||
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_user`
|
ALTER TABLE dmz_user
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `firstname` `c_firstname` VARCHAR(500) NOT NULL DEFAULT '',
|
CHANGE `firstname` `c_firstname` VARCHAR(500) NOT NULL DEFAULT '',
|
||||||
CHANGE `lastname` `c_lastname` VARCHAR(500) NOT NULL DEFAULT '',
|
CHANGE `lastname` `c_lastname` VARCHAR(500) NOT NULL DEFAULT '',
|
||||||
|
@ -255,7 +258,7 @@ ALTER TABLE `dmz_user`
|
||||||
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_user_account`
|
ALTER TABLE dmz_user_account
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `userid` `c_userid` CHAR(16) NOT NULL,
|
CHANGE `userid` `c_userid` CHAR(16) NOT NULL,
|
||||||
|
@ -267,7 +270,7 @@ ALTER TABLE `dmz_user_account`
|
||||||
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_user_activity`
|
ALTER TABLE dmz_user_activity
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `userid` `c_userid` CHAR(16) NOT NULL,
|
CHANGE `userid` `c_userid` CHAR(16) NOT NULL,
|
||||||
CHANGE `labelid` `c_spaceid` CHAR(16) NOT NULL,
|
CHANGE `labelid` `c_spaceid` CHAR(16) NOT NULL,
|
||||||
|
@ -278,17 +281,17 @@ ALTER TABLE `dmz_user_activity`
|
||||||
CHANGE `metadata` `c_metadata` VARCHAR(1000) NOT NULL DEFAULT '',
|
CHANGE `metadata` `c_metadata` VARCHAR(1000) NOT NULL DEFAULT '',
|
||||||
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_user_config`
|
ALTER TABLE dmz_user_config
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `userid` `c_userid` CHAR(16) NOT NULL,
|
CHANGE `userid` `c_userid` CHAR(16) NOT NULL,
|
||||||
CHANGE `key` `c_key` CHAR(200) NOT NULL,
|
CHANGE `key` `c_key` CHAR(200) NOT NULL,
|
||||||
CHANGE `config` `c_config` JSON;
|
CHANGE `config` `c_config` JSON;
|
||||||
|
|
||||||
ALTER TABLE `dmz_config`
|
ALTER TABLE dmz_config
|
||||||
CHANGE `key` `c_key` CHAR(200) NOT NULL,
|
CHANGE `key` `c_key` CHAR(200) NOT NULL,
|
||||||
CHANGE `config` `c_config` JSON;
|
CHANGE `config` `c_config` JSON;
|
||||||
|
|
||||||
ALTER TABLE `dmz_pin`
|
ALTER TABLE dmz_pin
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `userid` `c_userid` CHAR(16) DEFAULT '',
|
CHANGE `userid` `c_userid` CHAR(16) DEFAULT '',
|
||||||
|
@ -299,7 +302,7 @@ ALTER TABLE `dmz_pin`
|
||||||
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `revised` `c_revised` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_search`
|
ALTER TABLE dmz_search
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
||||||
CHANGE `itemid` `c_itemid` CHAR(16) NOT NULL DEFAULT '',
|
CHANGE `itemid` `c_itemid` CHAR(16) NOT NULL DEFAULT '',
|
||||||
|
@ -307,14 +310,14 @@ ALTER TABLE `dmz_search`
|
||||||
CHANGE `content` `c_content` LONGTEXT,
|
CHANGE `content` `c_content` LONGTEXT,
|
||||||
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_audit_log`
|
ALTER TABLE dmz_audit_log
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `userid` `c_userid` CHAR(16) NOT NULL,
|
CHANGE `userid` `c_userid` CHAR(16) NOT NULL,
|
||||||
CHANGE `eventtype` `c_eventtype` VARCHAR(100) NOT NULL DEFAULT '',
|
CHANGE `eventtype` `c_eventtype` VARCHAR(100) NOT NULL DEFAULT '',
|
||||||
CHANGE `ip` `c_ip` VARCHAR(39) NOT NULL DEFAULT '',
|
CHANGE `ip` `c_ip` VARCHAR(39) NOT NULL DEFAULT '',
|
||||||
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
CHANGE `created` `c_created` TIMESTAMP DEFAULT CURRENT_TIMESTAMP;
|
||||||
|
|
||||||
ALTER TABLE `dmz_action`
|
ALTER TABLE dmz_action
|
||||||
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
CHANGE `refid` `c_refid` CHAR(16) NOT NULL,
|
||||||
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
CHANGE `orgid` `c_orgid` CHAR(16) NOT NULL,
|
||||||
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
CHANGE `documentid` `c_docid` CHAR(16) NOT NULL,
|
||||||
|
|
8
core/env/runtime.go
vendored
8
core/env/runtime.go
vendored
|
@ -107,9 +107,17 @@ type StoreProvider interface {
|
||||||
// that records the database version number.
|
// that records the database version number.
|
||||||
QueryRecordVersionUpgrade(version int) string
|
QueryRecordVersionUpgrade(version int) string
|
||||||
|
|
||||||
|
// QueryRecordVersionUpgrade returns database specific insert statement
|
||||||
|
// that records the database version number.
|
||||||
|
// For use on databases before The Great Schema Migration (v25, MySQL).
|
||||||
|
QueryRecordVersionUpgradeLegacy(version int) string
|
||||||
|
|
||||||
// QueryGetDatabaseVersion returns the schema version number.
|
// QueryGetDatabaseVersion returns the schema version number.
|
||||||
QueryGetDatabaseVersion() string
|
QueryGetDatabaseVersion() string
|
||||||
|
|
||||||
|
// QueryGetDatabaseVersionLegacy returns the schema version number before The Great Schema Migration (v25, MySQL).
|
||||||
|
QueryGetDatabaseVersionLegacy() string
|
||||||
|
|
||||||
// QueryTableList returns a list tables in Documize database.
|
// QueryTableList returns a list tables in Documize database.
|
||||||
QueryTableList() string
|
QueryTableList() string
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ func (s Scope) RecordUserActivity(ctx domain.RequestContext, activity activity.U
|
||||||
activity.UserID = ctx.UserID
|
activity.UserID = ctx.UserID
|
||||||
activity.Created = time.Now().UTC()
|
activity.Created = time.Now().UTC()
|
||||||
|
|
||||||
_, err = ctx.Transaction.Exec("INSERT INTO dmz_user_activity (c_orgid, c_userid, c_spaceid, c_docid, c_pageid, c_sourcetype, c_activitytype, c_metadata, c_created) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
_, err = ctx.Transaction.Exec("INSERT INTO dmz_user_activity (c_orgid, c_userid, c_spaceid, c_docid, c_sectionid, c_sourcetype, c_activitytype, c_metadata, c_created) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
activity.OrgID, activity.UserID, activity.SpaceID, activity.DocumentID, activity.SectionID, activity.SourceType, activity.ActivityType, activity.Metadata, activity.Created)
|
activity.OrgID, activity.UserID, activity.SpaceID, activity.DocumentID, activity.SectionID, activity.SourceType, activity.ActivityType, activity.Metadata, activity.Created)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -46,15 +46,15 @@ func (s Scope) RecordUserActivity(ctx domain.RequestContext, activity activity.U
|
||||||
|
|
||||||
// GetDocumentActivity returns the metadata for a specified document.
|
// GetDocumentActivity returns the metadata for a specified document.
|
||||||
func (s Scope) GetDocumentActivity(ctx domain.RequestContext, id string) (a []activity.DocumentActivity, err error) {
|
func (s Scope) GetDocumentActivity(ctx domain.RequestContext, id string) (a []activity.DocumentActivity, err error) {
|
||||||
qry := `SELECT a.id, DATE(a.c_created) as created, a.c_orgid as orgid,
|
qry := `SELECT a.id, DATE(a.c_created) AS created, a.c_orgid AS orgid,
|
||||||
IFNULL(a.c_userid, '') AS userid, a.c_spaceid AS spaceid,
|
IFNULL(a.c_userid, '') AS userid, a.c_spaceid AS spaceid,
|
||||||
a.docid AS documentid, a.sectionid AS sectionid, a.c_activitytype AS activitytype,
|
a.docid AS documentid, a.sectionid AS sectionid, a.c_activitytype AS activitytype,
|
||||||
a.c_metadata AS metadata,
|
a.c_metadata AS metadata,
|
||||||
IFNULL(u.c_firstname, 'Anonymous') AS firstname, IFNULL(u.c_lastname, 'Viewer') AS lastname,
|
IFNULL(u.c_firstname, 'Anonymous') AS firstname, IFNULL(u.c_lastname, 'Viewer') AS lastname,
|
||||||
IFNULL(p.c_name, '') as sectionname
|
IFNULL(p.c_name, '') AS sectionname
|
||||||
FROM dmz_user_activity a
|
FROM dmz_user_activity a
|
||||||
LEFT JOIN user u ON a.c_userid=u.c_refid
|
LEFT JOIN dmz_user u ON a.c_userid=u.c_refid
|
||||||
LEFT JOIN page p ON a.c_pageid=p.c_refid
|
LEFT JOIN dmz_section p ON a.c_sectionid=p.c_refid
|
||||||
WHERE a.c_orgid=? AND a.c_docid=?
|
WHERE a.c_orgid=? AND a.c_docid=?
|
||||||
AND a.c_userid != '0' AND a.c_userid != ''
|
AND a.c_userid != '0' AND a.c_userid != ''
|
||||||
ORDER BY a.c_created DESC`
|
ORDER BY a.c_created DESC`
|
||||||
|
|
|
@ -190,7 +190,7 @@ func (h *Handler) ValidateToken(w http.ResponseWriter, r *http.Request) {
|
||||||
rc.OrgName = org.Title
|
rc.OrgName = org.Title
|
||||||
rc.Administrator = false
|
rc.Administrator = false
|
||||||
rc.Editor = false
|
rc.Editor = false
|
||||||
rc.Global = false
|
rc.GlobalAdmin = false
|
||||||
rc.AppURL = r.Host
|
rc.AppURL = r.Host
|
||||||
rc.Subdomain = organization.GetSubdomainFromHost(r)
|
rc.Subdomain = organization.GetSubdomainFromHost(r)
|
||||||
rc.SSL = r.TLS != nil
|
rc.SSL = r.TLS != nil
|
||||||
|
@ -210,7 +210,7 @@ func (h *Handler) ValidateToken(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
rc.Administrator = u.Admin
|
rc.Administrator = u.Admin
|
||||||
rc.Editor = u.Editor
|
rc.Editor = u.Editor
|
||||||
rc.Global = u.Global
|
rc.GlobalAdmin = u.GlobalAdmin
|
||||||
|
|
||||||
response.WriteJSON(w, u)
|
response.WriteJSON(w, u)
|
||||||
}
|
}
|
||||||
|
|
|
@ -250,7 +250,7 @@ func convertUser(c lm.LDAPConfig, lu lm.LDAPUser) (du user.User) {
|
||||||
du.ViewUsers = false
|
du.ViewUsers = false
|
||||||
du.Analytics = false
|
du.Analytics = false
|
||||||
du.Admin = false
|
du.Admin = false
|
||||||
du.Global = false
|
du.GlobalAdmin = false
|
||||||
du.Editor = c.DefaultPermissionAddSpace
|
du.Editor = c.DefaultPermissionAddSpace
|
||||||
du.Email = lu.Email
|
du.Email = lu.Email
|
||||||
du.Firstname = lu.Firstname
|
du.Firstname = lu.Firstname
|
||||||
|
|
|
@ -54,10 +54,11 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
||||||
err = json.Unmarshal(body, &b)
|
err = json.Unmarshal(body, &b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteBadRequestError(w, method, err.Error())
|
response.WriteBadRequestError(w, method, err.Error())
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !permission.CanUploadDocument(ctx, *h.Store, b.LabelID) {
|
if !permission.CanUploadDocument(ctx, *h.Store, b.SpaceID) {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -67,6 +68,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,6 +76,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
ctx.Transaction.Rollback()
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +87,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
||||||
b, err = h.Store.Block.Get(ctx, b.RefID)
|
b, err = h.Store.Block.Get(ctx, b.RefID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -104,6 +108,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
||||||
b, err := h.Store.Block.Get(ctx, blockID)
|
b, err := h.Store.Block.Get(ctx, blockID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,6 +137,7 @@ func (h *Handler) GetBySpace(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +171,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
b.RefID = blockID
|
b.RefID = blockID
|
||||||
|
|
||||||
if !permission.CanUploadDocument(ctx, *h.Store, b.LabelID) {
|
if !permission.CanUploadDocument(ctx, *h.Store, b.SpaceID) {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -173,6 +179,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,6 +187,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
ctx.Transaction.Rollback()
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,6 +220,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
ctx.Transaction.Rollback()
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,6 +228,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
ctx.Transaction.Rollback()
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ func (s Scope) Add(ctx domain.RequestContext, b block.Block) (err error) {
|
||||||
b.Revised = time.Now().UTC()
|
b.Revised = time.Now().UTC()
|
||||||
|
|
||||||
_, err = ctx.Transaction.Exec("INSERT INTO dmz_section_template (c_refid, c_orgid, c_spaceid, c_userid, c_contenttype, c_type, c_name, c_body, c_desc, c_rawbody, c_config, c_external, used, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
_, err = ctx.Transaction.Exec("INSERT INTO dmz_section_template (c_refid, c_orgid, c_spaceid, c_userid, c_contenttype, c_type, c_name, c_body, c_desc, c_rawbody, c_config, c_external, used, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
b.RefID, b.OrgID, b.SpaceID, b.UserID, b.ContentType, b.PageType, b.Name, b.Body, b.Excerpt, b.RawBody, b.Config, b.ExternalSource, b.Used, b.Created, b.Revised)
|
b.RefID, b.OrgID, b.SpaceID, b.UserID, b.ContentType, b.Type, b.Name, b.Body, b.Excerpt, b.RawBody, b.Config, b.ExternalSource, b.Used, b.Created, b.Revised)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute insert block")
|
err = errors.Wrap(err, "execute insert block")
|
||||||
|
@ -53,7 +53,7 @@ func (s Scope) Get(ctx domain.RequestContext, id string) (b block.Block, err err
|
||||||
a.c_name AS name, a.c_body AS body, a.c_desc AS excerpt, a.c_rawbody AS rawbody,
|
a.c_name AS name, a.c_body AS body, a.c_desc AS excerpt, a.c_rawbody AS rawbody,
|
||||||
a.c_config AS config, a.c_external AS externalsource, a.c_used AS used,
|
a.c_config AS config, a.c_external AS externalsource, a.c_used AS used,
|
||||||
a.c_created AS created, a.c_revised AS revised,
|
a.c_created AS created, a.c_revised AS revised,
|
||||||
b.c_firstname a firstname, b.c_lastname AS lastname
|
b.c_firstname AS firstname, b.c_lastname AS lastname
|
||||||
FROM dmz_section_template a LEFT JOIN dmz_user b ON a.c_userid = b.c_refid
|
FROM dmz_section_template a LEFT JOIN dmz_user b ON a.c_userid = b.c_refid
|
||||||
WHERE a.c_orgid=? AND a.c_refid=?`,
|
WHERE a.c_orgid=? AND a.c_refid=?`,
|
||||||
ctx.OrgID, id)
|
ctx.OrgID, id)
|
||||||
|
@ -74,7 +74,7 @@ func (s Scope) GetBySpace(ctx domain.RequestContext, spaceID string) (b []block.
|
||||||
a.c_name AS name, a.c_body AS body, a.c_desc AS excerpt, a.c_rawbody AS rawbody,
|
a.c_name AS name, a.c_body AS body, a.c_desc AS excerpt, a.c_rawbody AS rawbody,
|
||||||
a.c_config AS config, a.c_external AS externalsource, a.c_used AS used,
|
a.c_config AS config, a.c_external AS externalsource, a.c_used AS used,
|
||||||
a.c_created AS created, a.c_revised AS revised,
|
a.c_created AS created, a.c_revised AS revised,
|
||||||
b.c_firstname a firstname, b.c_lastname AS lastname
|
b.c_firstname AS firstname, b.c_lastname AS lastname
|
||||||
FROM dmz_section_template a LEFT JOIN dmz_user b ON a.c_userid = b.c_refid
|
FROM dmz_section_template a LEFT JOIN dmz_user b ON a.c_userid = b.c_refid
|
||||||
WHERE a.c_orgid=? AND a.c_spaceid=?
|
WHERE a.c_orgid=? AND a.c_spaceid=?
|
||||||
ORDER BY a.c_name`,
|
ORDER BY a.c_name`,
|
||||||
|
|
|
@ -74,9 +74,9 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Category max length 30.
|
// Category max length 30.
|
||||||
cat.Category = strings.TrimSpace(cat.Category)
|
cat.Name = strings.TrimSpace(cat.Name)
|
||||||
if len(cat.Category) > 30 {
|
if len(cat.Name) > 30 {
|
||||||
cat.Category = cat.Category[:30]
|
cat.Name = cat.Name[:30]
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.Store.Category.Add(ctx, cat)
|
err = h.Store.Category.Add(ctx, cat)
|
||||||
|
@ -200,7 +200,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
cat.OrgID = ctx.OrgID
|
cat.OrgID = ctx.OrgID
|
||||||
cat.RefID = categoryID
|
cat.RefID = categoryID
|
||||||
|
|
||||||
ok := permission.HasPermission(ctx, *h.Store, cat.LabelID, pm.SpaceManage, pm.SpaceOwner)
|
ok := permission.HasPermission(ctx, *h.Store, cat.SpaceID, pm.SpaceManage, pm.SpaceOwner)
|
||||||
if !ok || !ctx.Authenticated {
|
if !ok || !ctx.Authenticated {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
|
@ -252,7 +252,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ok := permission.HasPermission(ctx, *h.Store, cat.LabelID, pm.SpaceManage, pm.SpaceOwner)
|
ok := permission.HasPermission(ctx, *h.Store, cat.SpaceID, pm.SpaceManage, pm.SpaceOwner)
|
||||||
if !ok || !ctx.Authenticated {
|
if !ok || !ctx.Authenticated {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
|
@ -358,7 +358,7 @@ func (h *Handler) SetDocumentCategoryMembership(w http.ResponseWriter, r *http.R
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !permission.HasPermission(ctx, *h.Store, cats[0].LabelID, pm.DocumentAdd, pm.DocumentEdit) {
|
if !permission.HasPermission(ctx, *h.Store, cats[0].SpaceID, pm.DocumentAdd, pm.DocumentEdit) {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -413,7 +413,7 @@ func (h *Handler) GetDocumentCategoryMembership(w http.ResponseWriter, r *http.R
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !permission.HasPermission(ctx, *h.Store, doc.LabelID, pm.SpaceView, pm.DocumentAdd, pm.DocumentEdit) {
|
if !permission.HasPermission(ctx, *h.Store, doc.SpaceID, pm.SpaceView, pm.DocumentAdd, pm.DocumentEdit) {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,7 +225,7 @@ func (s Scope) GetSpaceCategorySummary(ctx domain.RequestContext, spaceID string
|
||||||
c = []category.SummaryModel{}
|
c = []category.SummaryModel{}
|
||||||
|
|
||||||
err = s.Runtime.Db.Select(&c, `
|
err = s.Runtime.Db.Select(&c, `
|
||||||
SELECT 'documents' AS type, c_categoryid, COUNT(*) AS count
|
SELECT 'documents' AS type, c_categoryid AS categoryid, COUNT(*) AS count
|
||||||
FROM dmz_category_member
|
FROM dmz_category_member
|
||||||
WHERE c_orgid=? AND c_spaceid=?
|
WHERE c_orgid=? AND c_spaceid=?
|
||||||
AND c_docid IN (
|
AND c_docid IN (
|
||||||
|
@ -241,13 +241,13 @@ func (s Scope) GetSpaceCategorySummary(ctx domain.RequestContext, spaceID string
|
||||||
GROUP BY c_groupid
|
GROUP BY c_groupid
|
||||||
) AS x INNER JOIN dmz_doc AS d ON d.c_groupid=x.c_groupid AND d.c_versionorder=x.latestversion
|
) AS x INNER JOIN dmz_doc AS d ON d.c_groupid=x.c_groupid AND d.c_versionorder=x.latestversion
|
||||||
)
|
)
|
||||||
GROUP BY c_categoryid, c_type
|
GROUP BY c_categoryid, type
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT 'users' AS type, c_refid AS categoryid, count(*) AS count
|
SELECT 'users' AS type, c_refid AS categoryid, count(*) AS count
|
||||||
FROM dmz_permission
|
FROM dmz_permission
|
||||||
WHERE c_orgid=? AND c_location='category' AND c_refid IN
|
WHERE c_orgid=? AND c_location='category' AND c_refid IN
|
||||||
(SELECT c_refid FROM dmz_category WHERE c_orgid=? AND c_spaceid=?)
|
(SELECT c_refid FROM dmz_category WHERE c_orgid=? AND c_spaceid=?)
|
||||||
GROUP BY c_refid, c_type`,
|
GROUP BY c_refid, type`,
|
||||||
ctx.OrgID, spaceID,
|
ctx.OrgID, spaceID,
|
||||||
ctx.OrgID, spaceID, ctx.OrgID, spaceID,
|
ctx.OrgID, spaceID, ctx.OrgID, spaceID,
|
||||||
ctx.OrgID, ctx.OrgID, spaceID)
|
ctx.OrgID, ctx.OrgID, spaceID)
|
||||||
|
@ -286,7 +286,7 @@ func (s Scope) GetSpaceCategoryMembership(ctx domain.RequestContext, spaceID str
|
||||||
err = s.Runtime.Db.Select(&c, `
|
err = s.Runtime.Db.Select(&c, `
|
||||||
SELECT id, c_refid AS refid, c_orgid AS orgid, c_spaceid AS spaceid, c_categoryid AS categoryid, c_docid AS documentid, c_created AS created, c_revised AS revised
|
SELECT id, c_refid AS refid, c_orgid AS orgid, c_spaceid AS spaceid, c_categoryid AS categoryid, c_docid AS documentid, c_created AS created, c_revised AS revised
|
||||||
FROM dmz_category_member
|
FROM dmz_category_member
|
||||||
WHERE c_orgid=? AND c_spaceid=? AND spaceid IN
|
WHERE c_orgid=? AND c_spaceid=? AND c_spaceid IN
|
||||||
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_location='space' AND c_refid IN
|
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_location='space' AND c_refid IN
|
||||||
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space' AND c_action='view'
|
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space' AND c_action='view'
|
||||||
UNION ALL
|
UNION ALL
|
||||||
|
|
|
@ -42,7 +42,7 @@ type RequestContext struct {
|
||||||
Analytics bool
|
Analytics bool
|
||||||
Active bool
|
Active bool
|
||||||
Editor bool
|
Editor bool
|
||||||
Global bool
|
GlobalAdmin bool
|
||||||
ViewUsers bool
|
ViewUsers bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -171,7 +171,7 @@ func processDocument(ctx domain.RequestContext, r *env.Runtime, store *domain.St
|
||||||
document := convertFileResult(filename, fileResult)
|
document := convertFileResult(filename, fileResult)
|
||||||
document.Job = job
|
document.Job = job
|
||||||
document.OrgID = ctx.OrgID
|
document.OrgID = ctx.OrgID
|
||||||
document.LabelID = sp.RefID
|
document.SpaceID = sp.RefID
|
||||||
document.UserID = ctx.UserID
|
document.UserID = ctx.UserID
|
||||||
documentID := uniqueid.Generate()
|
documentID := uniqueid.Generate()
|
||||||
document.RefID = documentID
|
document.RefID = documentID
|
||||||
|
@ -193,16 +193,16 @@ func processDocument(ctx domain.RequestContext, r *env.Runtime, store *domain.St
|
||||||
p.OrgID = ctx.OrgID
|
p.OrgID = ctx.OrgID
|
||||||
p.DocumentID = documentID
|
p.DocumentID = documentID
|
||||||
p.Level = v.Level
|
p.Level = v.Level
|
||||||
p.Title = v.Title
|
p.Name = v.Title
|
||||||
p.Body = string(v.Body)
|
p.Body = string(v.Body)
|
||||||
p.Sequence = float64(k+1) * 1024.0 // need to start above 0 to allow insertion before the first item
|
p.Sequence = float64(k+1) * 1024.0 // need to start above 0 to allow insertion before the first item
|
||||||
pageID := uniqueid.Generate()
|
pageID := uniqueid.Generate()
|
||||||
p.RefID = pageID
|
p.RefID = pageID
|
||||||
p.ContentType = "wysiwyg"
|
p.ContentType = "wysiwyg"
|
||||||
p.PageType = "section"
|
p.Type = "section"
|
||||||
|
|
||||||
meta := page.Meta{}
|
meta := page.Meta{}
|
||||||
meta.PageID = pageID
|
meta.SectionID = pageID
|
||||||
meta.RawBody = p.Body
|
meta.RawBody = p.Body
|
||||||
meta.Config = "{}"
|
meta.Config = "{}"
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ func processDocument(ctx domain.RequestContext, r *env.Runtime, store *domain.St
|
||||||
}
|
}
|
||||||
|
|
||||||
store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: newDocument.LabelID,
|
SpaceID: newDocument.SpaceID,
|
||||||
DocumentID: newDocument.RefID,
|
DocumentID: newDocument.RefID,
|
||||||
SourceType: activity.SourceTypeDocument,
|
SourceType: activity.SourceTypeDocument,
|
||||||
ActivityType: activity.TypeCreated})
|
ActivityType: activity.TypeCreated})
|
||||||
|
@ -278,13 +278,13 @@ func convertFileResult(filename string, fileResult *api.DocumentConversionRespon
|
||||||
document = doc.Document{}
|
document = doc.Document{}
|
||||||
document.RefID = ""
|
document.RefID = ""
|
||||||
document.OrgID = ""
|
document.OrgID = ""
|
||||||
document.LabelID = ""
|
document.SpaceID = ""
|
||||||
document.Job = ""
|
document.Job = ""
|
||||||
document.Location = filename
|
document.Location = filename
|
||||||
|
|
||||||
if fileResult != nil {
|
if fileResult != nil {
|
||||||
if len(fileResult.Pages) > 0 {
|
if len(fileResult.Pages) > 0 {
|
||||||
document.Title = fileResult.Pages[0].Title
|
document.Name = fileResult.Pages[0].Title
|
||||||
document.Slug = stringutil.MakeSlug(fileResult.Pages[0].Title)
|
document.Slug = stringutil.MakeSlug(fileResult.Pages[0].Title)
|
||||||
}
|
}
|
||||||
document.Excerpt = fileResult.Excerpt
|
document.Excerpt = fileResult.Excerpt
|
||||||
|
|
|
@ -100,7 +100,7 @@ func CopyDocument(ctx domain.RequestContext, s domain.Store, documentID string)
|
||||||
|
|
||||||
pageID := uniqueid.Generate()
|
pageID := uniqueid.Generate()
|
||||||
p.RefID = pageID
|
p.RefID = pageID
|
||||||
meta.PageID = pageID
|
meta.SectionID = pageID
|
||||||
meta.DocumentID = newDocumentID
|
meta.DocumentID = newDocumentID
|
||||||
|
|
||||||
m := page.NewPage{}
|
m := page.NewPage{}
|
||||||
|
|
|
@ -70,7 +70,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !permission.CanViewSpaceDocument(ctx, *h.Store, document.LabelID) {
|
if !permission.CanViewSpaceDocument(ctx, *h.Store, document.SpaceID) {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -85,7 +85,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: document.LabelID,
|
SpaceID: document.SpaceID,
|
||||||
DocumentID: document.RefID,
|
DocumentID: document.RefID,
|
||||||
SourceType: activity.SourceTypeDocument,
|
SourceType: activity.SourceTypeDocument,
|
||||||
ActivityType: activity.TypeRead})
|
ActivityType: activity.TypeRead})
|
||||||
|
@ -166,7 +166,7 @@ func (h *Handler) BySpace(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sort by title.
|
// Sort by title.
|
||||||
sort.Sort(doc.ByTitle(documents))
|
sort.Sort(doc.ByName(documents))
|
||||||
|
|
||||||
// Remove documents that cannot be seen due to lack of
|
// Remove documents that cannot be seen due to lack of
|
||||||
// category view/access permission.
|
// category view/access permission.
|
||||||
|
@ -231,9 +231,9 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if oldDoc.LabelID != d.LabelID {
|
if oldDoc.SpaceID != d.SpaceID {
|
||||||
h.Store.Category.RemoveDocumentCategories(ctx, d.RefID)
|
h.Store.Category.RemoveDocumentCategories(ctx, d.RefID)
|
||||||
err = h.Store.Document.MoveActivity(ctx, documentID, oldDoc.LabelID, d.LabelID)
|
err = h.Store.Document.MoveActivity(ctx, documentID, oldDoc.SpaceID, d.SpaceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
ctx.Transaction.Rollback()
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
@ -268,7 +268,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
// Record document being marked as archived.
|
// Record document being marked as archived.
|
||||||
if d.Lifecycle == workflow.LifecycleArchived {
|
if d.Lifecycle == workflow.LifecycleArchived {
|
||||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: d.LabelID,
|
SpaceID: d.SpaceID,
|
||||||
DocumentID: documentID,
|
DocumentID: documentID,
|
||||||
SourceType: activity.SourceTypeDocument,
|
SourceType: activity.SourceTypeDocument,
|
||||||
ActivityType: activity.TypeArchived})
|
ActivityType: activity.TypeArchived})
|
||||||
|
@ -277,7 +277,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
// Record document being marked as draft.
|
// Record document being marked as draft.
|
||||||
if d.Lifecycle == workflow.LifecycleDraft {
|
if d.Lifecycle == workflow.LifecycleDraft {
|
||||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: d.LabelID,
|
SpaceID: d.SpaceID,
|
||||||
DocumentID: documentID,
|
DocumentID: documentID,
|
||||||
SourceType: activity.SourceTypeDocument,
|
SourceType: activity.SourceTypeDocument,
|
||||||
ActivityType: activity.TypeDraft})
|
ActivityType: activity.TypeDraft})
|
||||||
|
@ -286,7 +286,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
// Record document being marked as live.
|
// Record document being marked as live.
|
||||||
if d.Lifecycle == workflow.LifecycleLive {
|
if d.Lifecycle == workflow.LifecycleLive {
|
||||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: d.LabelID,
|
SpaceID: d.SpaceID,
|
||||||
DocumentID: documentID,
|
DocumentID: documentID,
|
||||||
SourceType: activity.SourceTypeDocument,
|
SourceType: activity.SourceTypeDocument,
|
||||||
ActivityType: activity.TypePublished})
|
ActivityType: activity.TypePublished})
|
||||||
|
@ -340,7 +340,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// If approval workflow then only approvers can delete page
|
// If approval workflow then only approvers can delete page
|
||||||
if doc.Protection == workflow.ProtectionReview {
|
if doc.Protection == workflow.ProtectionReview {
|
||||||
approvers, err := permission.GetUsersWithDocumentPermission(ctx, *h.Store, doc.LabelID, doc.RefID, pm.DocumentApprove)
|
approvers, err := permission.GetUsersWithDocumentPermission(ctx, *h.Store, doc.SpaceID, doc.RefID, pm.DocumentApprove)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
h.Runtime.Log.Error(method, err)
|
h.Runtime.Log.Error(method, err)
|
||||||
|
@ -389,7 +389,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||||
// Draft actions are not logged
|
// Draft actions are not logged
|
||||||
if doc.Lifecycle == workflow.LifecycleLive {
|
if doc.Lifecycle == workflow.LifecycleLive {
|
||||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: doc.LabelID,
|
SpaceID: doc.SpaceID,
|
||||||
DocumentID: documentID,
|
DocumentID: documentID,
|
||||||
SourceType: activity.SourceTypeDocument,
|
SourceType: activity.SourceTypeDocument,
|
||||||
ActivityType: activity.TypeDeleted})
|
ActivityType: activity.TypeDeleted})
|
||||||
|
@ -458,7 +458,7 @@ func (h *Handler) SearchDocuments(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: "",
|
SpaceID: "",
|
||||||
DocumentID: "",
|
DocumentID: "",
|
||||||
Metadata: options.Keywords,
|
Metadata: options.Keywords,
|
||||||
SourceType: activity.SourceTypeSearch,
|
SourceType: activity.SourceTypeSearch,
|
||||||
|
@ -504,7 +504,7 @@ func (h *Handler) recordSearchActivity(ctx domain.RequestContext, q []search.Que
|
||||||
|
|
||||||
if _, isExisting := prev[q[i].DocumentID]; !isExisting {
|
if _, isExisting := prev[q[i].DocumentID]; !isExisting {
|
||||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: q[i].SpaceID,
|
SpaceID: q[i].SpaceID,
|
||||||
DocumentID: q[i].DocumentID,
|
DocumentID: q[i].DocumentID,
|
||||||
Metadata: keywords,
|
Metadata: keywords,
|
||||||
SourceType: activity.SourceTypeSearch,
|
SourceType: activity.SourceTypeSearch,
|
||||||
|
@ -545,7 +545,7 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !permission.CanViewSpaceDocument(ctx, *h.Store, document.LabelID) {
|
if !permission.CanViewSpaceDocument(ctx, *h.Store, document.SpaceID) {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -557,9 +557,10 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// permissions
|
// permissions
|
||||||
perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, document.LabelID)
|
perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, document.SpaceID)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(perms) == 0 {
|
if len(perms) == 0 {
|
||||||
|
@ -570,6 +571,7 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) {
|
||||||
roles, err := h.Store.Permission.GetUserDocumentPermissions(ctx, document.RefID)
|
roles, err := h.Store.Permission.GetUserDocumentPermissions(ctx, document.RefID)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if len(roles) == 0 {
|
if len(roles) == 0 {
|
||||||
|
@ -629,7 +631,7 @@ func (h *Handler) FetchDocumentData(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if document.Lifecycle == workflow.LifecycleLive {
|
if document.Lifecycle == workflow.LifecycleLive {
|
||||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: document.LabelID,
|
SpaceID: document.SpaceID,
|
||||||
DocumentID: document.RefID,
|
DocumentID: document.RefID,
|
||||||
SourceType: activity.SourceTypeDocument,
|
SourceType: activity.SourceTypeDocument,
|
||||||
ActivityType: activity.TypeRead})
|
ActivityType: activity.TypeRead})
|
||||||
|
|
|
@ -153,7 +153,7 @@ func exportSpace(ctx domain.RequestContext, s domain.Store, spaceID string) (toc
|
||||||
for _, d := range docs {
|
for _, d := range docs {
|
||||||
docHTML, e := processDocument(ctx, s, d.RefID)
|
docHTML, e := processDocument(ctx, s, d.RefID)
|
||||||
if e == nil && len(docHTML) > 0 {
|
if e == nil && len(docHTML) > 0 {
|
||||||
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Title})
|
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Name})
|
||||||
b.WriteString(docHTML)
|
b.WriteString(docHTML)
|
||||||
} else {
|
} else {
|
||||||
return toc, b.String(), err
|
return toc, b.String(), err
|
||||||
|
@ -221,7 +221,7 @@ func exportCategory(ctx domain.RequestContext, s domain.Store, spaceID string, c
|
||||||
for _, d := range exportDocs {
|
for _, d := range exportDocs {
|
||||||
docHTML, e := processDocument(ctx, s, d.RefID)
|
docHTML, e := processDocument(ctx, s, d.RefID)
|
||||||
if e == nil && len(docHTML) > 0 {
|
if e == nil && len(docHTML) > 0 {
|
||||||
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Title})
|
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Name})
|
||||||
b.WriteString(docHTML)
|
b.WriteString(docHTML)
|
||||||
} else {
|
} else {
|
||||||
return toc, b.String(), err
|
return toc, b.String(), err
|
||||||
|
@ -274,7 +274,7 @@ func exportDocument(ctx domain.RequestContext, s domain.Store, spaceID string, d
|
||||||
if permission.CanViewDocument(ctx, s, d.RefID) {
|
if permission.CanViewDocument(ctx, s, d.RefID) {
|
||||||
docHTML, e := processDocument(ctx, s, d.RefID)
|
docHTML, e := processDocument(ctx, s, d.RefID)
|
||||||
if e == nil && len(docHTML) > 0 {
|
if e == nil && len(docHTML) > 0 {
|
||||||
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Title})
|
toc = append(toc, exportTOC{ID: d.RefID, Entry: d.Name})
|
||||||
b.WriteString(docHTML)
|
b.WriteString(docHTML)
|
||||||
} else {
|
} else {
|
||||||
return toc, b.String(), err
|
return toc, b.String(), err
|
||||||
|
@ -325,7 +325,7 @@ func processDocument(ctx domain.RequestContext, s domain.Store, documentID strin
|
||||||
// Put out document name.
|
// Put out document name.
|
||||||
b.WriteString(fmt.Sprintf("<div class='export-doc-header' id='%s'>", doc.RefID))
|
b.WriteString(fmt.Sprintf("<div class='export-doc-header' id='%s'>", doc.RefID))
|
||||||
b.WriteString("<div class='export-doc-title'>")
|
b.WriteString("<div class='export-doc-title'>")
|
||||||
b.WriteString(doc.Title)
|
b.WriteString(doc.Name)
|
||||||
b.WriteString("</div>")
|
b.WriteString("</div>")
|
||||||
b.WriteString("<div class='export-doc-excerpt'>")
|
b.WriteString("<div class='export-doc-excerpt'>")
|
||||||
b.WriteString(doc.Excerpt)
|
b.WriteString(doc.Excerpt)
|
||||||
|
@ -338,7 +338,7 @@ func processDocument(ctx domain.RequestContext, s domain.Store, documentID strin
|
||||||
b.WriteString(`<div class="document-structure">`)
|
b.WriteString(`<div class="document-structure">`)
|
||||||
b.WriteString(`<div class="page-header">`)
|
b.WriteString(`<div class="page-header">`)
|
||||||
b.WriteString(fmt.Sprintf("<span class='page-number'>%s</span>", page.Numbering))
|
b.WriteString(fmt.Sprintf("<span class='page-number'>%s</span>", page.Numbering))
|
||||||
b.WriteString(fmt.Sprintf("<span class='page-title'>%s</span>", page.Title))
|
b.WriteString(fmt.Sprintf("<span class='page-title'>%s</span>", page.Name))
|
||||||
b.WriteString("</div>")
|
b.WriteString("</div>")
|
||||||
b.WriteString("</div>")
|
b.WriteString("</div>")
|
||||||
|
|
||||||
|
|
|
@ -119,13 +119,14 @@ func (s Scope) GetBySpace(ctx domain.RequestContext, spaceID string) (documents
|
||||||
c_lifecycle AS lifecycle, c_versioned AS versioned, c_versionid AS versionid,
|
c_lifecycle AS lifecycle, c_versioned AS versioned, c_versionid AS versionid,
|
||||||
c_versionorder AS versionorder, c_groupid AS groupid, c_created AS created, c_revised AS revised
|
c_versionorder AS versionorder, c_groupid AS groupid, c_created AS created, c_revised AS revised
|
||||||
FROM dmz_doc
|
FROM dmz_doc
|
||||||
WHERE c_orgid=? AND c_template=0 AND c_spaceid IN (
|
WHERE c_orgid=? AND c_template=0 AND c_spaceid IN
|
||||||
(SELECT c_refid FROM dmz_space WHERE c_orgid=? AND c_refid IN
|
(SELECT c_refid FROM dmz_space WHERE c_orgid=? AND c_refid IN
|
||||||
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_location='space' AND c_refid=? AND c_refid IN
|
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_location='space' AND c_refid=? AND c_refid IN
|
||||||
(SELECT c_refid from dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space' AND c_action='view'
|
(SELECT c_refid from dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space' AND c_action='view'
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT p.c_refid from permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid WHERE p.c_orgid=?
|
SELECT p.c_refid from dmz_permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid WHERE p.c_orgid=?
|
||||||
AND p.c_who='role' AND p.c_location='space' AND p.c_refid=? AND p.c_action='view' AND (r.c_userid=? OR r.c_userid='0'))
|
AND p.c_who='role' AND p.c_location='space' AND p.c_refid=? AND p.c_action='view' AND (r.c_userid=? OR r.c_userid='0')
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
ORDER BY c_name, c_versionorder`,
|
ORDER BY c_name, c_versionorder`,
|
||||||
|
@ -154,9 +155,9 @@ func (s Scope) TemplatesBySpace(ctx domain.RequestContext, spaceID string) (docu
|
||||||
AND c_spaceid IN
|
AND c_spaceid IN
|
||||||
(SELECT c_refid FROM dmz_space WHERE c_orgid=? AND c_refid IN
|
(SELECT c_refid FROM dmz_space WHERE c_orgid=? AND c_refid IN
|
||||||
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_location='space' AND c_refid IN
|
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_location='space' AND c_refid IN
|
||||||
(SELECT c_refid from dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space' AND c_action='view'
|
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space' AND c_action='view'
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT p.refid from permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid WHERE p.c_orgid=? AND p.c_who='role' AND p.c_location='space' AND p.c_action='view' AND (r.c_userid=? OR r.c_userid='0'))
|
SELECT p.c_refid FROM dmz_permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid WHERE p.c_orgid=? AND p.c_who='role' AND p.c_location='space' AND p.c_action='view' AND (r.c_userid=? OR r.c_userid='0'))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
ORDER BY c_name`, ctx.OrgID, spaceID, ctx.OrgID, ctx.OrgID, ctx.OrgID, ctx.UserID, ctx.OrgID, ctx.UserID)
|
ORDER BY c_name`, ctx.OrgID, spaceID, ctx.OrgID, ctx.OrgID, ctx.OrgID, ctx.UserID, ctx.OrgID, ctx.UserID)
|
||||||
|
@ -311,23 +312,23 @@ func (s Scope) Delete(ctx domain.RequestContext, documentID string) (rows int64,
|
||||||
// Remove document pages, revisions, attachments, updates the search subsystem.
|
// Remove document pages, revisions, attachments, updates the search subsystem.
|
||||||
func (s Scope) DeleteBySpace(ctx domain.RequestContext, spaceID string) (rows int64, err error) {
|
func (s Scope) DeleteBySpace(ctx domain.RequestContext, spaceID string) (rows int64, err error) {
|
||||||
b := mysql.BaseQuery{}
|
b := mysql.BaseQuery{}
|
||||||
rows, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_section WHERE docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
rows, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_section WHERE _cdocid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_section_revision WHERE docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_section_revision WHERE c_docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_doc_attachment WHERE docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_doc_attachment WHERE c_docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_doc_vote WHERE docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
_, err = b.DeleteWhere(ctx.Transaction, fmt.Sprintf("DELETE FROM dmz_doc_vote WHERE c_docid IN (SELECT c_refid FROM dmz_doc WHERE c_spaceid=\"%s\" AND c_orgid=\"%s\")", spaceID, ctx.OrgID))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -346,7 +347,7 @@ func (s Scope) GetVersions(ctx domain.RequestContext, groupID string) (v []doc.V
|
||||||
v = []doc.Version{}
|
v = []doc.Version{}
|
||||||
|
|
||||||
err = s.Runtime.Db.Select(&v, `
|
err = s.Runtime.Db.Select(&v, `
|
||||||
SELECT versionid, refid as documentid
|
SELECT c_versionid AS versionid, c_refid as documentid
|
||||||
FROM dmz_doc
|
FROM dmz_doc
|
||||||
WHERE c_orgid=? AND c_groupid=?
|
WHERE c_orgid=? AND c_groupid=?
|
||||||
ORDER BY c_versionorder`, ctx.OrgID, groupID)
|
ORDER BY c_versionorder`, ctx.OrgID, groupID)
|
||||||
|
|
|
@ -68,7 +68,7 @@ func (s Scope) GetAll(ctx domain.RequestContext) (groups []group.Group, err erro
|
||||||
FROM dmz_group a
|
FROM dmz_group a
|
||||||
LEFT JOIN dmz_group_member b ON a.c_refid=b.c_groupid
|
LEFT JOIN dmz_group_member b ON a.c_refid=b.c_groupid
|
||||||
WHERE a.c_orgid=?
|
WHERE a.c_orgid=?
|
||||||
GROUP BY a.c_id, a.c_refid, a.c_orgid, a.c_name, a.c_desc, a.c_created, a.c_revised
|
GROUP BY a.id, a.c_refid, a.c_orgid, a.c_name, a.c_desc, a.c_created, a.c_revised
|
||||||
ORDER BY a.c_name`,
|
ORDER BY a.c_name`,
|
||||||
ctx.OrgID)
|
ctx.OrgID)
|
||||||
|
|
||||||
|
|
|
@ -80,11 +80,11 @@ func (h *Handler) GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
||||||
if p.RefID != pageID {
|
if p.RefID != pageID {
|
||||||
c := link.Candidate{
|
c := link.Candidate{
|
||||||
RefID: uniqueid.Generate(),
|
RefID: uniqueid.Generate(),
|
||||||
FolderID: folderID,
|
SpaceID: folderID,
|
||||||
DocumentID: documentID,
|
DocumentID: documentID,
|
||||||
TargetID: p.RefID,
|
TargetID: p.RefID,
|
||||||
LinkType: p.PageType,
|
LinkType: p.Type,
|
||||||
Title: p.Title,
|
Title: p.Name,
|
||||||
}
|
}
|
||||||
pc = append(pc, c)
|
pc = append(pc, c)
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ func (h *Handler) GetLinkCandidates(w http.ResponseWriter, r *http.Request) {
|
||||||
for _, f := range files {
|
for _, f := range files {
|
||||||
c := link.Candidate{
|
c := link.Candidate{
|
||||||
RefID: uniqueid.Generate(),
|
RefID: uniqueid.Generate(),
|
||||||
FolderID: folderID,
|
SpaceID: folderID,
|
||||||
DocumentID: documentID,
|
DocumentID: documentID,
|
||||||
TargetID: f.RefID,
|
TargetID: f.RefID,
|
||||||
LinkType: "file",
|
LinkType: "file",
|
||||||
|
|
|
@ -60,7 +60,7 @@ func getLink(t html.Token) (ok bool, link link.Link) {
|
||||||
case "data-link-id":
|
case "data-link-id":
|
||||||
link.RefID = strings.TrimSpace(a.Val)
|
link.RefID = strings.TrimSpace(a.Val)
|
||||||
case "data-link-space-id":
|
case "data-link-space-id":
|
||||||
link.FolderID = strings.TrimSpace(a.Val)
|
link.SpaceID = strings.TrimSpace(a.Val)
|
||||||
case "data-link-target-document-id":
|
case "data-link-target-document-id":
|
||||||
link.TargetDocumentID = strings.TrimSpace(a.Val)
|
link.TargetDocumentID = strings.TrimSpace(a.Val)
|
||||||
case "data-link-target-id":
|
case "data-link-target-id":
|
||||||
|
|
|
@ -37,7 +37,7 @@ func (s Scope) Add(ctx domain.RequestContext, l link.Link) (err error) {
|
||||||
l.Revised = time.Now().UTC()
|
l.Revised = time.Now().UTC()
|
||||||
|
|
||||||
_, err = ctx.Transaction.Exec("INSERT INTO dmz_doc_link (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) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
_, err = ctx.Transaction.Exec("INSERT INTO dmz_doc_link (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) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
l.RefID, l.OrgID, l.FolderID, l.UserID, l.SourceDocumentID, l.SourceSectionID, l.TargetDocumentID, l.TargetID, l.ExternalID, l.LinkType, l.Orphan, l.Created, l.Revised)
|
l.RefID, l.OrgID, l.SpaceID, l.UserID, l.SourceDocumentID, l.SourceSectionID, l.TargetDocumentID, l.TargetID, l.ExternalID, l.LinkType, l.Orphan, l.Created, l.Revised)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute link insert")
|
err = errors.Wrap(err, "execute link insert")
|
||||||
|
|
|
@ -166,7 +166,7 @@ func (h *Handler) Sitemap(w http.ResponseWriter, r *http.Request) {
|
||||||
for _, document := range documents {
|
for _, document := range documents {
|
||||||
var item sitemapItem
|
var item sitemapItem
|
||||||
item.URL = ctx.GetAppURL(fmt.Sprintf("s/%s/%s/d/%s/%s",
|
item.URL = ctx.GetAppURL(fmt.Sprintf("s/%s/%s/d/%s/%s",
|
||||||
document.FolderID, stringutil.MakeSlug(document.Folder), document.DocumentID, stringutil.MakeSlug(document.Document)))
|
document.SpaceID, stringutil.MakeSlug(document.Folder), document.DocumentID, stringutil.MakeSlug(document.Document)))
|
||||||
item.Date = document.Revised.Format("2006-01-02T15:04:05.999999-07:00")
|
item.Date = document.Revised.Format("2006-01-02T15:04:05.999999-07:00")
|
||||||
items = append(items, item)
|
items = append(items, item)
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ func (h *Handler) Sitemap(w http.ResponseWriter, r *http.Request) {
|
||||||
func (h *Handler) Reindex(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) Reindex(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := domain.GetRequestContext(r)
|
ctx := domain.GetRequestContext(r)
|
||||||
|
|
||||||
if !ctx.Global {
|
if !ctx.GlobalAdmin {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
h.Runtime.Log.Info(fmt.Sprintf("%s attempted search reindex"))
|
h.Runtime.Log.Info(fmt.Sprintf("%s attempted search reindex"))
|
||||||
return
|
return
|
||||||
|
@ -234,7 +234,7 @@ func (h *Handler) SearchStatus(w http.ResponseWriter, r *http.Request) {
|
||||||
method := "meta.SearchStatus"
|
method := "meta.SearchStatus"
|
||||||
ctx := domain.GetRequestContext(r)
|
ctx := domain.GetRequestContext(r)
|
||||||
|
|
||||||
if !ctx.Global {
|
if !ctx.GlobalAdmin {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
h.Runtime.Log.Info(fmt.Sprintf("%s attempted get of search status"))
|
h.Runtime.Log.Info(fmt.Sprintf("%s attempted get of search status"))
|
||||||
return
|
return
|
||||||
|
|
|
@ -147,7 +147,7 @@ func (h *Handler) SaveInstanceSetting(w http.ResponseWriter, r *http.Request) {
|
||||||
func (h *Handler) GetGlobalSetting(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) GetGlobalSetting(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := domain.GetRequestContext(r)
|
ctx := domain.GetRequestContext(r)
|
||||||
|
|
||||||
if !ctx.Global {
|
if !ctx.GlobalAdmin {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -163,7 +163,7 @@ func (h *Handler) SaveGlobalSetting(w http.ResponseWriter, r *http.Request) {
|
||||||
method := "org.SaveGlobalSetting"
|
method := "org.SaveGlobalSetting"
|
||||||
ctx := domain.GetRequestContext(r)
|
ctx := domain.GetRequestContext(r)
|
||||||
|
|
||||||
if !ctx.Global {
|
if !ctx.GlobalAdmin {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,13 +49,14 @@ func (s Scope) AddOrganization(ctx domain.RequestContext, org org.Organization)
|
||||||
|
|
||||||
// GetOrganization returns the Organization reocrod from the organization database table with the given id.
|
// GetOrganization returns the Organization reocrod from the organization database table with the given id.
|
||||||
func (s Scope) GetOrganization(ctx domain.RequestContext, id string) (org org.Organization, err error) {
|
func (s Scope) GetOrganization(ctx domain.RequestContext, id string) (org org.Organization, err error) {
|
||||||
stmt, err := s.Runtime.Db.Preparex(`SELECT id, c_refid as refid,
|
stmt, err := s.Runtime.Db.Preparex(`SELECT id, c_refid AS refid,
|
||||||
c_orgid as orgid, c_title as title, c_message as message, c_domain as domain,
|
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_service AS conversionendpoint, c_email AS email, c_serial AS serial, c_active AS active,
|
||||||
c_anonaccess as allowannonymousaccess, c_authprovider as authprovider,
|
c_anonaccess AS allowanonymousaccess, c_authprovider AS authprovider,
|
||||||
coalesce(c_authconfig,JSON_UNQUOTE('{}')) as authconfig, c_maxtags as maxtags,
|
coalesce(c_authconfig,JSON_UNQUOTE('{}')) AS authconfig, c_maxtags AS maxtags,
|
||||||
c_created as created, c_revised as revised
|
c_created AS created, c_revised AS revised
|
||||||
FROM dmz_org WHERE refid=?`)
|
FROM dmz_org
|
||||||
|
WHERE c_refid=?`)
|
||||||
defer streamutil.Close(stmt)
|
defer streamutil.Close(stmt)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -64,7 +65,6 @@ func (s Scope) GetOrganization(ctx domain.RequestContext, id string) (org org.Or
|
||||||
}
|
}
|
||||||
|
|
||||||
err = stmt.Get(&org, id)
|
err = stmt.Get(&org, id)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to get org %s", id))
|
err = errors.Wrap(err, fmt.Sprintf("unable to get org %s", id))
|
||||||
return
|
return
|
||||||
|
@ -86,26 +86,29 @@ func (s Scope) GetOrganizationByDomain(subdomain string) (o org.Organization, er
|
||||||
}
|
}
|
||||||
|
|
||||||
// match on given domain name
|
// match on given domain name
|
||||||
err = s.Runtime.Db.Get(&o, `SELECT id, c_refid as refid,
|
err = s.Runtime.Db.Get(&o, `SELECT id, c_refid AS refid,
|
||||||
c_orgid as orgid, c_title as title, c_message as message, c_domain as domain,
|
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_service AS conversionendpoint, c_email AS email, c_serial AS serial, c_active AS active,
|
||||||
c_anonaccess as allowannonymousaccess, c_authprovider as authprovider,
|
c_anonaccess AS allowanonymousaccess, c_authprovider AS authprovider,
|
||||||
coalesce(c_authconfig,JSON_UNQUOTE('{}')) as authconfig, c_maxtags as maxtags,
|
coalesce(c_authconfig,JSON_UNQUOTE('{}')) AS authconfig, c_maxtags AS maxtags,
|
||||||
c_created as created, c_revised as revised
|
c_created AS created, c_revised AS revised
|
||||||
FROM dmz_org WHERE c_domain=? AND c_active=1`, subdomain)
|
FROM dmz_org
|
||||||
|
WHERE c_domain=? AND c_active=1`, subdomain)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
fmt.Println(err)
|
||||||
err = nil
|
err = nil
|
||||||
|
|
||||||
// match on empty domain as last resort
|
// match on empty domain AS last resort
|
||||||
err = s.Runtime.Db.Get(&o, `SELECT id, c_refid as refid,
|
err = s.Runtime.Db.Get(&o, `SELECT id, c_refid AS refid,
|
||||||
c_orgid as orgid, c_title as title, c_message as message, c_domain as domain,
|
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_service AS conversionendpoint, c_email AS email, c_serial AS serial, c_active AS active,
|
||||||
c_anonaccess as allowannonymousaccess, c_authprovider as authprovider,
|
c_anonaccess AS allowanonymousaccess, c_authprovider AS authprovider,
|
||||||
coalesce(c_authconfig,JSON_UNQUOTE('{}')) as authconfig, c_maxtags as maxtags,
|
coalesce(c_authconfig,JSON_UNQUOTE('{}')) AS authconfig, c_maxtags AS maxtags,
|
||||||
c_created as created, c_revised as revised
|
c_created AS created, c_revised AS revised
|
||||||
FROM dmz_org WHERE c_domain='' AND c_active=1`)
|
FROM dmz_org
|
||||||
|
WHERE c_domain='' AND c_active=1`)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
err = errors.Wrap(err, "unable to execute select for empty subdomain")
|
err = errors.Wrap(err, "unable to execute select for empty subdomain")
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
pageID := uniqueid.Generate()
|
pageID := uniqueid.Generate()
|
||||||
model.Page.RefID = pageID
|
model.Page.RefID = pageID
|
||||||
model.Meta.PageID = pageID
|
model.Meta.SectionID = pageID
|
||||||
model.Meta.OrgID = ctx.OrgID // required for Render call below
|
model.Meta.OrgID = ctx.OrgID // required for Render call below
|
||||||
model.Meta.UserID = ctx.UserID // required for Render call below
|
model.Meta.UserID = ctx.UserID // required for Render call below
|
||||||
model.Page.SetDefaults()
|
model.Page.SetDefaults()
|
||||||
|
@ -160,16 +160,16 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(model.Page.BlockID) > 0 {
|
if len(model.Page.TemplateID) > 0 {
|
||||||
h.Store.Block.IncrementUsage(ctx, model.Page.BlockID)
|
h.Store.Block.IncrementUsage(ctx, model.Page.TemplateID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draft actions are not logged
|
// Draft actions are not logged
|
||||||
if doc.Lifecycle == workflow.LifecycleLive {
|
if doc.Lifecycle == workflow.LifecycleLive {
|
||||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: doc.LabelID,
|
SpaceID: doc.SpaceID,
|
||||||
DocumentID: model.Page.DocumentID,
|
DocumentID: model.Page.DocumentID,
|
||||||
PageID: model.Page.RefID,
|
SectionID: model.Page.RefID,
|
||||||
SourceType: activity.SourceTypePage,
|
SourceType: activity.SourceTypePage,
|
||||||
ActivityType: activity.TypeCreated})
|
ActivityType: activity.TypeCreated})
|
||||||
}
|
}
|
||||||
|
@ -438,9 +438,9 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
// Draft edits are not logged
|
// Draft edits are not logged
|
||||||
if doc.Lifecycle == workflow.LifecycleLive {
|
if doc.Lifecycle == workflow.LifecycleLive {
|
||||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: doc.LabelID,
|
SpaceID: doc.SpaceID,
|
||||||
DocumentID: model.Page.DocumentID,
|
DocumentID: model.Page.DocumentID,
|
||||||
PageID: model.Page.RefID,
|
SectionID: model.Page.RefID,
|
||||||
SourceType: activity.SourceTypePage,
|
SourceType: activity.SourceTypePage,
|
||||||
ActivityType: activity.TypeEdited})
|
ActivityType: activity.TypeEdited})
|
||||||
}
|
}
|
||||||
|
@ -462,7 +462,7 @@ func (h *Handler) Update(w http.ResponseWriter, r *http.Request) {
|
||||||
link.OrgID = ctx.OrgID
|
link.OrgID = ctx.OrgID
|
||||||
link.UserID = ctx.UserID
|
link.UserID = ctx.UserID
|
||||||
link.SourceDocumentID = model.Page.DocumentID
|
link.SourceDocumentID = model.Page.DocumentID
|
||||||
link.SourcePageID = model.Page.RefID
|
link.SourceSectionID = model.Page.RefID
|
||||||
|
|
||||||
if link.LinkType == "document" || link.LinkType == "network" {
|
if link.LinkType == "document" || link.LinkType == "network" {
|
||||||
link.TargetID = ""
|
link.TargetID = ""
|
||||||
|
@ -562,8 +562,8 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(p.BlockID) > 0 {
|
if len(p.TemplateID) > 0 {
|
||||||
h.Store.Block.DecrementUsage(ctx, p.BlockID)
|
h.Store.Block.DecrementUsage(ctx, p.TemplateID)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = h.Store.Page.Delete(ctx, documentID, pageID)
|
_, err = h.Store.Page.Delete(ctx, documentID, pageID)
|
||||||
|
@ -577,9 +577,9 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||||
// Draft actions are not logged
|
// Draft actions are not logged
|
||||||
if doc.Lifecycle == workflow.LifecycleLive {
|
if doc.Lifecycle == workflow.LifecycleLive {
|
||||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: doc.LabelID,
|
SpaceID: doc.SpaceID,
|
||||||
DocumentID: documentID,
|
DocumentID: documentID,
|
||||||
PageID: pageID,
|
SectionID: pageID,
|
||||||
SourceType: activity.SourceTypePage,
|
SourceType: activity.SourceTypePage,
|
||||||
ActivityType: activity.TypeDeleted})
|
ActivityType: activity.TypeDeleted})
|
||||||
}
|
}
|
||||||
|
@ -647,7 +647,7 @@ func (h *Handler) DeletePages(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, page := range *model {
|
for _, page := range *model {
|
||||||
pageData, err := h.Store.Page.Get(ctx, page.PageID)
|
pageData, err := h.Store.Page.Get(ctx, page.SectionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
ctx.Transaction.Rollback()
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
@ -670,11 +670,11 @@ func (h *Handler) DeletePages(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(pageData.BlockID) > 0 {
|
if len(pageData.TemplateID) > 0 {
|
||||||
h.Store.Block.DecrementUsage(ctx, pageData.BlockID)
|
h.Store.Block.DecrementUsage(ctx, pageData.TemplateID)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = h.Store.Page.Delete(ctx, documentID, page.PageID)
|
_, err = h.Store.Page.Delete(ctx, documentID, page.SectionID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
ctx.Transaction.Rollback()
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
@ -682,20 +682,20 @@ func (h *Handler) DeletePages(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
go h.Indexer.DeleteContent(ctx, page.PageID)
|
go h.Indexer.DeleteContent(ctx, page.SectionID)
|
||||||
|
|
||||||
h.Store.Link.DeleteSourcePageLinks(ctx, page.PageID)
|
h.Store.Link.DeleteSourcePageLinks(ctx, page.SectionID)
|
||||||
|
|
||||||
h.Store.Link.MarkOrphanPageLink(ctx, page.PageID)
|
h.Store.Link.MarkOrphanPageLink(ctx, page.SectionID)
|
||||||
|
|
||||||
h.Store.Page.DeletePageRevisions(ctx, page.PageID)
|
h.Store.Page.DeletePageRevisions(ctx, page.SectionID)
|
||||||
|
|
||||||
// Draft actions are not logged
|
// Draft actions are not logged
|
||||||
if doc.Lifecycle == workflow.LifecycleLive {
|
if doc.Lifecycle == workflow.LifecycleLive {
|
||||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: doc.LabelID,
|
SpaceID: doc.SpaceID,
|
||||||
DocumentID: documentID,
|
DocumentID: documentID,
|
||||||
PageID: page.PageID,
|
SectionID: page.SectionID,
|
||||||
SourceType: activity.SourceTypePage,
|
SourceType: activity.SourceTypePage,
|
||||||
ActivityType: activity.TypeDeleted})
|
ActivityType: activity.TypeDeleted})
|
||||||
}
|
}
|
||||||
|
@ -769,7 +769,7 @@ func (h *Handler) ChangePageSequence(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range *model {
|
for _, p := range *model {
|
||||||
err = h.Store.Page.UpdateSequence(ctx, documentID, p.PageID, p.Sequence)
|
err = h.Store.Page.UpdateSequence(ctx, documentID, p.SectionID, p.Sequence)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
ctx.Transaction.Rollback()
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
@ -838,7 +838,7 @@ func (h *Handler) ChangePageLevel(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, p := range *model {
|
for _, p := range *model {
|
||||||
err = h.Store.Page.UpdateLevel(ctx, documentID, p.PageID, p.Level)
|
err = h.Store.Page.UpdateLevel(ctx, documentID, p.SectionID, p.Level)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Transaction.Rollback()
|
ctx.Transaction.Rollback()
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
@ -932,7 +932,7 @@ func (h *Handler) Copy(w http.ResponseWriter, r *http.Request) {
|
||||||
p.DocumentID = targetID
|
p.DocumentID = targetID
|
||||||
p.UserID = ctx.UserID
|
p.UserID = ctx.UserID
|
||||||
pageMeta.DocumentID = targetID
|
pageMeta.DocumentID = targetID
|
||||||
pageMeta.PageID = newPageID
|
pageMeta.SectionID = newPageID
|
||||||
pageMeta.UserID = ctx.UserID
|
pageMeta.UserID = ctx.UserID
|
||||||
|
|
||||||
model := new(page.NewPage)
|
model := new(page.NewPage)
|
||||||
|
@ -954,16 +954,16 @@ func (h *Handler) Copy(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(model.Page.BlockID) > 0 {
|
if len(model.Page.TemplateID) > 0 {
|
||||||
h.Store.Block.IncrementUsage(ctx, model.Page.BlockID)
|
h.Store.Block.IncrementUsage(ctx, model.Page.TemplateID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log t actions are not logged
|
// Log t actions are not logged
|
||||||
if doc.Lifecycle == workflow.LifecycleLive {
|
if doc.Lifecycle == workflow.LifecycleLive {
|
||||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: doc.LabelID,
|
SpaceID: doc.SpaceID,
|
||||||
DocumentID: targetID,
|
DocumentID: targetID,
|
||||||
PageID: newPageID,
|
SectionID: newPageID,
|
||||||
SourceType: activity.SourceTypePage,
|
SourceType: activity.SourceTypePage,
|
||||||
ActivityType: activity.TypeCreated})
|
ActivityType: activity.TypeCreated})
|
||||||
}
|
}
|
||||||
|
@ -1215,9 +1215,9 @@ func (h *Handler) Rollback(w http.ResponseWriter, r *http.Request) {
|
||||||
// Draft actions are not logged
|
// Draft actions are not logged
|
||||||
if doc.Lifecycle == workflow.LifecycleLive {
|
if doc.Lifecycle == workflow.LifecycleLive {
|
||||||
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: doc.LabelID,
|
SpaceID: doc.SpaceID,
|
||||||
DocumentID: p.DocumentID,
|
DocumentID: p.DocumentID,
|
||||||
PageID: p.RefID,
|
SectionID: p.RefID,
|
||||||
SourceType: activity.SourceTypePage,
|
SourceType: activity.SourceTypePage,
|
||||||
ActivityType: activity.TypeReverted})
|
ActivityType: activity.TypeReverted})
|
||||||
}
|
}
|
||||||
|
@ -1290,7 +1290,7 @@ func (h *Handler) FetchPages(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// permissions
|
// permissions
|
||||||
perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, doc.LabelID)
|
perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, doc.SpaceID)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
return
|
return
|
||||||
|
@ -1344,7 +1344,7 @@ func (h *Handler) FetchPages(w http.ResponseWriter, r *http.Request) {
|
||||||
d.Page = p
|
d.Page = p
|
||||||
|
|
||||||
for _, m := range meta {
|
for _, m := range meta {
|
||||||
if p.RefID == m.PageID {
|
if p.RefID == m.SectionID {
|
||||||
d.Meta = m
|
d.Meta = m
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -1359,7 +1359,7 @@ func (h *Handler) FetchPages(w http.ResponseWriter, r *http.Request) {
|
||||||
ud.Page = up
|
ud.Page = up
|
||||||
|
|
||||||
for _, m := range meta {
|
for _, m := range meta {
|
||||||
if up.RefID == m.PageID {
|
if up.RefID == m.SectionID {
|
||||||
ud.Meta = m
|
ud.Meta = m
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -1413,7 +1413,7 @@ func (h *Handler) FetchPages(w http.ResponseWriter, r *http.Request) {
|
||||||
h.Runtime.Log.Error(method, err)
|
h.Runtime.Log.Error(method, err)
|
||||||
} else {
|
} else {
|
||||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: doc.LabelID,
|
SpaceID: doc.SpaceID,
|
||||||
DocumentID: doc.RefID,
|
DocumentID: doc.RefID,
|
||||||
Metadata: source, // deliberate
|
Metadata: source, // deliberate
|
||||||
SourceType: activity.SourceTypeSearch, // deliberate
|
SourceType: activity.SourceTypeSearch, // deliberate
|
||||||
|
@ -1450,7 +1450,7 @@ func (h *Handler) workflowPermitsChange(doc dm.Document, ctx domain.RequestConte
|
||||||
|
|
||||||
// If approval workflow then only approvers can delete page
|
// If approval workflow then only approvers can delete page
|
||||||
if doc.Protection == workflow.ProtectionReview {
|
if doc.Protection == workflow.ProtectionReview {
|
||||||
approvers, err := permission.GetUsersWithDocumentPermission(ctx, *h.Store, doc.LabelID, doc.RefID, pm.DocumentApprove)
|
approvers, err := permission.GetUsersWithDocumentPermission(ctx, *h.Store, doc.SpaceID, doc.RefID, pm.DocumentApprove)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.Runtime.Log.Error("workflowAllowsChange", err)
|
h.Runtime.Log.Error("workflowAllowsChange", err)
|
||||||
return false, err
|
return false, err
|
||||||
|
|
|
@ -58,10 +58,10 @@ func (s Scope) Add(ctx domain.RequestContext, model page.NewPage) (err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ctx.Transaction.Exec("INSERT INTO dmz_section (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) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
_, err = ctx.Transaction.Exec("INSERT INTO dmz_section (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) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
model.Page.RefID, model.Page.OrgID, model.Page.DocumentID, model.Page.UserID, model.Page.ContentType, model.Page.PageType, model.Page.Level, model.Page.Title, model.Page.Body, model.Page.Revisions, model.Page.Sequence, model.Page.BlockID, model.Page.Status, model.Page.RelativeID, model.Page.Created, model.Page.Revised)
|
model.Page.RefID, model.Page.OrgID, model.Page.DocumentID, model.Page.UserID, model.Page.ContentType, model.Page.Type, model.Page.Level, model.Page.Name, model.Page.Body, model.Page.Revisions, model.Page.Sequence, model.Page.TemplateID, model.Page.Status, model.Page.RelativeID, model.Page.Created, model.Page.Revised)
|
||||||
|
|
||||||
_, err = ctx.Transaction.Exec("INSERT INTO dmz_section_meta (c_sectionid, c_orgid, c_userid, c_docid, c_rawbody, c_config, c_external, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
_, err = ctx.Transaction.Exec("INSERT INTO dmz_section_meta (c_sectionid, c_orgid, c_userid, c_docid, c_rawbody, c_config, c_external, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
model.Meta.PageID, model.Meta.OrgID, model.Meta.UserID, model.Meta.DocumentID, model.Meta.RawBody, model.Meta.Config, model.Meta.ExternalSource, model.Meta.Created, model.Meta.Revised)
|
model.Meta.SectionID, model.Meta.OrgID, model.Meta.UserID, model.Meta.DocumentID, model.Meta.RawBody, model.Meta.Config, model.Meta.ExternalSource, model.Meta.Created, model.Meta.Revised)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute page meta insert")
|
err = errors.Wrap(err, "execute page meta insert")
|
||||||
|
@ -73,7 +73,9 @@ func (s Scope) Add(ctx domain.RequestContext, model page.NewPage) (err error) {
|
||||||
// Get returns the pageID page record from the page table.
|
// Get returns the pageID page record from the page table.
|
||||||
func (s Scope) Get(ctx domain.RequestContext, pageID string) (p page.Page, err error) {
|
func (s Scope) Get(ctx domain.RequestContext, pageID string) (p page.Page, err error) {
|
||||||
err = s.Runtime.Db.Get(&p, `
|
err = s.Runtime.Db.Get(&p, `
|
||||||
SELECT c_id, c_refid, c_orgid, c_docid, c_userid, c_contenttype, c_type, c_level, c_sequence, c_name, c_body, c_revisions, c_templateid, c_status, c_relativeid, c_created, c_revised
|
SELECT id, c_refid AS refid, c_orgid AS orgid, c_docid AS documentid, c_userid AS userid, c_contenttype AS contenttype, c_type AS type,
|
||||||
|
c_level AS level, c_sequence AS sequence, c_name AS name, c_body AS body, c_revisions AS revisions, c_templateid AS templateid,
|
||||||
|
c_status AS status, c_relativeid AS relativeid, c_created AS created, c_revised AS revised
|
||||||
FROM dmz_section
|
FROM dmz_section
|
||||||
WHERE c_orgid=? AND c_refid=?`,
|
WHERE c_orgid=? AND c_refid=?`,
|
||||||
ctx.OrgID, pageID)
|
ctx.OrgID, pageID)
|
||||||
|
@ -88,7 +90,9 @@ func (s Scope) Get(ctx domain.RequestContext, pageID string) (p page.Page, err e
|
||||||
// GetPages returns a slice containing all published page records for a given documentID, in presentation sequence.
|
// GetPages returns a slice containing all published page records for a given documentID, in presentation sequence.
|
||||||
func (s Scope) GetPages(ctx domain.RequestContext, documentID string) (p []page.Page, err error) {
|
func (s Scope) GetPages(ctx domain.RequestContext, documentID string) (p []page.Page, err error) {
|
||||||
err = s.Runtime.Db.Select(&p, `
|
err = s.Runtime.Db.Select(&p, `
|
||||||
SELECT c_id, c_refid, c_orgid, c_docid, c_userid, c_contenttype, c_type, c_level, c_sequence, c_name, c_body, c_revisions, c_templateid, c_status, c_relativeid, c_created, c_revised
|
SELECT id, c_refid AS refid, c_orgid AS orgid, c_docid AS documentid, c_userid AS userid, c_contenttype AS contenttype, c_type AS type,
|
||||||
|
c_level AS level, c_sequence AS sequence, c_name AS name, c_body AS body, c_revisions AS revisions, c_templateid AS templateid,
|
||||||
|
c_status AS status, c_relativeid AS relativeid, c_created AS created, c_revised AS revised
|
||||||
FROM dmz_section
|
FROM dmz_section
|
||||||
WHERE c_orgid=? AND c_docid=? AND (c_status=0 OR ((c_status=4 OR c_status=2) AND c_relativeid=''))
|
WHERE c_orgid=? AND c_docid=? AND (c_status=0 OR ((c_status=4 OR c_status=2) AND c_relativeid=''))
|
||||||
ORDER BY c_sequence`,
|
ORDER BY c_sequence`,
|
||||||
|
@ -104,7 +108,9 @@ func (s Scope) GetPages(ctx domain.RequestContext, documentID string) (p []page.
|
||||||
// GetUnpublishedPages returns a slice containing all published page records for a given documentID, in presentation sequence.
|
// GetUnpublishedPages returns a slice containing all published page records for a given documentID, in presentation sequence.
|
||||||
func (s Scope) GetUnpublishedPages(ctx domain.RequestContext, documentID string) (p []page.Page, err error) {
|
func (s Scope) GetUnpublishedPages(ctx domain.RequestContext, documentID string) (p []page.Page, err error) {
|
||||||
err = s.Runtime.Db.Select(&p, `
|
err = s.Runtime.Db.Select(&p, `
|
||||||
SELECT c_id, c_refid, c_orgid, c_docid, c_userid, c_contenttype, c_type, c_level, c_sequence, c_name, c_body, c_revisions, c_templateid, c_status, c_relativeid, c_created, c_revised
|
SELECT id, c_refid AS refid, c_orgid AS orgid, c_docid AS documentid, c_userid AS userid, c_contenttype AS contenttype, c_type AS type,
|
||||||
|
c_level AS level, c_sequence AS sequence, c_name AS name, c_body AS body, c_revisions AS revisions, c_templateid AS templateid,
|
||||||
|
c_status AS status, c_relativeid AS relativeid, c_created AS created, c_revised AS revised
|
||||||
FROM dmz_section
|
FROM dmz_section
|
||||||
WHERE c_orgid=? AND c_docid=? AND c_status!=0 AND c_relativeid!=''
|
WHERE c_orgid=? AND c_docid=? AND c_status!=0 AND c_relativeid!=''
|
||||||
ORDER BY c_sequence`,
|
ORDER BY c_sequence`,
|
||||||
|
@ -121,7 +127,9 @@ func (s Scope) GetUnpublishedPages(ctx domain.RequestContext, documentID string)
|
||||||
// but without the body field (which holds the HTML content).
|
// but without the body field (which holds the HTML content).
|
||||||
func (s Scope) GetPagesWithoutContent(ctx domain.RequestContext, documentID string) (pages []page.Page, err error) {
|
func (s Scope) GetPagesWithoutContent(ctx domain.RequestContext, documentID string) (pages []page.Page, err error) {
|
||||||
err = s.Runtime.Db.Select(&pages, `
|
err = s.Runtime.Db.Select(&pages, `
|
||||||
SELECT c_id, c_refid, c_orgid, c_docid, c_userid, c_contenttype, c_type, c_level, c_sequence, c_name, c_body, c_revisions, c_templateid, c_status, c_relativeid, c_created, c_revised
|
SELECT id, c_refid AS refid, c_orgid AS orgid, c_docid AS documentid, c_userid AS userid, c_contenttype AS contenttype, c_type AS type,
|
||||||
|
c_level AS level, c_sequence AS sequence, c_name AS name, c_revisions AS revisions, c_templateid AS templateid,
|
||||||
|
c_status AS status, c_relativeid AS relativeid, c_created AS created, c_revised AS revised
|
||||||
FROM dmz_section
|
FROM dmz_section
|
||||||
WHERE c_orgid=? AND c_docid=? AND c_status=0
|
WHERE c_orgid=? AND c_docid=? AND c_status=0
|
||||||
ORDER BY c_sequence`,
|
ORDER BY c_sequence`,
|
||||||
|
@ -145,9 +153,9 @@ func (s Scope) Update(ctx domain.RequestContext, page page.Page, refID, userID s
|
||||||
INSERT INTO dmz_section_revision
|
INSERT INTO dmz_section_revision
|
||||||
(c_refid, c_orgid, c_docid, c_ownerid, c_sectionid, c_userid, c_contenttype, c_type,
|
(c_refid, c_orgid, c_docid, c_ownerid, c_sectionid, c_userid, c_contenttype, c_type,
|
||||||
c_name, c_body, c_rawbody, c_config, c_created, c_revised)
|
c_name, c_body, c_rawbody, c_config, c_created, c_revised)
|
||||||
SELECT ? as refid, a.c_orgid, a.c_docid, a.c_userid as ownerid, a.c_refid as sectionid,
|
SELECT ? AS refid, a.c_orgid, a.c_docid, a.c_userid AS ownerid, a.c_refid AS sectionid,
|
||||||
? as userid, a.c_contenttype, a.c_type, a.c_name, a.c_body,
|
? AS userid, a.c_contenttype, a.c_type, a.c_name, a.c_body,
|
||||||
b.c_rawbody, b.c_config, ? as c_created, ? as c_revised
|
b.c_rawbody, b.c_config, ? AS c_created, ? As c_revised
|
||||||
FROM dmz_section a, dmz_section_meta b
|
FROM dmz_section a, dmz_section_meta b
|
||||||
WHERE a.c_refid=? AND a.c_refid=b.c_sectionid`,
|
WHERE a.c_refid=? AND a.c_refid=b.c_sectionid`,
|
||||||
refID, userID, time.Now().UTC(), time.Now().UTC(), page.RefID)
|
refID, userID, time.Now().UTC(), time.Now().UTC(), page.RefID)
|
||||||
|
@ -160,10 +168,10 @@ func (s Scope) Update(ctx domain.RequestContext, page page.Page, refID, userID s
|
||||||
|
|
||||||
// Update page
|
// Update page
|
||||||
_, err = ctx.Transaction.NamedExec(`UPDATE dmz_section SET
|
_, err = ctx.Transaction.NamedExec(`UPDATE dmz_section SET
|
||||||
docid=:documentid, level=:level, c_name=:name, body=:body,
|
c_docid=:documentid, c_level=:level, c_name=:name, c_body=:body,
|
||||||
c_revisions=:revisions, c_sequence=:sequence, c_status=:status,
|
c_revisions=:revisions, c_sequence=:sequence, c_status=:status,
|
||||||
c_relativeid=:relativeid, c_revised=:revised
|
c_relativeid=:relativeid, c_revised=:revised
|
||||||
WHERE orgid=:orgid AND refid=:refid`,
|
WHERE c_orgid=:orgid AND c_refid=:refid`,
|
||||||
&page)
|
&page)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -347,7 +355,7 @@ func (s Scope) GetPageRevision(ctx domain.RequestContext, revisionID string) (re
|
||||||
// GetPageRevisions returns a slice of page revision records for a given pageID, in the order they were created.
|
// GetPageRevisions returns a slice of page revision records for a given pageID, in the order they were created.
|
||||||
// Then audits that the get-page-revisions action has occurred.
|
// Then audits that the get-page-revisions action has occurred.
|
||||||
func (s Scope) GetPageRevisions(ctx domain.RequestContext, pageID string) (revisions []page.Revision, err error) {
|
func (s Scope) GetPageRevisions(ctx domain.RequestContext, pageID string) (revisions []page.Revision, err error) {
|
||||||
err = s.Runtime.Db.Select(&revisions, `SELECT a.c_id, a.c_refid AS refid,
|
err = s.Runtime.Db.Select(&revisions, `SELECT a.id, a.c_refid AS refid,
|
||||||
a.c_orgid AS orgid, a.c_docid AS documentid, a.c_ownerid AS ownerid, a.c_sectionid AS sectionid, a.c_userid AS userid,
|
a.c_orgid AS orgid, a.c_docid AS documentid, a.c_ownerid AS ownerid, a.c_sectionid AS sectionid, a.c_userid AS userid,
|
||||||
a.c_contenttype AS contenttype, a.c_type AS type, a.c_name AS name,
|
a.c_contenttype AS contenttype, a.c_type AS type, a.c_name AS name,
|
||||||
a.c_created AS created, a.c_revised AS revised,
|
a.c_created AS created, a.c_revised AS revised,
|
||||||
|
|
|
@ -333,6 +333,7 @@ func (h *Handler) GetUserSpacePermissions(w http.ResponseWriter, r *http.Request
|
||||||
perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, spaceID)
|
perms, err := h.Store.Permission.GetUserSpacePermissions(ctx, spaceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -354,6 +355,7 @@ func (h *Handler) GetCategoryViewers(w http.ResponseWriter, r *http.Request) {
|
||||||
u, err := h.Store.Permission.GetCategoryUsers(ctx, categoryID)
|
u, err := h.Store.Permission.GetCategoryUsers(ctx, categoryID)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
h.Runtime.Log.Error(method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -574,7 +576,7 @@ func (h *Handler) SetDocumentPermissions(w http.ResponseWriter, r *http.Request)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
sp, err := h.Store.Space.Get(ctx, doc.LabelID)
|
sp, err := h.Store.Space.Get(ctx, doc.SpaceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.WriteNotFoundError(w, method, "space not found")
|
response.WriteNotFoundError(w, method, "space not found")
|
||||||
return
|
return
|
||||||
|
@ -639,7 +641,7 @@ func (h *Handler) SetDocumentPermissions(w http.ResponseWriter, r *http.Request)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
url := ctx.GetAppURL(fmt.Sprintf("s/%s/%s/d/%s/%s", sp.RefID, stringutil.MakeSlug(sp.Name), doc.RefID, stringutil.MakeSlug(doc.Title)))
|
url := ctx.GetAppURL(fmt.Sprintf("s/%s/%s/d/%s/%s", sp.RefID, stringutil.MakeSlug(sp.Name), doc.RefID, stringutil.MakeSlug(doc.Name)))
|
||||||
|
|
||||||
// Permissions can be assigned to both groups and individual users.
|
// Permissions can be assigned to both groups and individual users.
|
||||||
// Pre-fetch users with group membership to help us work out
|
// Pre-fetch users with group membership to help us work out
|
||||||
|
@ -701,8 +703,8 @@ func (h *Handler) SetDocumentPermissions(w http.ResponseWriter, r *http.Request)
|
||||||
}
|
}
|
||||||
|
|
||||||
mailer := mail.Mailer{Runtime: h.Runtime, Store: h.Store, Context: ctx}
|
mailer := mail.Mailer{Runtime: h.Runtime, Store: h.Store, Context: ctx}
|
||||||
go mailer.DocumentApprover(existingUser.Email, inviter.Fullname(), inviter.Email, url, doc.Title)
|
go mailer.DocumentApprover(existingUser.Email, inviter.Fullname(), inviter.Email, url, doc.Name)
|
||||||
h.Runtime.Log.Info(fmt.Sprintf("%s has made %s document approver for: %s", inviter.Email, existingUser.Email, doc.Title))
|
h.Runtime.Log.Info(fmt.Sprintf("%s has made %s document approver for: %s", inviter.Email, existingUser.Email, doc.Name))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,14 +65,15 @@ func (s Scope) GetUserSpacePermissions(ctx domain.RequestContext, spaceID string
|
||||||
r = []permission.Permission{}
|
r = []permission.Permission{}
|
||||||
|
|
||||||
err = s.Runtime.Db.Select(&r, `
|
err = s.Runtime.Db.Select(&r, `
|
||||||
SELECT c_id, orgid, who, whoid, action, scope, location, refid
|
SELECT id, c_orgid AS orgid, c_who AS who, c_whoid AS whoid, c_action AS action,
|
||||||
|
c_scope AS scope, c_location AS location, c_refid AS refid
|
||||||
FROM dmz_permission
|
FROM dmz_permission
|
||||||
WHERE orgid=? AND location='space' AND refid=? AND who='user' AND (whoid=? OR whoid='0')
|
WHERE c_orgid=? AND c_location='space' AND c_refid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0')
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT p.id, p.orgid, p.who, p.whoid, p.action, p.scope, p.location, p.refid
|
SELECT p.id, p.c_orgid AS orgid, p.c_who AS who, p.c_whoid AS whoid, p.c_action AS action, p.c_scope AS scope, p.c_location AS location, p.c_refid AS refid
|
||||||
FROM dmz_permission p
|
FROM dmz_permission p
|
||||||
LEFT JOIN rolemember r ON p.whoid=r.roleid
|
LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid
|
||||||
WHERE p.orgid=? AND p.location='space' AND refid=? AND p.who='role' AND (r.userid=? OR r.userid='0')`,
|
WHERE p.c_orgid=? AND p.c_location='space' AND c_refid=? AND p.c_who='role' AND (r.c_userid=? OR r.c_userid='0')`,
|
||||||
ctx.OrgID, spaceID, ctx.UserID, ctx.OrgID, spaceID, ctx.UserID)
|
ctx.OrgID, spaceID, ctx.UserID, ctx.OrgID, spaceID, ctx.UserID)
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
|
@ -96,7 +97,7 @@ func (s Scope) GetSpacePermissionsForUser(ctx domain.RequestContext, spaceID, us
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT p.id, p.c_orgid AS orgid, p.c_who AS who, p.c_whoid AS whoid, p.c_action AS action, p.c_scope AS scope, p.c_location AS location, p.c_refid AS refid
|
SELECT p.id, p.c_orgid AS orgid, p.c_who AS who, p.c_whoid AS whoid, p.c_action AS action, p.c_scope AS scope, p.c_location AS location, p.c_refid AS refid
|
||||||
FROM dmz_permission p
|
FROM dmz_permission p
|
||||||
LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_roleid
|
LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid
|
||||||
WHERE p.c_orgid=? AND p.c_location='space' AND c_refid=? AND p.c_who='role' AND (r.c_userid=? OR r.c_userid='0')`,
|
WHERE p.c_orgid=? AND p.c_location='space' AND c_refid=? AND p.c_who='role' AND (r.c_userid=? OR r.c_userid='0')`,
|
||||||
ctx.OrgID, spaceID, userID, ctx.OrgID, spaceID, userID)
|
ctx.OrgID, spaceID, userID, ctx.OrgID, spaceID, userID)
|
||||||
|
|
||||||
|
@ -143,7 +144,7 @@ func (s Scope) GetCategoryPermissions(ctx domain.RequestContext, catID string) (
|
||||||
SELECT id, p.c_orgid AS orgid, p.c_who AS who, p.c_whoid AS whoid, p.c_action AS action, p.c_scope AS scope, p.c_location AS location, p.c_refid AS refid
|
SELECT id, p.c_orgid AS orgid, p.c_who AS who, p.c_whoid AS whoid, p.c_action AS action, p.c_scope AS scope, p.c_location AS location, p.c_refid AS refid
|
||||||
FROM dmz_permission p
|
FROM dmz_permission p
|
||||||
LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid
|
LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid
|
||||||
WHERE p.orgid=? AND p.location='category' AND p.who='role' AND (p.refid=? OR p.refid='0')`,
|
WHERE p.c_orgid=? AND p.c_location='category' AND p.c_who='role' AND (p.c_refid=? OR p.c_refid='0')`,
|
||||||
ctx.OrgID, catID, ctx.OrgID, catID)
|
ctx.OrgID, catID, ctx.OrgID, catID)
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
|
@ -195,7 +196,7 @@ func (s Scope) GetUserCategoryPermissions(ctx domain.RequestContext, userID stri
|
||||||
FROM dmz_permission
|
FROM dmz_permission
|
||||||
WHERE c_orgid=? AND c_location='category' AND c_who='user' AND (c_whoid=? OR c_whoid='0')
|
WHERE c_orgid=? AND c_location='category' AND c_who='user' AND (c_whoid=? OR c_whoid='0')
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT id, p.c_orgid AS orgid, p.c_who AS who, p.c_whoid AS whoid, p.c_action AS action, p.c_scope AS scope, p.c_location AS location, p.c_refid AS refid
|
SELECT p.id, p.c_orgid AS orgid, p.c_who AS who, p.c_whoid AS whoid, p.c_action AS action, p.c_scope AS scope, p.c_location AS location, p.c_refid AS refid
|
||||||
FROM dmz_permission p
|
FROM dmz_permission p
|
||||||
LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid
|
LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid
|
||||||
WHERE p.c_orgid=? AND p.c_location='category' AND p.c_who='role' AND (r.c_userid=? OR r.c_userid='0')`,
|
WHERE p.c_orgid=? AND p.c_location='category' AND p.c_who='role' AND (r.c_userid=? OR r.c_userid='0')`,
|
||||||
|
@ -219,7 +220,7 @@ func (s Scope) GetUserDocumentPermissions(ctx domain.RequestContext, documentID
|
||||||
FROM dmz_permission
|
FROM dmz_permission
|
||||||
WHERE c_orgid=? AND c_location='document' AND c_refid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0')
|
WHERE c_orgid=? AND c_location='document' AND c_refid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0')
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT id, p.c_orgid AS orgid, p.c_who AS who, p.c_whoid AS whoid, p.c_action AS action, p.c_scope AS scope, p.c_location AS location, p.c_refid AS refid
|
SELECT p.id, p.c_orgid AS orgid, p.c_who AS who, p.c_whoid AS whoid, p.c_action AS action, p.c_scope AS scope, p.c_location AS location, p.c_refid AS refid
|
||||||
FROM dmz_permission p
|
FROM dmz_permission p
|
||||||
LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid
|
LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid
|
||||||
WHERE p.c_orgid=? AND p.c_location='document' AND p.c_refid=? AND p.c_who='role' AND (r.c_userid=? OR r.c_userid='0')`,
|
WHERE p.c_orgid=? AND p.c_location='document' AND p.c_refid=? AND p.c_who='role' AND (r.c_userid=? OR r.c_userid='0')`,
|
||||||
|
|
|
@ -50,7 +50,7 @@ func CanViewDocument(ctx domain.RequestContext, s domain.Store, documentID strin
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
roles, err := s.Permission.GetUserSpacePermissions(ctx, document.LabelID)
|
roles, err := s.Permission.GetUserSpacePermissions(ctx, document.SpaceID)
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
err = nil
|
err = nil
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ func CanViewDocument(ctx domain.RequestContext, s domain.Store, documentID strin
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, role := range roles {
|
for _, role := range roles {
|
||||||
if role.RefID == document.LabelID && role.Location == pm.LocationSpace && role.Scope == pm.ScopeRow &&
|
if role.RefID == document.SpaceID && role.Location == pm.LocationSpace && role.Scope == pm.ScopeRow &&
|
||||||
pm.ContainsPermission(role.Action, pm.SpaceView, pm.SpaceManage, pm.SpaceOwner) {
|
pm.ContainsPermission(role.Action, pm.SpaceView, pm.SpaceManage, pm.SpaceOwner) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ func CanChangeDocument(ctx domain.RequestContext, s domain.Store, documentID str
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
roles, err := s.Permission.GetUserSpacePermissions(ctx, document.LabelID)
|
roles, err := s.Permission.GetUserSpacePermissions(ctx, document.SpaceID)
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
err = nil
|
err = nil
|
||||||
|
@ -89,7 +89,7 @@ func CanChangeDocument(ctx domain.RequestContext, s domain.Store, documentID str
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, role := range roles {
|
for _, role := range roles {
|
||||||
if role.RefID == document.LabelID && role.Location == pm.LocationSpace && role.Scope == pm.ScopeRow && role.Action == pm.DocumentEdit {
|
if role.RefID == document.SpaceID && role.Location == pm.LocationSpace && role.Scope == pm.ScopeRow && role.Action == pm.DocumentEdit {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ func CanDeleteDocument(ctx domain.RequestContext, s domain.Store, documentID str
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
roles, err := s.Permission.GetUserSpacePermissions(ctx, document.LabelID)
|
roles, err := s.Permission.GetUserSpacePermissions(ctx, document.SpaceID)
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
err = nil
|
err = nil
|
||||||
|
@ -118,7 +118,7 @@ func CanDeleteDocument(ctx domain.RequestContext, s domain.Store, documentID str
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, role := range roles {
|
for _, role := range roles {
|
||||||
if role.RefID == document.LabelID && role.Location == "space" && role.Scope == "object" && role.Action == pm.DocumentDelete {
|
if role.RefID == document.SpaceID && role.Location == "space" && role.Scope == "object" && role.Action == pm.DocumentDelete {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,9 +73,9 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
||||||
pin.RefID = uniqueid.Generate()
|
pin.RefID = uniqueid.Generate()
|
||||||
pin.OrgID = ctx.OrgID
|
pin.OrgID = ctx.OrgID
|
||||||
pin.UserID = ctx.UserID
|
pin.UserID = ctx.UserID
|
||||||
pin.Pin = strings.TrimSpace(pin.Pin)
|
pin.Name = strings.TrimSpace(pin.Name)
|
||||||
if len(pin.Pin) > 20 {
|
if len(pin.Name) > 20 {
|
||||||
pin.Pin = pin.Pin[0:20]
|
pin.Name = pin.Name[0:20]
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
ctx.Transaction, err = h.Runtime.Db.Beginx()
|
||||||
|
|
|
@ -55,7 +55,7 @@ func (s Scope) Add(ctx domain.RequestContext, pin pin.Pin) (err error) {
|
||||||
func (s Scope) GetPin(ctx domain.RequestContext, id string) (pin pin.Pin, err error) {
|
func (s Scope) GetPin(ctx domain.RequestContext, id string) (pin pin.Pin, err error) {
|
||||||
err = s.Runtime.Db.Get(&pin, `SELECT id, c_refid AS refid,
|
err = s.Runtime.Db.Get(&pin, `SELECT id, c_refid AS refid,
|
||||||
c_orgid AS orgid, c_userid AS userid, c_spaceid AS spaceid, c_docid AS documentid,
|
c_orgid AS orgid, c_userid AS userid, c_spaceid AS spaceid, c_docid AS documentid,
|
||||||
c_name AS pin, c_sequence AS sequence, c_created AS created, c_revised AS revised
|
c_name AS name, c_sequence AS sequence, c_created AS created, c_revised AS revised
|
||||||
FROM dmz_pin
|
FROM dmz_pin
|
||||||
WHERE c_orgid=? AND c_refid=?`,
|
WHERE c_orgid=? AND c_refid=?`,
|
||||||
ctx.OrgID, id)
|
ctx.OrgID, id)
|
||||||
|
@ -71,7 +71,7 @@ func (s Scope) GetPin(ctx domain.RequestContext, id string) (pin pin.Pin, err er
|
||||||
func (s Scope) GetUserPins(ctx domain.RequestContext, userID string) (pins []pin.Pin, err error) {
|
func (s Scope) GetUserPins(ctx domain.RequestContext, userID string) (pins []pin.Pin, err error) {
|
||||||
err = s.Runtime.Db.Select(&pins, `SELECT id, c_refid AS refid,
|
err = s.Runtime.Db.Select(&pins, `SELECT id, c_refid AS refid,
|
||||||
c_orgid AS orgid, c_userid AS userid, c_spaceid AS spaceid, c_docid AS documentid,
|
c_orgid AS orgid, c_userid AS userid, c_spaceid AS spaceid, c_docid AS documentid,
|
||||||
c_name AS pin, c_sequence AS sequence, c_created AS created, c_revised AS revised
|
c_name AS name, c_sequence AS sequence, c_created AS created, c_revised AS revised
|
||||||
FROM dmz_pin
|
FROM dmz_pin
|
||||||
WHERE c_orgid=? AND c_userid=?
|
WHERE c_orgid=? AND c_userid=?
|
||||||
ORDER BY c_sequence`,
|
ORDER BY c_sequence`,
|
||||||
|
|
|
@ -38,7 +38,7 @@ type Scope struct {
|
||||||
// searchable items. Any existing document entries are removed.
|
// searchable items. Any existing document entries are removed.
|
||||||
func (s Scope) IndexDocument(ctx domain.RequestContext, doc doc.Document, a []attachment.Attachment) (err error) {
|
func (s Scope) IndexDocument(ctx domain.RequestContext, doc doc.Document, a []attachment.Attachment) (err error) {
|
||||||
// remove previous search entries
|
// remove previous search entries
|
||||||
_, err = ctx.Transaction.Exec("DELETE FROM search WHERE orgid=? AND documentid=? AND (itemtype='doc' OR itemtype='file' OR itemtype='tag')",
|
_, err = ctx.Transaction.Exec("DELETE FROM dmz_search WHERE c_orgid=? AND c_docid=? AND (c_itemtype='doc' OR c_itemtype='file' OR c_itemtype='tag')",
|
||||||
ctx.OrgID, doc.RefID)
|
ctx.OrgID, doc.RefID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -46,8 +46,8 @@ func (s Scope) IndexDocument(ctx domain.RequestContext, doc doc.Document, a []at
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert doc title
|
// insert doc title
|
||||||
_, err = ctx.Transaction.Exec("INSERT INTO search (orgid, documentid, itemid, itemtype, content) VALUES (?, ?, ?, ?, ?)",
|
_, err = ctx.Transaction.Exec("INSERT INTO dmz_search (c_orgid, c_docid, c_itemid, c_itemtype, c_content) VALUES (?, ?, ?, ?, ?)",
|
||||||
ctx.OrgID, doc.RefID, "", "doc", doc.Title)
|
ctx.OrgID, doc.RefID, "", "doc", doc.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute insert document title entry")
|
err = errors.Wrap(err, "execute insert document title entry")
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ func (s Scope) IndexDocument(ctx domain.RequestContext, doc doc.Document, a []at
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ctx.Transaction.Exec("INSERT INTO search (orgid, documentid, itemid, itemtype, content) VALUES (?, ?, ?, ?, ?)",
|
_, err = ctx.Transaction.Exec("INSERT INTO dmz_search (c_orgid, c_docid, c_itemid, c_itemtype, c_content) VALUES (?, ?, ?, ?, ?)",
|
||||||
ctx.OrgID, doc.RefID, "", "tag", t)
|
ctx.OrgID, doc.RefID, "", "tag", t)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -69,7 +69,7 @@ func (s Scope) IndexDocument(ctx domain.RequestContext, doc doc.Document, a []at
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, file := range a {
|
for _, file := range a {
|
||||||
_, err = ctx.Transaction.Exec("INSERT INTO search (orgid, documentid, itemid, itemtype, content) VALUES (?, ?, ?, ?, ?)",
|
_, err = ctx.Transaction.Exec("INSERT INTO dmz_search (c_orgid, c_docid, c_itemid, c_itemtype, c_content) VALUES (?, ?, ?, ?, ?)",
|
||||||
ctx.OrgID, doc.RefID, file.RefID, "file", file.Filename)
|
ctx.OrgID, doc.RefID, file.RefID, "file", file.Filename)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -82,7 +82,7 @@ func (s Scope) IndexDocument(ctx domain.RequestContext, doc doc.Document, a []at
|
||||||
|
|
||||||
// DeleteDocument removes all search entries for document.
|
// DeleteDocument removes all search entries for document.
|
||||||
func (s Scope) DeleteDocument(ctx domain.RequestContext, ID string) (err error) {
|
func (s Scope) DeleteDocument(ctx domain.RequestContext, ID string) (err error) {
|
||||||
_, err = ctx.Transaction.Exec("DELETE FROM search WHERE orgid=? AND documentid=?", ctx.OrgID, ID)
|
_, err = ctx.Transaction.Exec("DELETE FROM dmz_search WHERE c_orgid=? AND c_docid=?", ctx.OrgID, ID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute delete document entries")
|
err = errors.Wrap(err, "execute delete document entries")
|
||||||
|
@ -100,7 +100,7 @@ func (s Scope) IndexContent(ctx domain.RequestContext, p page.Page) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove previous search entries
|
// remove previous search entries
|
||||||
_, err = ctx.Transaction.Exec("DELETE FROM search WHERE orgid=? AND documentid=? AND itemid=? AND itemtype='page'",
|
_, err = ctx.Transaction.Exec("DELETE FROM dmz_search WHERE c_orgid=? AND c_docid=? AND c_itemid=? AND c_itemtype='page'",
|
||||||
ctx.OrgID, p.DocumentID, p.RefID)
|
ctx.OrgID, p.DocumentID, p.RefID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -115,14 +115,14 @@ func (s Scope) IndexContent(ctx domain.RequestContext, p page.Page) (err error)
|
||||||
}
|
}
|
||||||
content = strings.TrimSpace(content)
|
content = strings.TrimSpace(content)
|
||||||
|
|
||||||
_, err = ctx.Transaction.Exec("INSERT INTO search (orgid, documentid, itemid, itemtype, content) VALUES (?, ?, ?, ?, ?)",
|
_, err = ctx.Transaction.Exec("INSERT INTO dmz_search (c_orgid, c_docid, c_itemid, c_itemtype, c_content) VALUES (?, ?, ?, ?, ?)",
|
||||||
ctx.OrgID, p.DocumentID, p.RefID, "page", content)
|
ctx.OrgID, p.DocumentID, p.RefID, "page", content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute insert document content entry")
|
err = errors.Wrap(err, "execute insert document content entry")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ctx.Transaction.Exec("INSERT INTO search (orgid, documentid, itemid, itemtype, content) VALUES (?, ?, ?, ?, ?)",
|
_, err = ctx.Transaction.Exec("INSERT INTO dmz_search (c_orgid, c_docid, c_itemid, c_itemtype, c_content) VALUES (?, ?, ?, ?, ?)",
|
||||||
ctx.OrgID, p.DocumentID, p.RefID, "page", p.Title)
|
ctx.OrgID, p.DocumentID, p.RefID, "page", p.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute insert document page title entry")
|
err = errors.Wrap(err, "execute insert document page title entry")
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ func (s Scope) IndexContent(ctx domain.RequestContext, p page.Page) (err error)
|
||||||
func (s Scope) DeleteContent(ctx domain.RequestContext, pageID string) (err error) {
|
func (s Scope) DeleteContent(ctx domain.RequestContext, pageID string) (err error) {
|
||||||
// remove all search entries
|
// remove all search entries
|
||||||
var stmt1 *sqlx.Stmt
|
var stmt1 *sqlx.Stmt
|
||||||
stmt1, err = ctx.Transaction.Preparex("DELETE FROM search WHERE orgid=? AND itemid=? AND itemtype=?")
|
stmt1, err = ctx.Transaction.Preparex("DELETE FROM dmz_search WHERE c_orgid=? AND c_itemid=? AND c_itemtype=?")
|
||||||
defer streamutil.Close(stmt1)
|
defer streamutil.Close(stmt1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "prepare delete document content entry")
|
err = errors.Wrap(err, "prepare delete document content entry")
|
||||||
|
@ -214,30 +214,30 @@ func (s Scope) Documents(ctx domain.RequestContext, q search.QueryOptions) (resu
|
||||||
func (s Scope) matchFullText(ctx domain.RequestContext, keywords, itemType string) (r []search.QueryResult, err error) {
|
func (s Scope) matchFullText(ctx domain.RequestContext, keywords, itemType string) (r []search.QueryResult, err error) {
|
||||||
sql1 := `
|
sql1 := `
|
||||||
SELECT
|
SELECT
|
||||||
s.id, s.orgid, s.documentid, s.itemid, s.itemtype,
|
s.id, s.c_orgid AS orgid, s.c_docid AS documentid, s.c_itemid AS itemid, s.c_itemtype AS itemtype,
|
||||||
d.labelid as spaceid, COALESCE(d.title,'Unknown') AS document, d.tags,
|
d.c_spaceid as spaceid, COALESCE(d.c_name,'Unknown') AS document, d.c_tags AS tags,
|
||||||
d.excerpt, d.template, d.versionid,
|
d.c_desc AS excerpt, d.c_template AS template, d.c_versionid AS versionid,
|
||||||
COALESCE(l.label,'Unknown') AS space
|
COALESCE(l.c_name,'Unknown') AS space
|
||||||
FROM
|
FROM
|
||||||
search s,
|
dmz_search s,
|
||||||
document d
|
dmz_doc d
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
label l ON l.orgid=d.orgid AND l.refid = d.labelid
|
dmz_space l ON l.c_orgid=d.c_orgid AND l.c_refid = d.c_spaceid
|
||||||
WHERE
|
WHERE
|
||||||
s.orgid = ?
|
s.c_orgid = ?
|
||||||
AND s.itemtype = ?
|
AND s.c_itemtype = ?
|
||||||
AND s.documentid = d.refid
|
AND s.c_docid = d.refid
|
||||||
AND d.labelid IN
|
AND d.c_spaceid IN
|
||||||
(
|
(
|
||||||
SELECT refid FROM label WHERE orgid=? AND refid IN
|
SELECT c_refid FROM dmz_space WHERE c_orgid=? AND c_refid IN
|
||||||
(
|
(
|
||||||
SELECT refid from permission WHERE orgid=? AND who='user' AND (whoid=? OR whoid='0') AND location='space'
|
SELECT c_refid from dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space'
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT p.refid from permission p LEFT JOIN rolemember r ON p.whoid=r.roleid WHERE p.orgid=? AND p.who='role'
|
SELECT p.c_refid from dmz_permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid WHERE p.c_orgid=? AND p.c_who='role'
|
||||||
AND p.location='space' AND (r.userid=? OR r.userid='0')
|
AND p.c_location='space' AND (r.c_userid=? OR r.c_userid='0')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
AND MATCH(s.content) AGAINST(? IN BOOLEAN MODE)`
|
AND MATCH(s.c_content) AGAINST(? IN BOOLEAN MODE)`
|
||||||
|
|
||||||
err = s.Runtime.Db.Select(&r,
|
err = s.Runtime.Db.Select(&r,
|
||||||
sql1,
|
sql1,
|
||||||
|
@ -270,30 +270,29 @@ func (s Scope) matchLike(ctx domain.RequestContext, keywords, itemType string) (
|
||||||
|
|
||||||
sql1 := `
|
sql1 := `
|
||||||
SELECT
|
SELECT
|
||||||
s.id, s.orgid, s.documentid, s.itemid, s.itemtype,
|
s.id, s.c_orgid AS orgid, s.c_docid AS documentid, s.c_itemid AS itemid, s.c_itemtype AS itemtype,
|
||||||
d.labelid as spaceid, COALESCE(d.title,'Unknown') AS document, d.tags, d.excerpt,
|
d.c_spaceid as spaceid, COALESCE(d.c_name,'Unknown') AS document, d.c_tags AS tags, d.c_desc AS excerpt,
|
||||||
COALESCE(l.label,'Unknown') AS space
|
COALESCE(l.c_name,'Unknown') AS space
|
||||||
FROM
|
FROM
|
||||||
search s,
|
dmz_search s,
|
||||||
document d
|
dmz_doc d
|
||||||
LEFT JOIN
|
LEFT JOIN
|
||||||
label l ON l.orgid=d.orgid AND l.refid = d.labelid
|
dmz_space l ON l.c_orgid=d.c_orgid AND l.c_refid = d.c_spaceid
|
||||||
WHERE
|
WHERE
|
||||||
s.orgid = ?
|
s.c_orgid = ?
|
||||||
AND s.itemtype = ?
|
AND s.c_itemtype = ?
|
||||||
AND s.documentid = d.refid
|
AND s.c_docid = d.c_refid
|
||||||
-- AND d.template = 0
|
AND d.c_spaceid IN
|
||||||
AND d.labelid IN
|
|
||||||
(
|
(
|
||||||
SELECT refid FROM label WHERE orgid=? AND refid IN
|
SELECT c_refid FROM dmz_space WHERE c_orgid=? AND c_refid IN
|
||||||
(
|
(
|
||||||
SELECT refid from permission WHERE orgid=? AND who='user' AND (whoid=? OR whoid='0') AND location='space'
|
SELECT c_refid from dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space'
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT p.refid from permission p LEFT JOIN rolemember r ON p.whoid=r.roleid WHERE p.orgid=? AND p.who='role'
|
SELECT p.c_refid from dmz_permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid WHERE p.c_orgid=? AND p.c_who='role'
|
||||||
AND p.location='space' AND (r.userid=? OR r.userid='0')
|
AND p.c_location='space' AND (r.c_userid=? OR r.c_userid='0')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
AND s.content LIKE ?`
|
AND s.c_content LIKE ?`
|
||||||
|
|
||||||
err = s.Runtime.Db.Select(&r,
|
err = s.Runtime.Db.Select(&r,
|
||||||
sql1,
|
sql1,
|
||||||
|
|
|
@ -111,7 +111,7 @@ func (h *Handler) RefreshSections(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
for _, pm := range meta {
|
for _, pm := range meta {
|
||||||
// Grab the page because we need content type and
|
// Grab the page because we need content type and
|
||||||
page, err2 := h.Store.Page.Get(ctx, pm.PageID)
|
page, err2 := h.Store.Page.Get(ctx, pm.SectionID)
|
||||||
if err2 == sql.ErrNoRows {
|
if err2 == sql.ErrNoRows {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ func (h *Handler) SMTP(w http.ResponseWriter, r *http.Request) {
|
||||||
method := "setting.SMTP"
|
method := "setting.SMTP"
|
||||||
ctx := domain.GetRequestContext(r)
|
ctx := domain.GetRequestContext(r)
|
||||||
|
|
||||||
if !ctx.Global {
|
if !ctx.GlobalAdmin {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ func (h *Handler) SetSMTP(w http.ResponseWriter, r *http.Request) {
|
||||||
method := "setting.SetSMTP"
|
method := "setting.SetSMTP"
|
||||||
ctx := domain.GetRequestContext(r)
|
ctx := domain.GetRequestContext(r)
|
||||||
|
|
||||||
if !ctx.Global {
|
if !ctx.GlobalAdmin {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -130,7 +130,7 @@ func (h *Handler) SetSMTP(w http.ResponseWriter, r *http.Request) {
|
||||||
func (h *Handler) License(w http.ResponseWriter, r *http.Request) {
|
func (h *Handler) License(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := domain.GetRequestContext(r)
|
ctx := domain.GetRequestContext(r)
|
||||||
|
|
||||||
if !ctx.Global {
|
if !ctx.GlobalAdmin {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -164,7 +164,7 @@ func (h *Handler) SetLicense(w http.ResponseWriter, r *http.Request) {
|
||||||
method := "setting.SetLicense"
|
method := "setting.SetLicense"
|
||||||
ctx := domain.GetRequestContext(r)
|
ctx := domain.GetRequestContext(r)
|
||||||
|
|
||||||
if !ctx.Global {
|
if !ctx.GlobalAdmin {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ func (h *Handler) AuthConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
method := "global.auth"
|
method := "global.auth"
|
||||||
ctx := domain.GetRequestContext(r)
|
ctx := domain.GetRequestContext(r)
|
||||||
|
|
||||||
if !ctx.Global {
|
if !ctx.GlobalAdmin {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ func (h *Handler) SetAuthConfig(w http.ResponseWriter, r *http.Request) {
|
||||||
method := "global.auth.save"
|
method := "global.auth.save"
|
||||||
ctx := domain.GetRequestContext(r)
|
ctx := domain.GetRequestContext(r)
|
||||||
|
|
||||||
if !ctx.Global {
|
if !ctx.GlobalAdmin {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@ func (s Scope) Get(area, path string) (value string, err error) {
|
||||||
path = "." + path
|
path = "." + path
|
||||||
}
|
}
|
||||||
|
|
||||||
sql := "SELECT JSON_EXTRACT(`config`,'$" + path + "') FROM `config` WHERE `key` = '" + area + "';"
|
sql := "SELECT JSON_EXTRACT(c_config,'$" + path + "') FROM dmz_config WHERE c_key = '" + area + "';"
|
||||||
|
|
||||||
var item = make([]uint8, 0)
|
var item = make([]uint8, 0)
|
||||||
|
|
||||||
|
@ -54,9 +54,9 @@ func (s Scope) Set(area, json string) (err error) {
|
||||||
return errors.New("no area")
|
return errors.New("no area")
|
||||||
}
|
}
|
||||||
|
|
||||||
sql := "INSERT INTO `config` (`key`,`config`) " +
|
sql := "INSERT INTO dmz_config (c_key,c_config) " +
|
||||||
"VALUES ('" + area + "','" + json +
|
"VALUES ('" + area + "','" + json +
|
||||||
"') ON DUPLICATE KEY UPDATE `config`='" + json + "';"
|
"') ON DUPLICATE KEY UPDATE c_config='" + json + "';"
|
||||||
|
|
||||||
_, err = s.Runtime.Db.Exec(sql)
|
_, err = s.Runtime.Db.Exec(sql)
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ func (s Scope) GetUser(orgID, userID, key, path string) (value string, err error
|
||||||
path = "." + path
|
path = "." + path
|
||||||
}
|
}
|
||||||
|
|
||||||
qry := "SELECT JSON_EXTRACT(`config`,'$" + path + "') FROM `userconfig` WHERE `key` = '" + key +
|
qry := "SELECT JSON_EXTRACT(c_config,'$" + path + "') FROM dmz_user_config WHERE c_key = '" + key +
|
||||||
"' AND `orgid` = '" + orgID + "' AND `userid` = '" + userID + "';"
|
"' AND c_orgid = '" + orgID + "' AND c_userid = '" + userID + "';"
|
||||||
|
|
||||||
err = s.Runtime.Db.Get(&item, qry)
|
err = s.Runtime.Db.Get(&item, qry)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
|
@ -101,13 +101,13 @@ func (s Scope) SetUser(orgID, userID, key, json string) (err error) {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec("DELETE FROM userconfig WHERE orgid=? AND userid=? AND `key`=?", orgID, userID, key)
|
_, err = tx.Exec("DELETE FROM dmz_user_config WHERE c_orgid=? AND c_userid=? AND c_key=?", orgID, userID, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
fmt.Println("ccc")
|
fmt.Println("ccc")
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = tx.Exec("INSERT INTO userconfig (orgid, userid, `key`, `config`) VALUES (?, ?, ?, ?)", orgID, userID, key, json)
|
_, err = tx.Exec("INSERT INTO dmz_user_config (c_orgid, c_userid, c_key, c_config) VALUES (?, ?, ?, ?)", orgID, userID, key, json)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
fmt.Println("ddd")
|
fmt.Println("ddd")
|
||||||
|
|
|
@ -131,7 +131,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: sp.RefID,
|
SpaceID: sp.RefID,
|
||||||
SourceType: activity.SourceTypeSpace,
|
SourceType: activity.SourceTypeSpace,
|
||||||
ActivityType: activity.TypeCreated})
|
ActivityType: activity.TypeCreated})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -210,7 +210,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
documentID := uniqueid.Generate()
|
documentID := uniqueid.Generate()
|
||||||
t.RefID = documentID
|
t.RefID = documentID
|
||||||
t.LabelID = sp.RefID
|
t.SpaceID = sp.RefID
|
||||||
|
|
||||||
// Reassign group ID
|
// Reassign group ID
|
||||||
if len(t.GroupID) > 0 {
|
if len(t.GroupID) > 0 {
|
||||||
|
@ -244,7 +244,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
||||||
pageID := uniqueid.Generate()
|
pageID := uniqueid.Generate()
|
||||||
p.RefID = pageID
|
p.RefID = pageID
|
||||||
|
|
||||||
meta.PageID = pageID
|
meta.SectionID = pageID
|
||||||
meta.DocumentID = documentID
|
meta.DocumentID = documentID
|
||||||
|
|
||||||
model := page.NewPage{}
|
model := page.NewPage{}
|
||||||
|
@ -287,7 +287,7 @@ func (h *Handler) Add(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
for _, b := range blocks {
|
for _, b := range blocks {
|
||||||
b.RefID = uniqueid.Generate()
|
b.RefID = uniqueid.Generate()
|
||||||
b.LabelID = sp.RefID
|
b.SpaceID = sp.RefID
|
||||||
b.UserID = ctx.UserID
|
b.UserID = ctx.UserID
|
||||||
|
|
||||||
err = h.Store.Block.Add(ctx, b)
|
err = h.Store.Block.Add(ctx, b)
|
||||||
|
@ -358,7 +358,7 @@ func (h *Handler) Get(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: sp.RefID,
|
SpaceID: sp.RefID,
|
||||||
SourceType: activity.SourceTypeSpace,
|
SourceType: activity.SourceTypeSpace,
|
||||||
ActivityType: activity.TypeRead})
|
ActivityType: activity.TypeRead})
|
||||||
|
|
||||||
|
@ -572,7 +572,7 @@ func (h *Handler) Remove(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: id,
|
SpaceID: id,
|
||||||
SourceType: activity.SourceTypeSpace,
|
SourceType: activity.SourceTypeSpace,
|
||||||
ActivityType: activity.TypeDeleted})
|
ActivityType: activity.TypeDeleted})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -669,7 +669,7 @@ func (h *Handler) Delete(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
err = h.Store.Activity.RecordUserActivity(ctx, activity.UserActivity{
|
||||||
LabelID: id,
|
SpaceID: id,
|
||||||
SourceType: activity.SourceTypeSpace,
|
SourceType: activity.SourceTypeSpace,
|
||||||
ActivityType: activity.TypeDeleted})
|
ActivityType: activity.TypeDeleted})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -47,10 +47,10 @@ func (s Scope) Add(ctx domain.RequestContext, sp space.Space) (err error) {
|
||||||
|
|
||||||
// Get returns a space from the store.
|
// Get returns a space from the store.
|
||||||
func (s Scope) Get(ctx domain.RequestContext, id string) (sp space.Space, err error) {
|
func (s Scope) Get(ctx domain.RequestContext, id string) (sp space.Space, err error) {
|
||||||
err = s.Runtime.Db.Get(&sp, `SELECT id, c_refid as refid,
|
err = s.Runtime.Db.Get(&sp, `SELECT id, c_refid AS refid,
|
||||||
c_name as name, c_orgid as orgid, c_userid as userid,
|
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_type AS type, c_lifecycle AS lifecycle, c_likes AS likes,
|
||||||
c_created as created, c_revised as revised
|
c_created AS created, c_revised AS revised
|
||||||
FROM dmz_space
|
FROM dmz_space
|
||||||
WHERE c_orgid=? and c_refid=?`,
|
WHERE c_orgid=? and c_refid=?`,
|
||||||
ctx.OrgID, id)
|
ctx.OrgID, id)
|
||||||
|
@ -64,10 +64,10 @@ func (s Scope) Get(ctx domain.RequestContext, id string) (sp space.Space, err er
|
||||||
|
|
||||||
// PublicSpaces returns spaces that anyone can see.
|
// PublicSpaces returns spaces that anyone can see.
|
||||||
func (s Scope) PublicSpaces(ctx domain.RequestContext, orgID string) (sp []space.Space, err error) {
|
func (s Scope) PublicSpaces(ctx domain.RequestContext, orgID string) (sp []space.Space, err error) {
|
||||||
qry := `SELECT id, c_refid as refid
|
qry := `SELECT id, c_refid AS refid,
|
||||||
c_name as name, c_orgid as orgid, c_userid as userid,
|
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_type AS type, c_lifecycle AS lifecycle, c_likes AS likes,
|
||||||
c_created as created, c_revised as revised
|
c_created AS created, c_revised AS revised
|
||||||
FROM dmz_space
|
FROM dmz_space
|
||||||
WHERE c_orgid=? AND c_type=1`
|
WHERE c_orgid=? AND c_type=1`
|
||||||
|
|
||||||
|
@ -88,16 +88,16 @@ func (s Scope) PublicSpaces(ctx domain.RequestContext, orgID string) (sp []space
|
||||||
// Also handles which spaces can be seen by anonymous users.
|
// Also handles which spaces can be seen by anonymous users.
|
||||||
func (s Scope) GetViewable(ctx domain.RequestContext) (sp []space.Space, err error) {
|
func (s Scope) GetViewable(ctx domain.RequestContext) (sp []space.Space, err error) {
|
||||||
q := `
|
q := `
|
||||||
SELECT id, c_refid as refid
|
SELECT id, c_refid AS refid,
|
||||||
c_name as name, c_orgid as orgid, c_userid as userid,
|
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_type AS type, c_lifecycle AS lifecycle, c_likes AS likes,
|
||||||
c_created as created, c_revised as revised
|
c_created AS created, c_revised AS revised
|
||||||
FROM dmz_space
|
FROM dmz_space
|
||||||
WHERE c_orgid=? AND c_refid IN
|
WHERE c_orgid=? AND c_refid IN
|
||||||
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_location='space' AND c_refid IN
|
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_location='space' AND c_refid IN
|
||||||
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space' AND c_action='view'
|
(SELECT c_refid FROM dmz_permission WHERE c_orgid=? AND c_who='user' AND (c_whoid=? OR c_whoid='0') AND c_location='space' AND c_action='view'
|
||||||
UNION ALL
|
UNION ALL
|
||||||
SELECT p.refid from dmz_permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid WHERE p.c_orgid=? AND p.c_who='role'
|
SELECT p.c_refid from dmz_permission p LEFT JOIN dmz_group_member r ON p.c_whoid=r.c_groupid WHERE p.c_orgid=? AND p.c_who='role'
|
||||||
AND p.c_location='space' AND p.c_action='view' AND (r.c_userid=? OR r.c_userid='0')
|
AND p.c_location='space' AND p.c_action='view' AND (r.c_userid=? OR r.c_userid='0')
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -125,10 +125,10 @@ func (s Scope) GetViewable(ctx domain.RequestContext) (sp []space.Space, err err
|
||||||
// GetAll for admin users!
|
// GetAll for admin users!
|
||||||
func (s Scope) GetAll(ctx domain.RequestContext) (sp []space.Space, err error) {
|
func (s Scope) GetAll(ctx domain.RequestContext) (sp []space.Space, err error) {
|
||||||
qry := `
|
qry := `
|
||||||
SELECT id, c_refid as refid
|
SELECT id, c_refid AS refid,
|
||||||
c_name as name, c_orgid as orgid, c_userid as userid,
|
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_type AS type, c_lifecycle AS lifecycle, c_likes AS likes,
|
||||||
c_created as created, c_revised as revised
|
c_created AS created, c_revised AS revised
|
||||||
FROM dmz_space
|
FROM dmz_space
|
||||||
WHERE c_orgid=?
|
WHERE c_orgid=?
|
||||||
ORDER BY c_name`
|
ORDER BY c_name`
|
||||||
|
|
|
@ -52,7 +52,7 @@ func (m *BaseQuery) DeleteConstrained(tx *sqlx.Tx, table string, orgID, id strin
|
||||||
|
|
||||||
// DeleteConstrainedWithID record constrained to Organization using non refid.
|
// DeleteConstrainedWithID record constrained to Organization using non refid.
|
||||||
func (m *BaseQuery) DeleteConstrainedWithID(tx *sqlx.Tx, table string, orgID, id string) (rows int64, err error) {
|
func (m *BaseQuery) DeleteConstrainedWithID(tx *sqlx.Tx, table string, orgID, id string) (rows int64, err error) {
|
||||||
result, err := tx.Exec("DELETE FROM "+table+" WHERE c_orgid=? AND c_id=?", orgID, id)
|
result, err := tx.Exec("DELETE FROM "+table+" WHERE c_orgid=? AND id=?", orgID, id)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to delete row in table %s", table))
|
err = errors.Wrap(err, fmt.Sprintf("unable to delete row in table %s", table))
|
||||||
|
|
|
@ -70,13 +70,13 @@ func (h *Handler) SavedList(w http.ResponseWriter, r *http.Request) {
|
||||||
for _, d := range documents {
|
for _, d := range documents {
|
||||||
var t = template.Template{}
|
var t = template.Template{}
|
||||||
t.ID = d.RefID
|
t.ID = d.RefID
|
||||||
t.Title = d.Title
|
t.Title = d.Name
|
||||||
t.Description = d.Excerpt
|
t.Description = d.Excerpt
|
||||||
t.Author = ""
|
t.Author = ""
|
||||||
t.Dated = d.Created
|
t.Dated = d.Created
|
||||||
t.Type = template.TypePrivate
|
t.Type = template.TypePrivate
|
||||||
|
|
||||||
if d.LabelID == folderID {
|
if d.SpaceID == folderID {
|
||||||
templates = append(templates, t)
|
templates = append(templates, t)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -123,7 +123,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !permission.HasPermission(ctx, *h.Store, doc.LabelID, pm.DocumentTemplate) {
|
if !permission.HasPermission(ctx, *h.Store, doc.SpaceID, pm.DocumentTemplate) {
|
||||||
response.WriteForbiddenError(w)
|
response.WriteForbiddenError(w)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
docID := uniqueid.Generate()
|
docID := uniqueid.Generate()
|
||||||
doc.Template = true
|
doc.Template = true
|
||||||
doc.Title = model.Name
|
doc.Name = model.Name
|
||||||
doc.Excerpt = model.Excerpt
|
doc.Excerpt = model.Excerpt
|
||||||
doc.RefID = docID
|
doc.RefID = docID
|
||||||
doc.ID = 0
|
doc.ID = 0
|
||||||
|
@ -170,7 +170,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
pageID := uniqueid.Generate()
|
pageID := uniqueid.Generate()
|
||||||
p.RefID = pageID
|
p.RefID = pageID
|
||||||
meta.PageID = pageID
|
meta.SectionID = pageID
|
||||||
meta.DocumentID = docID
|
meta.DocumentID = docID
|
||||||
|
|
||||||
m := page.NewPage{}
|
m := page.NewPage{}
|
||||||
|
@ -235,7 +235,7 @@ func (h *Handler) SaveAs(w http.ResponseWriter, r *http.Request) {
|
||||||
cc.CategoryID = c.RefID
|
cc.CategoryID = c.RefID
|
||||||
cc.RefID = uniqueid.Generate()
|
cc.RefID = uniqueid.Generate()
|
||||||
cc.DocumentID = docID
|
cc.DocumentID = docID
|
||||||
cc.LabelID = doc.LabelID
|
cc.SpaceID = doc.SpaceID
|
||||||
err = h.Store.Category.AssociateDocument(ctx, cc)
|
err = h.Store.Category.AssociateDocument(ctx, cc)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
@ -289,12 +289,12 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
// Define an empty document just in case user wanted one.
|
// Define an empty document just in case user wanted one.
|
||||||
var d = doc.Document{}
|
var d = doc.Document{}
|
||||||
d.Title = docTitle
|
d.Name = docTitle
|
||||||
d.Location = fmt.Sprintf("template-%s", templateID)
|
d.Location = fmt.Sprintf("template-%s", templateID)
|
||||||
d.Excerpt = "Add detailed description for document..."
|
d.Excerpt = "Add detailed description for document..."
|
||||||
d.Slug = stringutil.MakeSlug(d.Title)
|
d.Slug = stringutil.MakeSlug(d.Name)
|
||||||
d.Tags = ""
|
d.Tags = ""
|
||||||
d.LabelID = folderID
|
d.SpaceID = folderID
|
||||||
documentID := uniqueid.Generate()
|
documentID := uniqueid.Generate()
|
||||||
d.RefID = documentID
|
d.RefID = documentID
|
||||||
|
|
||||||
|
@ -338,9 +338,9 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
||||||
documentID = uniqueid.Generate()
|
documentID = uniqueid.Generate()
|
||||||
d.RefID = documentID
|
d.RefID = documentID
|
||||||
d.Template = false
|
d.Template = false
|
||||||
d.LabelID = folderID
|
d.SpaceID = folderID
|
||||||
d.UserID = ctx.UserID
|
d.UserID = ctx.UserID
|
||||||
d.Title = docTitle
|
d.Name = docTitle
|
||||||
|
|
||||||
if h.Runtime.Product.Edition == env.CommunityEdition {
|
if h.Runtime.Product.Edition == env.CommunityEdition {
|
||||||
d.Lifecycle = workflow.LifecycleLive
|
d.Lifecycle = workflow.LifecycleLive
|
||||||
|
@ -369,7 +369,7 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
||||||
pageID := uniqueid.Generate()
|
pageID := uniqueid.Generate()
|
||||||
p.RefID = pageID
|
p.RefID = pageID
|
||||||
|
|
||||||
meta.PageID = pageID
|
meta.SectionID = pageID
|
||||||
meta.DocumentID = documentID
|
meta.DocumentID = documentID
|
||||||
|
|
||||||
model := page.NewPage{}
|
model := page.NewPage{}
|
||||||
|
@ -418,7 +418,7 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
||||||
cc.CategoryID = c.RefID
|
cc.CategoryID = c.RefID
|
||||||
cc.RefID = uniqueid.Generate()
|
cc.RefID = uniqueid.Generate()
|
||||||
cc.DocumentID = d.RefID
|
cc.DocumentID = d.RefID
|
||||||
cc.LabelID = d.LabelID
|
cc.SpaceID = d.SpaceID
|
||||||
err = h.Store.Category.AssociateDocument(ctx, cc)
|
err = h.Store.Category.AssociateDocument(ctx, cc)
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
|
@ -437,7 +437,7 @@ func (h *Handler) Use(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
event.Handler().Publish(string(event.TypeAddDocument), nd.Title)
|
event.Handler().Publish(string(event.TypeAddDocument), nd.Name)
|
||||||
|
|
||||||
a, _ := h.Store.Attachment.GetAttachments(ctx, documentID)
|
a, _ := h.Store.Attachment.GetAttachments(ctx, documentID)
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ func (s Scope) Add(ctx domain.RequestContext, u user.User) (err error) {
|
||||||
u.Created = time.Now().UTC()
|
u.Created = time.Now().UTC()
|
||||||
u.Revised = time.Now().UTC()
|
u.Revised = time.Now().UTC()
|
||||||
|
|
||||||
_, err = ctx.Transaction.Exec("INSERT INTO user (refid, firstname, lastname, email, initials, password, salt, reset, lastversion, created, revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
_, err = ctx.Transaction.Exec("INSERT INTO dmz_user (c_refid, c_firstname, c_lastname, c_email, c_initials, c_password, c_salt, c_reset, c_lastversion, c_created, c_revised) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
|
||||||
u.RefID, u.Firstname, u.Lastname, strings.ToLower(u.Email), u.Initials, u.Password, u.Salt, "", u.LastVersion, u.Created, u.Revised)
|
u.RefID, u.Firstname, u.Lastname, strings.ToLower(u.Email), u.Initials, u.Password, u.Salt, "", u.LastVersion, u.Created, u.Revised)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -47,7 +47,13 @@ func (s Scope) Add(ctx domain.RequestContext, u user.User) (err error) {
|
||||||
|
|
||||||
// Get returns the user record for the given id.
|
// Get returns the user record for the given id.
|
||||||
func (s Scope) Get(ctx domain.RequestContext, id string) (u user.User, err error) {
|
func (s Scope) Get(ctx domain.RequestContext, id string) (u user.User, err error) {
|
||||||
err = s.Runtime.Db.Get(&u, "SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, lastversion, created, revised FROM user WHERE refid=?", id)
|
err = s.Runtime.Db.Get(&u, `
|
||||||
|
SELECT id, c_refid AS refid, c_firstname AS firstname, c_lastname AS lastname, c_email AS email,
|
||||||
|
c_initials AS initials, c_globaladmin AS globaladmin, c_password AS password, c_salt AS salt, c_reset AS reset,
|
||||||
|
c_lastversion AS lastversion, c_created AS created, c_revised AS revised
|
||||||
|
FROM dmz_user
|
||||||
|
WHERE c_refid=?`,
|
||||||
|
id)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("unable to execute select for user %s", id))
|
err = errors.Wrap(err, fmt.Sprintf("unable to execute select for user %s", id))
|
||||||
|
@ -60,7 +66,13 @@ func (s Scope) Get(ctx domain.RequestContext, id string) (u user.User, err error
|
||||||
func (s Scope) GetByDomain(ctx domain.RequestContext, domain, email string) (u user.User, err error) {
|
func (s Scope) GetByDomain(ctx domain.RequestContext, domain, email string) (u user.User, err error) {
|
||||||
email = strings.TrimSpace(strings.ToLower(email))
|
email = strings.TrimSpace(strings.ToLower(email))
|
||||||
|
|
||||||
err = s.Runtime.Db.Get(&u, "SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.global, u.password, u.salt, u.reset, u.lastversion, u.created, u.revised FROM user u, account a, organization o WHERE TRIM(LOWER(u.email))=? AND u.refid=a.userid AND a.orgid=o.refid AND TRIM(LOWER(o.domain))=?",
|
err = s.Runtime.Db.Get(&u, `SELECT u.id, u.c_refid AS refid,
|
||||||
|
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||||
|
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||||
|
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||||
|
u.c_created, u.c_revised
|
||||||
|
FROM dmz_user u, dmz_account a, dmz_org o
|
||||||
|
WHERE TRIM(LOWER(u.c_email))=? AND u.c_refid=a.c_userid AND a.c_orgid=o.c_refid AND TRIM(LOWER(o.c_domain))=?`,
|
||||||
email, domain)
|
email, domain)
|
||||||
|
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
|
@ -74,7 +86,14 @@ func (s Scope) GetByDomain(ctx domain.RequestContext, domain, email string) (u u
|
||||||
func (s Scope) GetByEmail(ctx domain.RequestContext, email string) (u user.User, err error) {
|
func (s Scope) GetByEmail(ctx domain.RequestContext, email string) (u user.User, err error) {
|
||||||
email = strings.TrimSpace(strings.ToLower(email))
|
email = strings.TrimSpace(strings.ToLower(email))
|
||||||
|
|
||||||
err = s.Runtime.Db.Get(&u, "SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, lastversion, created, revised FROM user WHERE TRIM(LOWER(email))=?", email)
|
err = s.Runtime.Db.Get(&u, `SELECT u.id, u.c_refid AS refid,
|
||||||
|
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||||
|
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||||
|
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||||
|
u.c_created, u.c_revised
|
||||||
|
FROM dmz_user
|
||||||
|
WHERE TRIM(LOWER(c_email))=?`,
|
||||||
|
email)
|
||||||
|
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute select user by email %s", email))
|
err = errors.Wrap(err, fmt.Sprintf("execute select user by email %s", email))
|
||||||
|
@ -85,7 +104,14 @@ func (s Scope) GetByEmail(ctx domain.RequestContext, email string) (u user.User,
|
||||||
|
|
||||||
// GetByToken returns a user record given a reset token value.
|
// GetByToken returns a user record given a reset token value.
|
||||||
func (s Scope) GetByToken(ctx domain.RequestContext, token string) (u user.User, err error) {
|
func (s Scope) GetByToken(ctx domain.RequestContext, token string) (u user.User, err error) {
|
||||||
err = s.Runtime.Db.Get(&u, "SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, lastversion, created, revised FROM user WHERE reset=?", token)
|
err = s.Runtime.Db.Get(&u, `SELECT u.id, u.c_refid AS refid,
|
||||||
|
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||||
|
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||||
|
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||||
|
u.c_created, u.c_revised
|
||||||
|
FROM dmz_user
|
||||||
|
WHERE c_reset=?`,
|
||||||
|
token)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute user select by token %s", token))
|
err = errors.Wrap(err, fmt.Sprintf("execute user select by token %s", token))
|
||||||
|
@ -98,7 +124,14 @@ func (s Scope) GetByToken(ctx domain.RequestContext, token string) (u user.User,
|
||||||
// This occurs when we you share a folder with a new user and they have to complete
|
// This occurs when we you share a folder with a new user and they have to complete
|
||||||
// the onboarding process.
|
// the onboarding process.
|
||||||
func (s Scope) GetBySerial(ctx domain.RequestContext, serial string) (u user.User, err error) {
|
func (s Scope) GetBySerial(ctx domain.RequestContext, serial string) (u user.User, err error) {
|
||||||
err = s.Runtime.Db.Get(&u, "SELECT id, refid, firstname, lastname, email, initials, global, password, salt, reset, lastversion, created, revised FROM user WHERE salt=?", serial)
|
err = s.Runtime.Db.Get(&u, `SELECT u.id, u.c_refid AS refid,
|
||||||
|
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||||
|
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||||
|
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||||
|
u.c_created, u.c_revised
|
||||||
|
FROM dmz_user
|
||||||
|
WHERE c_salt=?`,
|
||||||
|
serial)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute user select by serial %s", serial))
|
err = errors.Wrap(err, fmt.Sprintf("execute user select by serial %s", serial))
|
||||||
|
@ -112,12 +145,15 @@ func (s Scope) GetBySerial(ctx domain.RequestContext, serial string) (u user.Use
|
||||||
func (s Scope) GetActiveUsersForOrganization(ctx domain.RequestContext) (u []user.User, err error) {
|
func (s Scope) GetActiveUsersForOrganization(ctx domain.RequestContext) (u []user.User, err error) {
|
||||||
u = []user.User{}
|
u = []user.User{}
|
||||||
|
|
||||||
err = s.Runtime.Db.Select(&u,
|
err = s.Runtime.Db.Select(&u, `SELECT u.id, u.c_refid AS refid,
|
||||||
`SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.lastversion, u.created, u.revised,
|
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||||
u.global, a.active, a.editor, a.admin, a.users AS viewusers, a.analytics
|
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||||
FROM user u, account a
|
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||||
WHERE u.refid=a.userid AND a.orgid=? AND a.active=1
|
u.c_created, u.c_revised,
|
||||||
ORDER BY u.firstname,u.lastname`,
|
a.c_active AS active, a.c_editor AS editor, a.c_admin AS admin, a.c_users AS viewusers, a.c_analytics AS analytics
|
||||||
|
FROM dmz_user u, dmz_user_account a
|
||||||
|
WHERE u.c_refid=a.c_userid AND a.c_orgid=? AND a.c_active=1
|
||||||
|
ORDER BY u.c_firstname, u.c_lastname`,
|
||||||
ctx.OrgID)
|
ctx.OrgID)
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
|
@ -131,22 +167,25 @@ func (s Scope) GetActiveUsersForOrganization(ctx domain.RequestContext) (u []use
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUsersForOrganization returns a slice containing all of the user records for the organizaiton
|
// GetUsersForOrganization returns a slice containing all of the user records for the organizaiton
|
||||||
// identified in the Persister.
|
// identified in the context.
|
||||||
func (s Scope) GetUsersForOrganization(ctx domain.RequestContext, filter string, limit int) (u []user.User, err error) {
|
func (s Scope) GetUsersForOrganization(ctx domain.RequestContext, filter string, limit int) (u []user.User, err error) {
|
||||||
u = []user.User{}
|
u = []user.User{}
|
||||||
|
|
||||||
filter = strings.TrimSpace(strings.ToLower(filter))
|
filter = strings.TrimSpace(strings.ToLower(filter))
|
||||||
likeQuery := ""
|
likeQuery := ""
|
||||||
if len(filter) > 0 {
|
if len(filter) > 0 {
|
||||||
likeQuery = " AND (LOWER(u.firstname) LIKE '%" + filter + "%' OR LOWER(u.lastname) LIKE '%" + filter + "%' OR LOWER(u.email) LIKE '%" + filter + "%') "
|
likeQuery = " AND (LOWER(u.c_firstname) LIKE '%" + filter + "%' OR LOWER(u.c_lastname) LIKE '%" + filter + "%' OR LOWER(u.c_email) LIKE '%" + filter + "%') "
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.Runtime.Db.Select(&u,
|
err = s.Runtime.Db.Select(&u, `SELECT u.id, u.c_refid AS refid,
|
||||||
`SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.lastversion, u.created, u.revised,
|
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||||
u.global, a.active, a.editor, a.admin, a.users AS viewusers, a.analytics
|
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||||
FROM user u, account a
|
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||||
WHERE u.refid=a.userid AND a.orgid=? `+likeQuery+
|
u.c_created, u.c_revised,
|
||||||
`ORDER BY u.firstname, u.lastname LIMIT `+strconv.Itoa(limit), ctx.OrgID)
|
a.c_active AS active, a.c_editor AS editor, a.c_admin AS admin, a.c_users AS viewusers, a.c_analytics AS analytics
|
||||||
|
FROM dmz_user u, dmz_user_account a
|
||||||
|
WHERE u.c_refid=a.c_userid AND a.c_orgid=? `+likeQuery+
|
||||||
|
`ORDER BY u.c_firstname, u.c_lastname LIMIT `+strconv.Itoa(limit), ctx.OrgID)
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
err = nil
|
err = nil
|
||||||
|
@ -163,16 +202,20 @@ func (s Scope) GetUsersForOrganization(ctx domain.RequestContext, filter string,
|
||||||
func (s Scope) GetSpaceUsers(ctx domain.RequestContext, spaceID string) (u []user.User, err error) {
|
func (s Scope) GetSpaceUsers(ctx domain.RequestContext, spaceID string) (u []user.User, err error) {
|
||||||
u = []user.User{}
|
u = []user.User{}
|
||||||
|
|
||||||
err = s.Runtime.Db.Select(&u, `
|
err = s.Runtime.Db.Select(&u, `SELECT u.id, u.c_refid AS refid,
|
||||||
SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.created, u.lastversion, u.revised, u.global,
|
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||||
a.active, a.users AS viewusers, a.editor, a.admin, a.analytics
|
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||||
FROM user u, account a
|
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||||
WHERE a.orgid=? AND u.refid = a.userid AND a.active=1 AND u.refid IN (
|
u.c_created, u.c_revised,
|
||||||
SELECT whoid from permission WHERE orgid=? AND who='user' AND scope='object' AND location='space' AND refid=? UNION ALL
|
a.c_active AS active, a.c_editor AS editor, a.c_admin AS admin, a.c_users AS viewusers, a.c_analytics AS analytics
|
||||||
SELECT r.userid from rolemember r LEFT JOIN permission p ON p.whoid=r.roleid WHERE p.orgid=? AND p.who='role' AND p.scope='object' AND p.location='space' AND p.refid=?
|
FROM dmz_user u, dmz_user_account a
|
||||||
|
WHERE a.c_orgid=? AND u.c_refid = a.c_userid AND a.c_active=1 AND u.c_refid IN (
|
||||||
|
SELECT c_whoid from dmz_permission WHERE c_orgid=? AND c_who='user' AND c_scope='object' AND c_location='space' AND c_refid=?
|
||||||
|
UNION ALL
|
||||||
|
SELECT r.c_userid from dmz_group_member r LEFT JOIN dmz_permission p ON p.c_whoid=r.c_groupid WHERE p.c_orgid=? AND p.c_who='role' AND p.c_scope='object' AND p.c_location='space' AND p.c_refid=?
|
||||||
)
|
)
|
||||||
ORDER BY u.firstname, u.lastname
|
ORDER BY u.c_firstname, c_u.lastname`,
|
||||||
`, ctx.OrgID, ctx.OrgID, spaceID, ctx.OrgID, spaceID)
|
ctx.OrgID, ctx.OrgID, spaceID, ctx.OrgID, spaceID)
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
err = nil
|
err = nil
|
||||||
|
@ -193,15 +236,20 @@ func (s Scope) GetUsersForSpaces(ctx domain.RequestContext, spaces []string) (u
|
||||||
}
|
}
|
||||||
|
|
||||||
query, args, err := sqlx.In(`
|
query, args, err := sqlx.In(`
|
||||||
SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.lastversion, u.created, u.revised, u.global,
|
SELECT u.id, u.c_refid AS refid,
|
||||||
a.active, a.users AS viewusers, a.editor, a.admin, a.analytics
|
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||||
FROM user u, account a
|
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||||
WHERE a.orgid=? AND u.refid = a.userid AND a.active=1 AND u.refid IN (
|
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||||
SELECT whoid from permission WHERE orgid=? AND who='user' AND scope='object' AND location='space' AND refid IN(?) UNION ALL
|
u.c_created, u.c_revised,
|
||||||
SELECT r.userid from rolemember r LEFT JOIN permission p ON p.whoid=r.roleid WHERE p.orgid=? AND p.who='role' AND p.scope='object' AND p.location='space' AND p.refid IN(?)
|
a.c_active AS active, a.c_editor AS editor, a.c_admin AS admin, a.c_users AS viewusers, a.c_analytics AS analytics
|
||||||
|
FROM dmz_user u, dmz_user_account a
|
||||||
|
WHERE a.c_orgid=? AND u.c_refid = a.c_userid AND a.c_active=1 AND u.c_refid IN (
|
||||||
|
SELECT c_whoid from dmz_permission WHERE c_orgid=? AND c_who='user' AND c_scope='object' AND c_location='space' AND c_refid IN(?)
|
||||||
|
UNION ALL
|
||||||
|
SELECT r.c_userid from dmz_group_member r LEFT JOIN dmz_permission p ON p.c_whoid=r.c_groupid WHERE p.c_orgid=? AND p.c_who='role' AND p.c_scope='object' AND p.c_location='space' AND p.c_refid IN(?)
|
||||||
)
|
)
|
||||||
ORDER BY u.firstname, u.lastname
|
ORDER BY u.c_firstname, u.c_lastname`,
|
||||||
`, ctx.OrgID, ctx.OrgID, spaces, ctx.OrgID, spaces)
|
ctx.OrgID, ctx.OrgID, spaces, ctx.OrgID, spaces)
|
||||||
|
|
||||||
query = s.Runtime.Db.Rebind(query)
|
query = s.Runtime.Db.Rebind(query)
|
||||||
err = s.Runtime.Db.Select(&u, query, args...)
|
err = s.Runtime.Db.Select(&u, query, args...)
|
||||||
|
@ -221,9 +269,7 @@ func (s Scope) UpdateUser(ctx domain.RequestContext, u user.User) (err error) {
|
||||||
u.Revised = time.Now().UTC()
|
u.Revised = time.Now().UTC()
|
||||||
u.Email = strings.ToLower(u.Email)
|
u.Email = strings.ToLower(u.Email)
|
||||||
|
|
||||||
_, err = ctx.Transaction.NamedExec(
|
_, err = ctx.Transaction.NamedExec("UPDATE dmz_user SET c_firstname=:firstname, c_lastname=:lastname, c_email=:email, c_revised=:revised, c_initials=:initials, c_lastversion=:lastversion WHERE c_refid=:refid", &u)
|
||||||
"UPDATE user SET firstname=:firstname, lastname=:lastname, email=:email, revised=:revised, initials=:initials, lastversion=:lastversion WHERE refid=:refid", &u)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, fmt.Sprintf("execute user update %s", u.RefID))
|
err = errors.Wrap(err, fmt.Sprintf("execute user update %s", u.RefID))
|
||||||
}
|
}
|
||||||
|
@ -233,9 +279,7 @@ func (s Scope) UpdateUser(ctx domain.RequestContext, u user.User) (err error) {
|
||||||
|
|
||||||
// UpdateUserPassword updates a user record with new password and salt values.
|
// UpdateUserPassword updates a user record with new password and salt values.
|
||||||
func (s Scope) UpdateUserPassword(ctx domain.RequestContext, userID, salt, password string) (err error) {
|
func (s Scope) UpdateUserPassword(ctx domain.RequestContext, userID, salt, password string) (err error) {
|
||||||
_, err = ctx.Transaction.Exec("UPDATE user SET salt=?, password=?, reset='' WHERE refid=?",
|
_, err = ctx.Transaction.Exec("UPDATE dmz_user SET c_salt=?, c_password=?, c_reset='' WHERE c_refid=?", salt, password, userID)
|
||||||
salt, password, userID)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute user update")
|
err = errors.Wrap(err, "execute user update")
|
||||||
}
|
}
|
||||||
|
@ -245,8 +289,7 @@ func (s Scope) UpdateUserPassword(ctx domain.RequestContext, userID, salt, passw
|
||||||
|
|
||||||
// DeactiveUser deletes the account record for the given userID and persister.Context.OrgID.
|
// DeactiveUser deletes the account record for the given userID and persister.Context.OrgID.
|
||||||
func (s Scope) DeactiveUser(ctx domain.RequestContext, userID string) (err error) {
|
func (s Scope) DeactiveUser(ctx domain.RequestContext, userID string) (err error) {
|
||||||
_, err = ctx.Transaction.Exec("DELETE FROM account WHERE userid=? and orgid=?", userID, ctx.OrgID)
|
_, err = ctx.Transaction.Exec("DELETE FROM dmz_user_account WHERE c_userid=? and c_orgid=?", userID, ctx.OrgID)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute user deactivation")
|
err = errors.Wrap(err, "execute user deactivation")
|
||||||
}
|
}
|
||||||
|
@ -256,8 +299,7 @@ func (s Scope) DeactiveUser(ctx domain.RequestContext, userID string) (err error
|
||||||
|
|
||||||
// ForgotUserPassword sets the password to '' and the reset field to token, for a user identified by email.
|
// ForgotUserPassword sets the password to '' and the reset field to token, for a user identified by email.
|
||||||
func (s Scope) ForgotUserPassword(ctx domain.RequestContext, email, token string) (err error) {
|
func (s Scope) ForgotUserPassword(ctx domain.RequestContext, email, token string) (err error) {
|
||||||
_, err = ctx.Transaction.Exec("UPDATE user SET reset=?, password='' WHERE LOWER(email)=?", token, strings.ToLower(email))
|
_, err = ctx.Transaction.Exec("UPDATE dmz_user SET c_reset=?, c_password='' WHERE LOWER(c_email)=?", token, strings.ToLower(email))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(err, "execute password reset")
|
err = errors.Wrap(err, "execute password reset")
|
||||||
}
|
}
|
||||||
|
@ -267,10 +309,9 @@ func (s Scope) ForgotUserPassword(ctx domain.RequestContext, email, token string
|
||||||
|
|
||||||
// CountActiveUsers returns the number of active users in the system.
|
// CountActiveUsers returns the number of active users in the system.
|
||||||
func (s Scope) CountActiveUsers() (c int) {
|
func (s Scope) CountActiveUsers() (c int) {
|
||||||
row := s.Runtime.Db.QueryRow("SELECT count(*) FROM user u WHERE u.refid IN (SELECT userid FROM account WHERE active=1)")
|
row := s.Runtime.Db.QueryRow("SELECT count(*) FROM dmz_user WHERE c_refid IN (SELECT c_userid FROM dmz_user_account WHERE active=1)")
|
||||||
|
|
||||||
err := row.Scan(&c)
|
err := row.Scan(&c)
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
@ -290,15 +331,18 @@ func (s Scope) MatchUsers(ctx domain.RequestContext, text string, maxMatches int
|
||||||
text = strings.TrimSpace(strings.ToLower(text))
|
text = strings.TrimSpace(strings.ToLower(text))
|
||||||
likeQuery := ""
|
likeQuery := ""
|
||||||
if len(text) > 0 {
|
if len(text) > 0 {
|
||||||
likeQuery = " AND (LOWER(firstname) LIKE '%" + text + "%' OR LOWER(lastname) LIKE '%" + text + "%' OR LOWER(email) LIKE '%" + text + "%') "
|
likeQuery = " AND (LOWER(c_firstname) LIKE '%" + text + "%' OR LOWER(c_lastname) LIKE '%" + text + "%' OR LOWER(c_email) LIKE '%" + text + "%') "
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.Runtime.Db.Select(&u,
|
err = s.Runtime.Db.Select(&u,
|
||||||
`SELECT u.id, u.refid, u.firstname, u.lastname, u.email, u.initials, u.password, u.salt, u.reset, u.lastversion, u.created, u.revised,
|
`SELECT u.id, u.c_refid AS refid,
|
||||||
u.global, a.active, a.editor, a.admin, a.users AS viewusers, a.analytics
|
u.c_firstname AS firstname, u.c_lastname AS lastname, u.c_email AS email,
|
||||||
FROM user u, account a
|
u.c_initials AS initials, u.c_globaladmin AS globaladmin,
|
||||||
WHERE a.orgid=? AND u.refid=a.userid AND a.active=1 `+likeQuery+
|
u.c_password AS password, u.c_salt AS salt, u.c_reset AS reset, u.c_lastversion AS lastversion,
|
||||||
`ORDER BY u.firstname,u.lastname LIMIT `+strconv.Itoa(maxMatches),
|
u.c_created, u.c_revised,
|
||||||
|
a.c_active AS active, a.c_editor AS editor, a.c_admin AS admin, a.c_users AS viewusers, a.c_analytics AS analytics
|
||||||
|
FROM dmz_user u, dmz_user_account a
|
||||||
|
WHERE a.c_orgid=? AND u.c_refid=a.c_userid AND a.c_active=1 `+likeQuery+` ORDER BY u.c_firstname, u.c_lastname LIMIT `+strconv.Itoa(maxMatches),
|
||||||
ctx.OrgID)
|
ctx.OrgID)
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
|
|
|
@ -165,7 +165,7 @@ func (p MySQLProvider) QueryMeta() string {
|
||||||
|
|
||||||
// QueryStartLock locks database tables.
|
// QueryStartLock locks database tables.
|
||||||
func (p MySQLProvider) QueryStartLock() string {
|
func (p MySQLProvider) QueryStartLock() string {
|
||||||
return "LOCK TABLE `config` WRITE;"
|
return "LOCK TABLE dmz_config WRITE;"
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryFinishLock unlocks database tables.
|
// QueryFinishLock unlocks database tables.
|
||||||
|
@ -176,18 +176,26 @@ func (p MySQLProvider) QueryFinishLock() string {
|
||||||
// QueryInsertProcessID returns database specific query that will
|
// QueryInsertProcessID returns database specific query that will
|
||||||
// insert ID of this running process.
|
// insert ID of this running process.
|
||||||
func (p MySQLProvider) QueryInsertProcessID() string {
|
func (p MySQLProvider) QueryInsertProcessID() string {
|
||||||
return "INSERT INTO `config` (`key`,`config`) " + fmt.Sprintf(`VALUES ('DBLOCK','{"pid": "%d"}');`, os.Getpid())
|
return "INSERT INTO dmz_config (c_key,c_config) " + fmt.Sprintf(`VALUES ('DBLOCK','{"pid": "%d"}');`, os.Getpid())
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryDeleteProcessID returns database specific query that will
|
// QueryDeleteProcessID returns database specific query that will
|
||||||
// delete ID of this running process.
|
// delete ID of this running process.
|
||||||
func (p MySQLProvider) QueryDeleteProcessID() string {
|
func (p MySQLProvider) QueryDeleteProcessID() string {
|
||||||
return "DELETE FROM `config` WHERE `key`='DBLOCK';"
|
return "DELETE FROM dmz_config WHERE c_key='DBLOCK';"
|
||||||
}
|
}
|
||||||
|
|
||||||
// QueryRecordVersionUpgrade returns database specific insert statement
|
// QueryRecordVersionUpgrade returns database specific insert statement
|
||||||
// that records the database version number.
|
// that records the database version number.
|
||||||
func (p MySQLProvider) QueryRecordVersionUpgrade(version int) string {
|
func (p MySQLProvider) QueryRecordVersionUpgrade(version int) string {
|
||||||
|
// Make record that holds new database version number.
|
||||||
|
json := fmt.Sprintf("{\"database\": \"%d\"}", version)
|
||||||
|
return "INSERT INTO dmz_config (c_key,c_config) " + "VALUES ('META','" + json + "') ON DUPLICATE KEY UPDATE c_config='" + json + "';"
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryRecordVersionUpgradeLegacy returns database specific insert statement
|
||||||
|
// that records the database version number.
|
||||||
|
func (p MySQLProvider) QueryRecordVersionUpgradeLegacy(version int) string {
|
||||||
// Make record that holds new database version number.
|
// Make record that holds new database version number.
|
||||||
json := fmt.Sprintf("{\"database\": \"%d\"}", version)
|
json := fmt.Sprintf("{\"database\": \"%d\"}", version)
|
||||||
return "INSERT INTO `config` (`key`,`config`) " + "VALUES ('META','" + json + "') ON DUPLICATE KEY UPDATE `config`='" + json + "';"
|
return "INSERT INTO `config` (`key`,`config`) " + "VALUES ('META','" + json + "') ON DUPLICATE KEY UPDATE `config`='" + json + "';"
|
||||||
|
@ -195,6 +203,11 @@ func (p MySQLProvider) QueryRecordVersionUpgrade(version int) string {
|
||||||
|
|
||||||
// QueryGetDatabaseVersion returns the schema version number.
|
// QueryGetDatabaseVersion returns the schema version number.
|
||||||
func (p MySQLProvider) QueryGetDatabaseVersion() string {
|
func (p MySQLProvider) QueryGetDatabaseVersion() string {
|
||||||
|
return "SELECT JSON_EXTRACT(c_config,'$.database') FROM dmz_config WHERE c_key = 'META';"
|
||||||
|
}
|
||||||
|
|
||||||
|
// QueryGetDatabaseVersionLegacy returns the schema version number before The Great Schema Migration (v25, MySQL).
|
||||||
|
func (p MySQLProvider) QueryGetDatabaseVersionLegacy() string {
|
||||||
return "SELECT JSON_EXTRACT(`config`,'$.database') FROM `config` WHERE `key` = 'META';"
|
return "SELECT JSON_EXTRACT(`config`,'$.database') FROM `config` WHERE `key` = 'META';"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +218,7 @@ func (p MySQLProvider) QueryTableList() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
// VerfiyVersion checks to see if actual database meets
|
// VerfiyVersion checks to see if actual database meets
|
||||||
// minimum version requirements.
|
// minimum version requirements.``
|
||||||
func (p MySQLProvider) VerfiyVersion(dbVersion string) (bool, string) {
|
func (p MySQLProvider) VerfiyVersion(dbVersion string) (bool, string) {
|
||||||
// Minimum MySQL / MariaDB version.
|
// Minimum MySQL / MariaDB version.
|
||||||
minVer := []int{5, 7, 10}
|
minVer := []int{5, 7, 10}
|
||||||
|
|
1328
embed/bindata.go
1328
embed/bindata.go
File diff suppressed because one or more lines are too long
|
@ -20,7 +20,7 @@ type Block struct {
|
||||||
SpaceID string `json:"folderId"`
|
SpaceID string `json:"folderId"`
|
||||||
UserID string `json:"userId"`
|
UserID string `json:"userId"`
|
||||||
ContentType string `json:"contentType"`
|
ContentType string `json:"contentType"`
|
||||||
PageType string `json:"pageType"`
|
Type string `json:"pageType"`
|
||||||
Name string `json:"title"`
|
Name string `json:"title"`
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
Excerpt string `json:"excerpt"`
|
Excerpt string `json:"excerpt"`
|
||||||
|
|
|
@ -90,7 +90,7 @@ type UploadModel struct {
|
||||||
type SitemapDocument struct {
|
type SitemapDocument struct {
|
||||||
DocumentID string
|
DocumentID string
|
||||||
Document string
|
Document string
|
||||||
FolderID string
|
SpaceID string
|
||||||
Folder string
|
Folder string
|
||||||
Revised time.Time
|
Revised time.Time
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ import "github.com/documize/community/model"
|
||||||
type Link struct {
|
type Link struct {
|
||||||
model.BaseEntity
|
model.BaseEntity
|
||||||
OrgID string `json:"orgId"`
|
OrgID string `json:"orgId"`
|
||||||
FolderID string `json:"folderId"`
|
SpaceID string `json:"folderId"`
|
||||||
UserID string `json:"userId"`
|
UserID string `json:"userId"`
|
||||||
LinkType string `json:"linkType"`
|
LinkType string `json:"linkType"`
|
||||||
SourceDocumentID string `json:"sourceDocumentId"`
|
SourceDocumentID string `json:"sourceDocumentId"`
|
||||||
|
|
|
@ -71,7 +71,7 @@ func Numberize(pages []Page) {
|
||||||
// Troubleshooting help
|
// Troubleshooting help
|
||||||
if len(numbering) == 0 {
|
if len(numbering) == 0 {
|
||||||
fmt.Println(fmt.Sprintf("No number allocated to page %s ('%s')",
|
fmt.Println(fmt.Sprintf("No number allocated to page %s ('%s')",
|
||||||
pages[i].RefID, pages[i].Title))
|
pages[i].RefID, pages[i].Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
// update state
|
// update state
|
||||||
|
|
|
@ -31,7 +31,7 @@ type User struct {
|
||||||
Admin bool `json:"admin"`
|
Admin bool `json:"admin"`
|
||||||
ViewUsers bool `json:"viewUsers"`
|
ViewUsers bool `json:"viewUsers"`
|
||||||
Analytics bool `json:"analytics"`
|
Analytics bool `json:"analytics"`
|
||||||
Global bool `json:"global"`
|
GlobalAdmin bool `json:"global"`
|
||||||
Password string `json:"-"`
|
Password string `json:"-"`
|
||||||
Salt string `json:"-"`
|
Salt string `json:"-"`
|
||||||
Reset string `json:"-"`
|
Reset string `json:"-"`
|
||||||
|
|
|
@ -142,7 +142,7 @@ func (m *middleware) Authorize(w http.ResponseWriter, r *http.Request, next http
|
||||||
rc.Administrator = false
|
rc.Administrator = false
|
||||||
rc.Analytics = false
|
rc.Analytics = false
|
||||||
rc.Editor = false
|
rc.Editor = false
|
||||||
rc.Global = false
|
rc.GlobalAdmin = false
|
||||||
rc.ViewUsers = false
|
rc.ViewUsers = false
|
||||||
rc.AppURL = r.Host
|
rc.AppURL = r.Host
|
||||||
rc.Subdomain = organization.GetSubdomainFromHost(r)
|
rc.Subdomain = organization.GetSubdomainFromHost(r)
|
||||||
|
@ -166,6 +166,7 @@ func (m *middleware) Authorize(w http.ResponseWriter, r *http.Request, next http
|
||||||
if rc.Authenticated {
|
if rc.Authenticated {
|
||||||
u, err := user.GetSecuredUser(rc, *m.Store, org.RefID, rc.UserID)
|
u, err := user.GetSecuredUser(rc, *m.Store, org.RefID, rc.UserID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
m.Runtime.Log.Error("unable to secure API", err)
|
||||||
response.WriteServerError(w, method, err)
|
response.WriteServerError(w, method, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -174,7 +175,7 @@ func (m *middleware) Authorize(w http.ResponseWriter, r *http.Request, next http
|
||||||
rc.Active = u.Active
|
rc.Active = u.Active
|
||||||
rc.Analytics = u.Analytics
|
rc.Analytics = u.Analytics
|
||||||
rc.Editor = u.Editor
|
rc.Editor = u.Editor
|
||||||
rc.Global = u.Global
|
rc.GlobalAdmin = u.GlobalAdmin
|
||||||
rc.ViewUsers = u.ViewUsers
|
rc.ViewUsers = u.ViewUsers
|
||||||
rc.Fullname = u.Fullname()
|
rc.Fullname = u.Fullname()
|
||||||
|
|
||||||
|
@ -245,7 +246,7 @@ func (m *middleware) preAuthorizeStaticAssets(rt *env.Runtime, r *http.Request)
|
||||||
ctx.Administrator = false
|
ctx.Administrator = false
|
||||||
ctx.Editor = false
|
ctx.Editor = false
|
||||||
ctx.Analytics = false
|
ctx.Analytics = false
|
||||||
ctx.Global = false
|
ctx.GlobalAdmin = false
|
||||||
ctx.AppURL = r.Host
|
ctx.AppURL = r.Host
|
||||||
ctx.SSL = r.TLS != nil
|
ctx.SSL = r.TLS != nil
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue