Skip to content

Instantly share code, notes, and snippets.

View mphasize's full-sized avatar

Marcus mphasize

View GitHub Profile
@mphasize
mphasize / Blokdots.tsx
Created April 15, 2023 21:54
Proof of concept for using Code Overrides in Framer to connect to blokdots
import type { ComponentType } from "react"
import { useState, useEffect } from "react"
import { Override } from "framer"
import { Manager } from "https://jspm.dev/socket.io-client"
// Learn more: https://www.framer.com/docs/guides/code-components/
// Use with https://blokdots.com and the Socket.IO server integration
let manager = null
let socket = null
@mphasize
mphasize / beforeBlueprint.js
Created March 2, 2015 12:31
Sails-beforeBlueprint-Policy
/**
* beforeBlueprint
*
* @module :: Policy
* @description :: Simple policy to enable hooks into the model which can act upon req, res objects.
* @docs :: http://sailsjs.org/#!documentation/policies
*
*/
var actionUtil = require( 'sails/lib/hooks/blueprints/actionUtil' );
@mphasize
mphasize / beforeCreate.js
Created March 2, 2015 10:10
Sails-beforeCreate-Policy
/**
* beforeCreate
*
* @module :: Policy
* @description :: Simple policy to inject the user creating a record into the records values.
* Assumes req.user && req.user.id to be set when a user is logged in.
* @docs :: http://sailsjs.org/#!documentation/policies
*
*/
@mphasize
mphasize / actionUtil-accessControl.js
Last active December 21, 2020 16:58
A naive implementation of custom hooks to enable access control (extending the Sails blueprints).
// https://github.com/balderdashy/sails/blob/master/lib/hooks/blueprints/actionUtil.js
/**
* AccessControl proxy function, expects a Waterline query object for before* hooks and an array of records for after* hooks.
* @param {Collection} model Waterline collectio, from parseModel
* @param {String} action blueprint or hook, e.g. beforeFind, afterFind, beforeCreate, afterCreate --> translates to accessControlBeforeFind, etc.
* @param {Object} options Options: query {Query} Waterline query object for before* hooks, records: {Array} records for after* hooks, {Model} current user record
* @return {Query|Array} returns the modified query (with altered criteria) for before* or the filtered/extended record array for after*.
*/
accessControl: function ( model, action, options, callback ) {
@mphasize
mphasize / _info.md
Last active August 29, 2015 14:01
Sails-Many-to-Many through

An example on how to setup Many-to-Many relationships through a junction table with it's own model definition, enabling individual attributes and filtering on the relationship.

@mphasize
mphasize / Sails-Protect-Blueprints.md
Created May 20, 2014 07:38
Sails.js - protect attributes on blueprint routes with policy and model setting

I am keeping this as a reference to balderdashy/sails#352

Working with SailsJS v0.10-rc5: I am trying to keep the magic of blueprint controllers while at the same time protecting some model attributes from being changed by users on the default routes. I.e.: prevent access to the is_admin attribute on regular CRUD routes and implement a promote action or something similar on the UserController which makes the neccessary checks.

In order to do this, I came up with the following policy in combination with a small addition to the model definitions:

// file: api/policies/protectedAttributes.js

/**