UNPKG

publication-igid

Version:

Authorization gateway relying on an auth service for providing user editing interfaces

245 lines (206 loc) 6.32 kB
// const { TaggedTransition } = require('copious-transitions') let uuid = false // Publication Users class Publications extends TaggedTransition { constructor(descendant) { if ( descendant ) { super(descendant) } else { super("publication") } } initialize(conf) { super.initialize(conf) } encryption_check(topic) { if ( topic === "change-password" ) return(true) } existence_query(udata) { return { "email" : udata.email } } from_cache() { return(true) } back_ref() { return("user_id") } kv_store_key() { return("ucwid") } primary_key() { return("ucwid") } session_key() { return("ucwid") } match_key() { return("session_token") } secondary_match_key() { return("token") } action_selector(action) { let idx = ['publication'].indexOf(action) return(idx >= 0) } secondary_action_selector(action) { let idx = ['publication-secondary'].indexOf(action) return(idx >= 0) } sess_data_accessor() { return('publication') } update(data) { data._tracking = uuid() data.key_field = "_transition_path" data._user_dir_key = "email" data._transition_path =`publication+${data.email}` return([data,{}]) } } class PublicationsCommands extends Publications { // constructor() { super('publication-commands') // this.ok_topics = [ "blog-markdown", "demo-json", // encryption check as well... "streams-link", "link_package-json", "calendar-slots" ] // this.ok_command = [ "command-upload", "command-publish", "command-unpublish", "command-delete", "command-send" ] // this._record_of_publication = {} } initialize(conf) { if ( conf ) { this.class_conf = conf.custom_transitions let cconf = this.class_conf // this.path_list = [] if ( conf.dynamic_asset && conf.dynamic_assets.uploader_paths && Array.isArray(conf.dynamic_assets.uploader_paths.path_list) ) { this.path_list = conf.dynamic_assets.uploader_paths.path_list } if ( cconf ) { super.initialize(conf) if ( cconf.add_topics ) { this.ok_topics = this.ok_topics.concat(cconf.add_topics) } if ( cconf.add_commands ) { this.ok_command = this.ok_command.concat(cconf.add_commands) } } } // this.addModule('dynamic') // process the fetch from dynamic content } has_secondary_action(command_type) { if ( command_type === "command-upload" ) return true return(false) } // can_publish can_upload(topic,hash) { // check to see if the topic belongs to a profile operation... if ( "command-upload" === topic ) { if ( this.ok_command.indexOf(topic) >= 0 ) { // and supported this._record_of_publication[hash] = Date.now() return true } } return false } // can_publish can_publish(topic,hash,keep_record) { // check to see if the topic belongs to a profile operation... if ( ( this.ok_command.indexOf(topic) >= 0 ) || ( this.ok_topics.indexOf(topic) >= 0 ) ) { if ( keep_record ) this._record_of_publication[hash] = Date.now() return true } return false } // did_publish did_publish(topic,hash) { // check to see if the topic belongs to a profile operation... if ( ( this.ok_command.indexOf(topic) >= 0 ) || ( this.ok_topics.indexOf(topic) >= 0 ) ) { if ( this._record_of_publication[hash] !== undefined ) { delete this._record_of_publication[hash] return true } } return false } // interval to clean out lost publications.... } class PublicationsAssets extends Publications { constructor() { super('publication-assets') // this.ok_assets = [ "blog", "demo", // encryption check as well... "stream", "links", "calendar" ] // this.last_tagged = undefined } tagged(asset_type) { this.last_tagged = undefined if ( this.ok_assets.indexOf(asset_type) >= 0 ) { this.last_tagged = asset_type return(true) } return(false) } has_secondary_action(asset_type) { return(false) } update(data) { data.asset_type = this.last_tagged if ( data._tracking ) { data.key_field = "_transition_path" data._user_dir_key = "email" data._transition_path =`${data._tracking}+${data.asset_type}+${data.email}` if ( data.data ) { data.txt_full = data.data data.data = undefined } } else { data._tracking = uuid() data.key_field = "_transition_path" data._user_dir_key = "email" data._transition_path =`${data._tracking}+${data.asset_type}+${data.email}` if ( data.data ) { data.txt_full = data.data data.data = undefined } } } } class PublicationCustomTransitions { constructor() { this.publication_keyed = new Publications() this.pub_command_keyed = new PublicationsCommands() this.pub_assets_keyed = new PublicationsAssets() } initialize(conf) { uuid = global_appwide_token global.G_publication_trns = this.publication_keyed global.G_publication_commands_trns = this.pub_command_keyed global.G_publication_asset = this.pub_assets_keyed // this.pub_command_keyed.initialize(conf) } } module.exports = new PublicationCustomTransitions()