Example #1
0
//Delete a page.  Returns the revision, if successful
func (pm *PageManager) Delete(wiki string, pageId string,
	pageRev string, curUser *CurrentUserInfo) (string, error) {
	auth := curUser.Auth
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	//Load the page
	thePage := wikit.Page{}
	if _, err := theWiki.ReadPage(pageId, &thePage); err != nil {
		return "", err
	} else if thePage.OwningPage != pageId {
		//Thou shalt not delete historical revisions
		return "", BadRequestError()
	}
	//check if this is a 'home page'
	wm := WikiManager{}
	wr := WikiRecord{}
	if wRev, err := wm.Read(wiki, &wr, curUser); err != nil {
		return "", err
	} else if wr.HomePageId == pageId {
		//This is a home page, so clear the Wiki Record's home page Id
		wr.HomePageId = ""
		_, err = wm.Update(wiki, wRev, &wr, curUser)
		if err != nil {
			return "", err
		}
	}
	return theWiki.DeletePage(pageId, pageRev)
}
Example #2
0
//Saves a File Record (not the attachment)
func (fm *FileManager) SaveFileRecord(wiki string, file *wikit.File,
	id string, rev string, curUser *CurrentUserInfo) (string, error) {
	auth := curUser.Auth
	uploadedBy := curUser.User.UserName
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	return theWiki.SaveFileRecord(file, id, rev, uploadedBy)
}
Example #3
0
//Gets a list of all comments for a page
func (pm *PageManager) GetComments(wiki string, pageId string,
	pageNum int, numPerPage int,
	curUser *CurrentUserInfo) (*wikit.CommentIndexViewResponse, error) {
	auth := curUser.Auth
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	return theWiki.GetCommentsForPage(pageId, pageNum, numPerPage)
}
Example #4
0
//Deletes a File Record
func (fm *FileManager) DeleteFile(wiki string,
	id string, curUser *CurrentUserInfo) (string, error) {
	auth := curUser.Auth
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	theFile := wikit.File{}
	if rev, err := theWiki.GetFileRecord(id, &theFile); err != nil {
		return "", err
	} else {
		return theWiki.DeleteFileRecord(id, rev)
	}
}
Example #5
0
//Creates or Updates a page
//Returns the revision number, if successful
func (pm *PageManager) Save(wiki string, page *wikit.Page,
	pageId string, pageRev string, curUser *CurrentUserInfo) (string, error) {
	auth := curUser.Auth
	theUser := curUser.User
	//Read the content from the page
	//parse the markdown to Html
	out := make(chan string)
	//Convert (Sanitized) Markdown to HTML
	go processMarkdown(page.Content.Raw, out)
	page.Content.Formatted = <-out
	//Store the thing, if you have the auth
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	return theWiki.SavePage(page, pageId, pageRev, theUser.UserName)
}
Example #6
0
//Delete a comment.  Returns the revision if successful
func (pm *PageManager) DeleteComment(wiki string, commentId string,
	curUser *CurrentUserInfo) (string, error) {
	auth := curUser.Auth
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	if pm.allowedToUpdateComment(wiki, commentId, curUser) {
		comment := wikit.Comment{}
		commentRev, err := pm.ReadComment(wiki, commentId, &comment, curUser)
		if err != nil {
			return "", err
		}
		return theWiki.DeleteComment(commentId, commentRev)
	} else {
		return "", errors.New("[Error]:403: Not Authorized")
	}
}
Example #7
0
//Creates or updates a comment
func (pm *PageManager) SaveComment(wiki string, pageId string, comment *wikit.Comment,
	commentId string, commentRev string, curUser *CurrentUserInfo) (string, error) {
	auth := curUser.Auth
	theUser := curUser.User
	//First, if this is an update, check if this user can update the comment
	if commentRev != "" {
		if cu := pm.allowedToUpdateComment(wiki, commentId, curUser); cu == false {
			return "", errors.New("[Error]:403: Not Authorized")
		}
	}
	//Read the content from the comment
	//parse the markdown to Html
	out := make(chan string)
	//Convert (Sanitized) Markdown to HTML
	go processMarkdown(comment.Content.Raw, out)
	comment.Content.Formatted = <-out
	//Store it
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	return theWiki.SaveComment(comment, commentId, commentRev, pageId, theUser.UserName)
}
Example #8
0
//Gets a list of breadcrumbs for the current page
func (pm *PageManager) GetBreadcrumbs(wiki string, pageId string,
	curUser *CurrentUserInfo) ([]Breadcrumb, error) {
	thePage := wikit.Page{}
	if _, err := pm.Read(wiki, pageId, &thePage, curUser); err == nil {
		crumbs := []Breadcrumb{}
		response := wikit.MultiPageResponse{}
		theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), curUser.Auth)
		if szLineage := len(thePage.Lineage); szLineage > 1 {
			lineage := thePage.Lineage[0 : szLineage-1]
			if err = theWiki.ReadMultiplePages(lineage, &response); err != nil {
				return nil, err
			}
		}
		//Add the current page to the end of the list
		currentPageRow := wikit.MultiPageRow{
			Id:  pageId,
			Doc: thePage,
		}
		rows := append(response.Rows, currentPageRow)
		for _, row := range rows {
			theDoc := row.Doc
			parent := ""
			if len(theDoc.Lineage) >= 2 {
				parent = theDoc.Lineage[len(theDoc.Lineage)-2]
			}
			crumb := Breadcrumb{
				Name:   theDoc.Title,
				PageId: row.Id,
				WikiId: wiki,
				Parent: parent,
			}
			crumbs = append(crumbs, crumb)
		}
		return crumbs, nil
	} else {
		return nil, err
	}

}
Example #9
0
// Read a page by its slug.
// Assume the wiki Id passed in is a slug also
// Returns the WikiId, the Page Rev, and an error
func (pm *PageManager) ReadBySlug(wikiSlug string, pageSlug string,
	page *wikit.Page, curUser *CurrentUserInfo) (string, string, error) {
	// Need to get the true wiki Id from the slug
	auth := curUser.Auth
	mainDbName := MainDbName()
	mainDb := Connection.SelectDB(mainDbName, auth)
	response := WikiSlugViewResponse{}
	err := mainDb.GetView("wiki_query",
		"getWikiBySlug",
		&response,
		wikit.SetKey(wikiSlug))
	if err != nil {
		return "", "", err
	}
	if len(response.Rows) > 0 {
		wikiId := response.Rows[0].Id
		theWiki := wikit.SelectWiki(Connection, wikiDbString(wikiId), auth)
		pageRev, err := theWiki.ReadPageBySlug(pageSlug, page)
		return wikiId, pageRev, err
	} else {
		return "", "", NotFoundError()
	}
}
Example #10
0
func (pm *PageManager) allowedToUpdateComment(wiki string, commentId string,
	curUser *CurrentUserInfo) bool {
	userName := curUser.User.UserName
	userRoles := curUser.User.Roles
	auth := curUser.Auth
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	//First, we need to read the comment record
	comment := wikit.Comment{}
	_, err := theWiki.ReadComment(commentId, &comment)
	if err != nil {
		return false
	}
	//Only admins and the original comment author may update/delete
	isAdmin := util.HasRole(userRoles, AdminRole(wiki)) ||
		util.HasRole(userRoles, AdminRole(MainDbName())) ||
		util.HasRole(userRoles, MasterRole())
	if comment.Author == userName || isAdmin {
		return true
	} else {
		return false
	}

}
Example #11
0
//Get file attachment
func (fm *FileManager) GetFileAttachment(wiki, id, rev,
	attType, attName string, curUser *CurrentUserInfo) (io.ReadCloser, error) {
	auth := curUser.Auth
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	return theWiki.GetFileAttachment(id, rev, attType, attName)
}
Example #12
0
//Saves a File's Attachment
func (fm *FileManager) SaveFileAttachment(wiki, id, rev, attName, attType string,
	attContent io.Reader, curUser *CurrentUserInfo) (string, error) {
	auth := curUser.Auth
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	return theWiki.SaveFileAttachment(id, rev, attName, attType, attContent)
}
Example #13
0
//Reads a File Record (but not the attachment)
func (fm *FileManager) ReadFileRecord(wiki string,
	file *wikit.File, id string, curUser *CurrentUserInfo) (string, error) {
	auth := curUser.Auth
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	return theWiki.GetFileRecord(id, file)
}
Example #14
0
//Gets a list of all 'files' in a wiki
func (fm *FileManager) Index(wiki string, fileType string, pageNum int, numPerPage int,
	curUser *CurrentUserInfo) (*wikit.FileIndexViewResponse, error) {
	auth := curUser.Auth
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	return theWiki.GetFileIndex(fileType, pageNum, numPerPage)
}
Example #15
0
//Gets a list of child pages for a given document
func (pm *PageManager) ChildIndex(wiki string, pageId string,
	curUser *CurrentUserInfo) (wikit.PageIndex, error) {
	auth := curUser.Auth
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	return theWiki.GetChildPageIndex(pageId)
}
Example #16
0
//Read a page
//Pass an empty page to hold the data. returns the revision
func (pm *PageManager) Read(wiki string, pageId string,
	page *wikit.Page, curUser *CurrentUserInfo) (string, error) {
	auth := curUser.Auth
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	return theWiki.ReadPage(pageId, page)
}
Example #17
0
//Read a comment
func (pm *PageManager) ReadComment(wiki string, commentId string,
	comment *wikit.Comment, curUser *CurrentUserInfo) (string, error) {
	auth := curUser.Auth
	theWiki := wikit.SelectWiki(Connection, wikiDbString(wiki), auth)
	return theWiki.ReadComment(commentId, comment)
}