okinotes

package module
v0.0.0-...-be64f91 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2015 License: MIT Imports: 16 Imported by: 0

README

okinotes - Take notes and share in seconds

This repository contains the backend powering the Okinotes application at http://okinotes.appspot.com/

Documentation

Overview

Package okinotes contains all the model and business layers for the okinotes application.

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrFirstUserConnection is the errors returned when connecting
	//for the first time with an identity.
	ErrFirstUserConnection = errors.New("User not created")
)

Functions

func RegisterAPIOnRouter

func RegisterAPIOnRouter(m *mux.Router, f AppFactory) error

RegisterAPIOnRouter initializes the router for the API of the webapp

func RegisterPagesOnRouter

func RegisterPagesOnRouter(m *mux.Router, f AppFactory) error

RegisterPagesOnRouter initializes the router for the pages of the webapp

Types

type App

type App struct {
	// contains filtered or unexported fields
}

App is the main application.

func NewApp

NewApp creates a new App using the given services

func (App) CreateItem

func (app App) CreateItem(userName, pageName string, i Item) (Item, error)

CreateItem stores an item Returns the stored item.

func (App) CreatePage

func (app App) CreatePage(page Page) error

CreatePage create a new page for the given user Returns the id of the stored page.

func (App) CreateUser

func (app App) CreateUser(ident Ident, userName string) error

CreateUser creates a user

func (App) CurrentIdentity

func (app App) CurrentIdentity() (Identity, error)

CurrentIdentity returns the Identity used to logged in.

func (App) CurrentUser

func (app App) CurrentUser() (User, error)

CurrentUser returns the current user

func (App) CurrentUserIsAdmin

func (app App) CurrentUserIsAdmin() bool

CurrentUserIsAdmin returns true if the current user is an administrator

func (App) CurrentUserName

func (app App) CurrentUserName() string

CurrentUserName returns the name of the current user. Returns an empty string if not logged in.

func (App) DeleteImage

func (app App) DeleteImage(imgID string) error

DeleteImage delete an uploaded image

func (App) DeleteItem

func (app App) DeleteItem(userName, pageName string, itemID string) error

DeleteItem removes permanently an item

func (App) DeletePage

func (app App) DeletePage(userName, pageName string) error

DeletePage removes permanently a page and all the associated content (items and permissions)

func (App) GetAllTemplates

func (app App) GetAllTemplates() ([]Template, error)

GetAllTemplates retrieve all templates from the datastore

func (App) GetPage

func (app App) GetPage(userName string, pageName string) (Page, error)

GetPage retrieve an existing single page

func (App) GetTemplate

func (app App) GetTemplate(templateID string) (Template, error)

GetTemplate retrieve a template from the datastore

func (App) ImageURL

func (app App) ImageURL(img UploadInfo, secure bool, size int) (string, error)

ImageURL retrieves the image URL associated with the image

func (App) Images

func (app App) Images(limit int) ([]UploadInfo, error)

Images retrieves the images associated with the current user

func (App) ListOwnedPages

func (app App) ListOwnedPages(limit int) ([]Page, bool, error)

ListOwnedPages returns the list of pages owned by a given user

func (App) ListPublicPages

func (app App) ListPublicPages(limit int) ([]Page, bool, error)

ListPublicPages returns the list of public pages for a given user

func (App) LoginURL

func (app App) LoginURL(destURL string) (string, error)

LoginURL returns the URL to the log-in ressource

func (App) LogoutURL

func (app App) LogoutURL(destURL string) (string, error)

LogoutURL returns the URL to the log-out ressource

func (App) PutItem

func (app App) PutItem(userName, pageName string, i Item) (Item, error)

PutItem stores a fully defined item. Replace the item if it already exists Returns the stored item.

func (App) RenameImage

func (app App) RenameImage(imgID string, newName string) error

RenameImage changes the name of an uploaded image

func (App) SetItemTag

func (app App) SetItemTag(userName, pageName string, itemID string, tagKey string, tagValue string) error

SetItemTag stores a new value for an item tag

func (App) StoreImage

func (app App) StoreImage(r *http.Request, name string) error

StoreImage stores an uplaoded image in the datastore and associate it with the current user

func (App) StoreTemplate

func (app App) StoreTemplate(tpl Template) error

StoreTemplate insert or update a template in database

func (App) UpdateItem

func (app App) UpdateItem(userName, pageName string, i Item, updateTags bool) (Item, error)

UpdateItem stores an updated item

func (App) UpdatePage

func (app App) UpdatePage(page Page, pageTags TagDescriptionList) error

UpdatePage updates a given page. The description of tags in the current template must be provided.

func (App) UpdateTemplate

func (app App) UpdateTemplate(userName string, pageName string, newTemplateID string) error

UpdateTemplate changes the template of page.

func (App) UploadURL

func (app App) UploadURL(destURL string) (string, error)

UploadURL returns the URL to the upload ressource

func (App) Version

func (app App) Version() string

Version returns a user readable text describing the current version of the application

type AppFactory

type AppFactory interface {
	CreateApp(r *http.Request) (App, error)
}

AppFactory represents the objects able to create an App

type DataError

type DataError struct {
	Field   string
	Message string
}

DataError represents a validation error on data

func (DataError) Error

func (err DataError) Error() string

type Ident

type Ident struct {
	Provider string
	Identity string
}

Ident is an identity from a third party provider

type Identity

type Identity struct {
	Ident

	UserName string
}

Identity is the authentication of a user (the link between an external Ident and a User)

type Item

type Item struct {
	ID string `json:"id"`

	CreationDate         time.Time `json:"creationDate"`
	LastModificationDate time.Time `json:"lastModificationDate"`

	Kind        string        `json:"kind"`
	Title       string        `json:"title"`
	Content     string        `datastore:",noindex"  json:"content"`
	HTMLContent template.HTML `datastore:",noindex"  json:"htmlContent"`
	Source      string        `json:"source"`
	URL         string        `json:"url"`

	Tags TagList `json:"tags"`
}

Item is an element of a page. It belongs to his parent page.

func (Item) String

func (i Item) String() string

Compute a markdown representation of the Item

type LogInteractor

type LogInteractor interface {
	// Debugf formats its arguments according to the format, analogous to fmt.Printf,
	// and records the text as a log message at Debug level.
	Debugf(format string, args ...interface{})

	// Infof is like Debugf, but at Info level.
	Infof(format string, args ...interface{})

	// Warningf is like Debugf, but at Warning level.
	Warningf(format string, args ...interface{})

	// Errorf is like Debugf, but at Error level.
	Errorf(format string, args ...interface{})

	// Criticalf is like Debugf, but at Critical level.
	Criticalf(format string, args ...interface{})
}

LogInteractor allows logging of application messages

type Membership

type Membership struct {
	UserName string
	OrgName  string

	IsOrgAdmin bool
}

Membership indicates the membership of a user into an organisation.

type NotAuthorizedError

type NotAuthorizedError struct {
	Operation string
}

NotAuthorizedError represents an authorisation error on operation

func (NotAuthorizedError) Error

func (err NotAuthorizedError) Error() string

type NotInDatastoreError

type NotInDatastoreError struct {
	Type string
	ID   string
}

NotInDatastoreError represents an error on data not in datastore

func (NotInDatastoreError) Error

func (err NotInDatastoreError) Error() string

type Page

type Page struct {
	UserName             string    `json:"userName"`
	Name                 string    `json:"name"`
	CreationDate         time.Time `json:"creationDate"`
	LastModificationDate time.Time `json:"lastModificationDate"`
	Title                string    `json:"title"`
	ContentLicense       string    `json:"contentLicense"`
	Policy               Policy    `json:"policy"`
	TemplateID           string    `json:"templateID"`
	Tags                 TagList   `json:"tags"`
}

Page represents a collection of items. It belongs to a user

type PageQuery

type PageQuery interface {
	User(userName string) PageQuery
	Filter(filterStr string, value interface{}) PageQuery
	Order(fieldName string) PageQuery
	Limit(limit int) PageQuery

	GetAll() ([]Page, bool, error)
}

PageQuery allows querying multiple pages using conditions and ordering

type Policy

type Policy string

A Policy defines the accessibility of content

const (
	//PolicyPRIVATE means that only authorized user may access the data
	PolicyPRIVATE Policy = "PRIVATE"
	//PolicyPUBLIC means that anonymous user may access the data
	PolicyPUBLIC Policy = "PUBLIC"
)

type Repository

type Repository interface {
	RunInTransaction(func(repo Repository) error) error

	GetPage(userName string, pageName string) (Page, error)
	NewPageQuery() PageQuery
	StorePage(page Page) error
	DeletePage(userName string, pageName string) error

	GetItemsFromPage(userName string, pageName string, limit int) ([]Item, error)
	DeleteItemsFromPage(userName string, pageName string) error
	FindItem(userName string, pageName string, itemID string) (bool, error)
	GetItem(userName string, pageName string, itemID string) (Item, error)
	StoreItem(userName string, pageName string, i Item) error
	DeleteItem(userName string, pageName string, itemID string) error

	FindUser(userName string) (bool, error)
	GetUser(ident Ident) (User, error)
	GetIdentity(ident Ident) (Identity, error)
	StoreUser(user User) error
	StoreIdentity(identity Identity) error

	GetImages(userName string, limit int) ([]UploadInfo, error)
	StoreImage(img UploadInfo, userName string) error
	RenameImage(name string, imgID string, userName string) error
	DeleteImage(imgID string, userName string) error

	IsUsed(imgID string) (bool, error)
	StoreUsage(userName string, pageName string, imgID string) error
	DeleteUsages(userName string, pageName string) error

	GetTemplate(templateID string) (Template, error)
	GetAllTemplates() ([]Template, error)
	StoreTemplate(tpl Template, generateID func() string) (string, error)
	DeleteTemplate(templateID string) error
}

Repository is the interface allowing usage of any data store for Pages, Items and all other data

type Tag

type Tag struct {
	Key   string
	Value string
}

Tag represents additional informations allowing dynamic extension of some structs

type TagDescription

type TagDescription struct {
	Key          string
	Name         string
	Kind         string
	Description  string
	DefaultValue string
}

TagDescription represents metadata on a Tag

type TagDescriptionList

type TagDescriptionList []TagDescription

TagDescriptionList represenets a list of TagDescription

type TagList

type TagList []Tag

TagList represent all the extension information

func (*TagList) DefaultTo

func (l *TagList) DefaultTo(defaultValues TagDescriptionList)

DefaultTo add or replace the values of the current tag list with the one from the new list TagList remains sorted after this operation.

func (TagList) Len

func (l TagList) Len() int

func (TagList) Less

func (l TagList) Less(i, j int) bool

func (*TagList) SetTag

func (l *TagList) SetTag(key, value string)

SetTag add or replace the value associated to the given key. TagList remains sorted after this operation.

func (TagList) Swap

func (l TagList) Swap(i, j int)

func (TagList) Tag

func (l TagList) Tag(key string) string

Tag returns the value associated to the given key. Returns an empty string when the key does not exists.

type Template

type Template struct {
	ID string

	CreationDate         time.Time
	LastModificationDate time.Time

	Name string
	File string

	PageTags TagDescriptionList
	ItemTags TagDescriptionList
}

Template represents a page schema with optional parameters

type UploadInfo

type UploadInfo struct {
	Key          string
	ContentType  string
	CreationTime time.Time
	Filename     string
	Size         int64
}

UploadInfo contains all the information of uploaded content

type UploadInteractor

type UploadInteractor interface {
	UploadURL(destURL string, maxUploadBytes int64) (string, error)
	UploadInfo(req *http.Request, name string) (UploadInfo, error)
	ImageURL(key string, secure bool, size int) (string, error)
	Delete(key string) error
}

UploadInteractor allows uploading and serving images

type Usage

type Usage struct {
	UploadInfoKey string
}

Usage represents the characteristics of the usage of a ressource in a page.

type User

type User struct {
	Name     string //Uniquely identify the user
	Kind     UserKind
	FullName string
}

User represents someone interacting with notes

func (User) String

func (u User) String() string

Compute a markdown representation of the User

type UserInteractor

type UserInteractor interface {
	CurrentIdentity() (Ident, error)
	CurrentUserIsAdmin() bool

	LoginURL(destURL string) (string, error)
	LogoutURL(destURL string) (string, error)
}

UserInteractor allows interactions with the User connected to the application

type UserKind

type UserKind string

UserKind represents the kind of a user

const (
	//UserKindUSER are users having an identity
	UserKindUSER UserKind = "USER"
	//UserKindORG represents a group of users
	UserKindORG UserKind = "ORG"
)

Directories

Path Synopsis
Package ae contains the appengine specific implementation of the okinotes app.
Package ae contains the appengine specific implementation of the okinotes app.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL