mirror of
https://github.com/documize/community.git
synced 2025-07-24 15:49:44 +02:00
Make Sitemap & Robots.txt use new schema
This commit is contained in:
parent
4f0cc2f616
commit
d67767fcfc
4 changed files with 46 additions and 45 deletions
|
@ -131,7 +131,7 @@ func setupAccount(rt *env.Runtime, completion onboardRequest, serial string) (er
|
|||
// Allocate organization to the user.
|
||||
orgID := uniqueid.Generate()
|
||||
|
||||
sql := fmt.Sprintf("insert into organization (refid, company, title, message, domain, email, serial) values (\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\")",
|
||||
sql := fmt.Sprintf("insert into dmz_org (c_refid, c_company, c_title, c_message, c_domain, c_email, c_serial) VALUES (\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\")",
|
||||
orgID, completion.Company, completion.CompanyLong, completion.Message, completion.URL, completion.Email, serial)
|
||||
_, err = runSQL(rt, sql)
|
||||
|
||||
|
@ -142,7 +142,7 @@ func setupAccount(rt *env.Runtime, completion onboardRequest, serial string) (er
|
|||
|
||||
userID := uniqueid.Generate()
|
||||
|
||||
sql = fmt.Sprintf("insert into user (refid, firstname, lastname, email, initials, salt, password, global) values (\"%s\",\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", 1)",
|
||||
sql = fmt.Sprintf("INSERT INTO dmz_user (c_refid, c_firstname, c_lastname, c_email, c_initials, c_salt, c_password, c_globaladmin) VALUES (\"%s\",\"%s\", \"%s\", \"%s\", \"%s\", \"%s\", \"%s\", 1)",
|
||||
userID, completion.Firstname, completion.Lastname, completion.Email, stringutil.MakeInitials(completion.Firstname, completion.Lastname), salt, password)
|
||||
_, err = runSQL(rt, sql)
|
||||
|
||||
|
@ -153,7 +153,7 @@ func setupAccount(rt *env.Runtime, completion onboardRequest, serial string) (er
|
|||
|
||||
// Link user to organization.
|
||||
accountID := uniqueid.Generate()
|
||||
sql = fmt.Sprintf("insert into account (refid, userid, orgid, `admin`, editor, users, analytics) values (\"%s\", \"%s\", \"%s\", 1, 1, 1, 1)", accountID, userID, orgID)
|
||||
sql = fmt.Sprintf("INSERT INTO dmz_user_account (c_refid, c_userid, c_orgid, c_admin, c_editor, c_users, c_analytics) VALUES (\"%s\", \"%s\", \"%s\", 1, 1, 1, 1)", accountID, userID, orgID)
|
||||
_, err = runSQL(rt, sql)
|
||||
|
||||
if err != nil {
|
||||
|
@ -163,59 +163,59 @@ func setupAccount(rt *env.Runtime, completion onboardRequest, serial string) (er
|
|||
|
||||
// create space
|
||||
labelID := uniqueid.Generate()
|
||||
sql = fmt.Sprintf("insert into label (refid, orgid, label, type, userid) values (\"%s\", \"%s\", \"My Project\", 2, \"%s\")", labelID, orgID, userID)
|
||||
sql = fmt.Sprintf("INSERT INTO dmz_space (c_refid, c_orgid, c_name, c_type, c_userid) VALUES (\"%s\", \"%s\", \"My Project\", 2, \"%s\")", labelID, orgID, userID)
|
||||
_, err = runSQL(rt, sql)
|
||||
if err != nil {
|
||||
rt.Log.Error("insert into label failed", err)
|
||||
rt.Log.Error("INSERT INTO label failed", err)
|
||||
}
|
||||
|
||||
// assign permissions to space
|
||||
perms := []string{"view", "manage", "own", "doc-add", "doc-edit", "doc-delete", "doc-move", "doc-copy", "doc-template", "doc-approve", "doc-version", "doc-lifecycle"}
|
||||
for _, p := range perms {
|
||||
sql = fmt.Sprintf("insert into permission (orgid, who, whoid, action, scope, location, refid) values (\"%s\", 'user', \"%s\", \"%s\", 'object', 'space', \"%s\")", orgID, userID, p, labelID)
|
||||
sql = fmt.Sprintf("INSERT INTO dmz_permission (c_orgid, c_who, c_whoid, c_action, c_scope, c_location, c_refid) VALUES (\"%s\", 'user', \"%s\", \"%s\", 'object', 'space', \"%s\")", orgID, userID, p, labelID)
|
||||
_, err = runSQL(rt, sql)
|
||||
if err != nil {
|
||||
rt.Log.Error("insert into permission failed", err)
|
||||
rt.Log.Error("INSERT INTO permission failed", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Create some user groups
|
||||
groupDevID := uniqueid.Generate()
|
||||
sql = fmt.Sprintf("INSERT INTO role (refid, orgid, role, purpose) VALUES (\"%s\", \"%s\", \"Technology\", \"On-site and remote development teams\")", groupDevID, orgID)
|
||||
sql = fmt.Sprintf("INSERT INTO group (c_refid, c_orgid, c_name, c_desc) VALUES (\"%s\", \"%s\", \"Technology\", \"On-site and remote development teams\")", groupDevID, orgID)
|
||||
_, err = runSQL(rt, sql)
|
||||
if err != nil {
|
||||
rt.Log.Error("insert into role failed", err)
|
||||
rt.Log.Error("INSERT INTO group failed", err)
|
||||
}
|
||||
|
||||
groupProjectID := uniqueid.Generate()
|
||||
sql = fmt.Sprintf("INSERT INTO role (refid, orgid, role, purpose) VALUES (\"%s\", \"%s\", \"Project Management\", \"HQ project management\")", groupProjectID, orgID)
|
||||
sql = fmt.Sprintf("INSERT INTO group (c_refid, c_orgid, c_name, c_desc) VALUES (\"%s\", \"%s\", \"Project Management\", \"HQ project management\")", groupProjectID, orgID)
|
||||
_, err = runSQL(rt, sql)
|
||||
if err != nil {
|
||||
rt.Log.Error("insert into role failed", err)
|
||||
rt.Log.Error("INSERT INTO group failed", err)
|
||||
}
|
||||
|
||||
groupBackofficeID := uniqueid.Generate()
|
||||
sql = fmt.Sprintf("INSERT INTO role (refid, orgid, role, purpose) VALUES (\"%s\", \"%s\", \"Back Office\", \"Non-IT and PMO personnel\")", groupBackofficeID, orgID)
|
||||
sql = fmt.Sprintf("INSERT INTO group (c_refid, c_orgid, c_name, c_desc) VALUES (\"%s\", \"%s\", \"Back Office\", \"Non-IT and PMO personnel\")", groupBackofficeID, orgID)
|
||||
_, err = runSQL(rt, sql)
|
||||
if err != nil {
|
||||
rt.Log.Error("insert into role failed", err)
|
||||
rt.Log.Error("INSERT INTO group failed", err)
|
||||
}
|
||||
|
||||
// Join some groups
|
||||
sql = fmt.Sprintf("INSERT INTO rolemember (orgid, roleid, userid) VALUES (\"%s\", \"%s\", \"%s\")", orgID, groupDevID, userID)
|
||||
sql = fmt.Sprintf("INSERT INTO dmz_group_member (c_orgid, c_groupid, c_userid) VALUES (\"%s\", \"%s\", \"%s\")", orgID, groupDevID, userID)
|
||||
_, err = runSQL(rt, sql)
|
||||
if err != nil {
|
||||
rt.Log.Error("insert into rolemember failed", err)
|
||||
rt.Log.Error("INSERT INTO dmz_group_member failed", err)
|
||||
}
|
||||
sql = fmt.Sprintf("INSERT INTO rolemember (orgid, roleid, userid) VALUES (\"%s\", \"%s\", \"%s\")", orgID, groupProjectID, userID)
|
||||
sql = fmt.Sprintf("INSERT INTO dmz_group_member (c_orgid, c_groupid, c_userid) VALUES (\"%s\", \"%s\", \"%s\")", orgID, groupProjectID, userID)
|
||||
_, err = runSQL(rt, sql)
|
||||
if err != nil {
|
||||
rt.Log.Error("insert into rolemember failed", err)
|
||||
rt.Log.Error("INSERT INTO dmz_group_member failed", err)
|
||||
}
|
||||
sql = fmt.Sprintf("INSERT INTO rolemember (orgid, roleid, userid) VALUES (\"%s\", \"%s\", \"%s\")", orgID, groupBackofficeID, userID)
|
||||
sql = fmt.Sprintf("INSERT INTO dmz_group_member (c_orgid, c_groupid, c_userid) VALUES (\"%s\", \"%s\", \"%s\")", orgID, groupBackofficeID, userID)
|
||||
_, err = runSQL(rt, sql)
|
||||
if err != nil {
|
||||
rt.Log.Error("insert into rolemember failed", err)
|
||||
rt.Log.Error("INSERT INTO dmz_group_member failed", err)
|
||||
}
|
||||
|
||||
return
|
||||
|
|
|
@ -178,12 +178,8 @@ func (s Scope) TemplatesBySpace(ctx domain.RequestContext, spaceID string) (docu
|
|||
// These documents can then be seen by search crawlers.
|
||||
func (s Scope) PublicDocuments(ctx domain.RequestContext, orgID string) (documents []doc.SitemapDocument, err error) {
|
||||
err = s.Runtime.Db.Select(&documents, `
|
||||
SELECT id, c_refid AS refid, c_orgid AS orgid, c_spaceid AS spaceid, c_userid AS userid,
|
||||
c_job AS job, c_location AS location, c_name AS name, c_desc AS excerpt, c_slug AS slug,
|
||||
c_tags AS tags, c_template AS template, c_protection AS protection, c_approval AS approval,
|
||||
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
|
||||
FROM dmz_doc
|
||||
SELECT d.c_refid AS documentid, d.c_name AS document, d.c_revised as revised, l.c_refid AS spaceid, l.c_name AS space
|
||||
FROM dmz_doc d
|
||||
LEFT JOIN dmz_space l ON l.c_refid=d.c_spaceid
|
||||
WHERE d.c_orgid=? AND l.c_type=1 AND d.c_lifecycle=1 AND d.c_template=0`, orgID)
|
||||
|
||||
|
@ -192,12 +188,16 @@ func (s Scope) PublicDocuments(ctx domain.RequestContext, orgID string) (documen
|
|||
documents = []doc.SitemapDocument{}
|
||||
}
|
||||
if err != nil {
|
||||
err = errors.Wrap(err, fmt.Sprintf("execute GetPublicDocuments for org %s%s", orgID))
|
||||
err = errors.Wrap(err, fmt.Sprintf("execute GetPublicDocuments for org %s", orgID))
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
/*
|
||||
FROM document d LEFT JOIN label l ON l.refid=d.labelid
|
||||
*/
|
||||
|
||||
// Update changes the given document record to the new values, updates search information and audits the action.
|
||||
func (s Scope) Update(ctx domain.RequestContext, document doc.Document) (err error) {
|
||||
document.Revised = time.Now().UTC()
|
||||
|
|
|
@ -91,23 +91,24 @@ func (h *Handler) RobotsTxt(w http.ResponseWriter, r *http.Request) {
|
|||
// Anonymous access would mean we allow bots to crawl.
|
||||
if o.AllowAnonymousAccess {
|
||||
sitemap := ctx.GetAppURL("sitemap.xml")
|
||||
robots = fmt.Sprintf(
|
||||
`User-agent: *
|
||||
Disallow: /settings/
|
||||
Disallow: /settings/*
|
||||
Disallow: /profile/
|
||||
Disallow: /profile/*
|
||||
Disallow: /auth/login/
|
||||
Disallow: /auth/login/
|
||||
Disallow: /auth/logout/
|
||||
Disallow: /auth/logout/*
|
||||
Disallow: /auth/reset/*
|
||||
Disallow: /auth/reset/*
|
||||
Disallow: /auth/sso/
|
||||
Disallow: /auth/sso/*
|
||||
Disallow: /share
|
||||
Disallow: /share/*
|
||||
Sitemap: %s`, sitemap)
|
||||
robots = fmt.Sprintf(`User-agent: *
|
||||
Disallow: /settings/
|
||||
Disallow: /settings/*
|
||||
Disallow: /profile/
|
||||
Disallow: /profile/*
|
||||
Disallow: /auth/login/
|
||||
Disallow: /auth/login/
|
||||
Disallow: /auth/logout/
|
||||
Disallow: /auth/logout/*
|
||||
Disallow: /auth/reset/*
|
||||
Disallow: /auth/reset/*
|
||||
Disallow: /auth/sso/
|
||||
Disallow: /auth/sso/*
|
||||
Disallow: /auth/*
|
||||
Disallow: /auth/**
|
||||
Disallow: /share
|
||||
Disallow: /share/*
|
||||
Sitemap: %s`, sitemap)
|
||||
}
|
||||
|
||||
response.WriteBytes(w, []byte(robots))
|
||||
|
@ -166,7 +167,7 @@ func (h *Handler) Sitemap(w http.ResponseWriter, r *http.Request) {
|
|||
for _, document := range documents {
|
||||
var item sitemapItem
|
||||
item.URL = ctx.GetAppURL(fmt.Sprintf("s/%s/%s/d/%s/%s",
|
||||
document.SpaceID, stringutil.MakeSlug(document.Folder), document.DocumentID, stringutil.MakeSlug(document.Document)))
|
||||
document.SpaceID, stringutil.MakeSlug(document.Space), document.DocumentID, stringutil.MakeSlug(document.Document)))
|
||||
item.Date = document.Revised.Format("2006-01-02T15:04:05.999999-07:00")
|
||||
items = append(items, item)
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ type SitemapDocument struct {
|
|||
DocumentID string
|
||||
Document string
|
||||
SpaceID string
|
||||
Folder string
|
||||
Space string
|
||||
Revised time.Time
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue