// HandleIndex displays a list of files func HandleIndex(context router.Context) error { // Authorise err := authorise.Path(context) if err != nil { return router.NotAuthorizedError(err) } // Find the current user and check status u := authorise.CurrentUser(context) if u.Anon() { // return router.NotAuthorizedError(err) } // For admins, show all files, order by date desc q := files.Query().Order("updated_at desc") // otherwise show just the logged in user's files if !u.Admin() { // Find the files for this user, unless q = files.Where("user_id=?", u.Id) } // Fetch the files results, err := files.FindAll(q) if err != nil { return router.InternalError(err) } // Render the template view := view.New(context) view.AddKey("files", results) return view.Render() }
// HandleIndex displays a list of users func HandleIndex(context router.Context) error { // Authorise err := authorise.Path(context) if err != nil { return router.NotAuthorizedError(err) } // Build a query q := users.Query() // Order by required order, or default to id asc switch context.Param("order") { case "1": q.Order("created desc") case "2": q.Order("updated desc") case "3": q.Order("name asc") default: q.Order("id asc") } // Filter if necessary - this assumes name and summary cols filter := context.Param("filter") if len(filter) > 0 { filter = strings.Replace(filter, "&", "", -1) filter = strings.Replace(filter, " ", "", -1) filter = strings.Replace(filter, " ", " & ", -1) q.Where("( to_tsvector(name) || to_tsvector(summary) @@ to_tsquery(?) )", filter) } // Fetch the users results, err := users.FindAll(q) if err != nil { return router.InternalError(err) } // Render the template view := view.New(context) view.AddKey("filter", filter) view.AddKey("users", results) return view.Render() }
// HandleCreateShow serves the create form via GET for pages func HandleCreateShow(context router.Context) error { // Authorise err := authorise.Path(context) if err != nil { return router.NotAuthorizedError(err) } // Render the template view := view.New(context) page := pages.New() view.AddKey("page", page) return view.Render() }