Skip to content

Instantly share code, notes, and snippets.

View VinayaSathyanarayana's full-sized avatar

Vinaya Sathyanarayana VinayaSathyanarayana

View GitHub Profile
@VinayaSathyanarayana
VinayaSathyanarayana / views_in_keystone.md
Created May 28, 2017 18:26 — forked from wuhaixing/views_in_keystone.md
How to Construct Yourself UI in KeystoneJS

#How to Construct Yourself UI in KeystoneJS

KeystoneJS provide Admin UI with one set of route controllers and view templates(list&item) for all of the models.But usually,you will need some custome views other than Admin UI to display models. Although the KeystoneJS documention don't tell us much about how to contruct custome view,we can learn this from the source code in skeleton project generated by yo keystone,or you can just check out the keystone demo project's source code.We will walk through the blog feature's implementation in this demo application to demonstrate how to construct custome UI in KeystoneJS application.

As KeystoneJS documention described in Routes & Views section,there is a routes/index.js file, where we bind application's URL patterns to the controllers that load and process data, and render the appropriate template.You can find following code in it:

app.get('/blog/:catego

@VinayaSathyanarayana
VinayaSathyanarayana / security.js
Created June 14, 2017 09:31 — forked from crimeminister/security.js
Express middleware for IP-based access control
'use strict';
var _ = require('lodash');
var keystone = require('keystone');
var range_check = require('range_check');
var util = require('util');
/**
*
*/
@VinayaSathyanarayana
VinayaSathyanarayana / createItems.md
Created July 17, 2017 17:53 — forked from JedWatson/createItems.md
Examples of how to use Keystone's createItems functionality

Populating Data in KeystoneJS

Keystone's createItems function is a simple but powerful way to populate your database with data.

It can be used to create test fixtures or initialise your database with default content / users / etc.

There's also a shorthand syntax that can be used within update files; if you are using the auto updates feature, any file that exports a create object will automatically be wrapped and the data will be created.

createItems takes two passes at the data it is passed, first creating the items and retaining references by key (if provided) that can be used to populate relationships in the second pass. This makes it easy to create related data without asynchronous nesting (which for data creation sometimes ends up in knots).

@VinayaSathyanarayana
VinayaSathyanarayana / Countries.js
Created July 17, 2017 17:54 — forked from JedWatson/Countries.js
Example of how to use the filters option for Relationship fields
// A global file to provide the countries and cities
exports.countries = [{
name: 'Australia',
cities: ['Melbourne', 'Sydney', 'Canberra']
}, {
name: 'España',
cities: ['Madrid', 'Barcelona', 'Sevilla']
}, {
name: 'Italia',
@VinayaSathyanarayana
VinayaSathyanarayana / KeystoneApiExample.md
Created July 17, 2017 17:55 — forked from JedWatson/KeystoneApiExample.md
Example of how to scaffold API endpoints for Posts in a Keystone project (based on the yo keystone example).

This is an example of how to scaffold API endpoints to list / get / create / update / delete Posts in a Keystone website.

It's a modification of the default project created with the yo keystone generator (see https://github.com/JedWatson/generator-keystone)

Gists don't let you specify full paths, so in the project structure the files would be:

routes-index.js        -->    /routes/index.js         // modified to add the api endpoints
routes-api-posts.js    -->    /routes/api/posts.js     // new file containing the Post API route controllers
@VinayaSathyanarayana
VinayaSathyanarayana / passport_node_acl_example.js
Created July 18, 2017 17:55 — forked from danwit/passport_node_acl_example.js
Authentication and authorization with passportjs + node_acl + mongo + express
/**
* Simple authentication and authorization example with passport, node_acl,
* MongoDB and expressjs
*
* The example shown here uses local userdata and sessions to remember a
* logged in user. Roles are persistent all the way and applied to user
* after logging in.
*
* Usage:
* 1. Start this as server
@VinayaSathyanarayana
VinayaSathyanarayana / main.js
Created July 25, 2017 15:27 — forked from lukemelia/main.js
letsencrypt with node and heroku
var LE = require('letsencrypt');
var pem = require('pem');
var RSVP = require('rsvp');
var fs = require('fs');
var path = require('path');
var mkdirp = require('mkdirp');
var domains, herokuAppName, duplicate;
if (process.env.YAPP_ENV === 'qa') {
domains = ['heroku.yappqa.us', 'my.yappqa.us', 'api.yappqa.us', 'support.yappqa.us' ];

To implement API authentication in KeystoneJS, you need the following:

For key based authentication

  • Middleware that validates the key in the request body or a header

For session based authentication

  • An endpoint that handles signin
  • An endpoint that handles signout
@VinayaSathyanarayana
VinayaSathyanarayana / Readme.md
Created November 15, 2017 17:33 — forked from jeffreypriebe/Readme.md
Keystone Admin User Role Permissions

The admin-user-roles-permissions has basic support for handling user permissions in the Keystone admin area.

It is comprised of basic parts:

  1. Additional fields on the user model (mentioned in steps below and also the User.js file)

    • isUserAdmin, isSuperAdmin and isPWD (the last one has permissions to edit any other user always)
    • Simply, each user has the ability to edit self and all users with fewer permissions.
  2. Exposure of these values (via virtuals) to the React admin/src/views/item.js route and to the server side jade templates and express routes.

Keystone Roles & Permissions Support

The following documents the user permission support in keystone based on the support being added via PR #2111. Permissions are based on roles. If a user has a role and the list also specifies that role for any of its CRUD operations then it is permissive for the user to perform whichever CRUD operation matches the role. All users must define, at least, one role. The following are guidelines for adding role/permission support to your application:

Define a Role List Model: