add framework
This commit is contained in:
parent
c7c25255d2
commit
c3cf74f126
11 changed files with 105 additions and 2 deletions
|
@ -14,6 +14,7 @@
|
|||
//= require jquery
|
||||
//= require jquery-ui
|
||||
//= require jquery_ujs
|
||||
//= require action_cable
|
||||
//= require_directory ./lib
|
||||
//= require ./webpacked/metamaps.bundle
|
||||
//= require ./Metamaps.ServerData
|
||||
|
|
4
app/channels/application_cable/channel.rb
Normal file
4
app/channels/application_cable/channel.rb
Normal file
|
@ -0,0 +1,4 @@
|
|||
module ApplicationCable
|
||||
class Channel < ActionCable::Channel::Base
|
||||
end
|
||||
end
|
20
app/channels/application_cable/connection.rb
Normal file
20
app/channels/application_cable/connection.rb
Normal file
|
@ -0,0 +1,20 @@
|
|||
module ApplicationCable
|
||||
class Connection < ActionCable::Connection::Base
|
||||
identified_by :current_user
|
||||
|
||||
def connect
|
||||
self.current_user = find_verified_user
|
||||
logger.add_tags 'ActionCable', current_user.name
|
||||
end
|
||||
|
||||
protected
|
||||
def find_verified_user
|
||||
verified_user = User.find_by(id: cookies.signed['user.id'])
|
||||
if verified_user && cookies.signed['user.expires_at'] > Time.now
|
||||
verified_user
|
||||
else
|
||||
reject_unauthorized_connection
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -38,6 +38,15 @@ class Synapse < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def filtered
|
||||
{
|
||||
id: id,
|
||||
permission: permission,
|
||||
user_id: user_id,
|
||||
collaborator_ids: collaborator_ids
|
||||
}
|
||||
end
|
||||
|
||||
def as_json(_options = {})
|
||||
super(methods: [:user_name, :user_image, :collaborator_ids])
|
||||
end
|
||||
|
|
|
@ -90,6 +90,15 @@ class Topic < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def filtered
|
||||
{
|
||||
id: id,
|
||||
permission: permission,
|
||||
user_id: user_id,
|
||||
collaborator_ids: collaborator_ids
|
||||
}
|
||||
end
|
||||
|
||||
# TODO: move to a decorator?
|
||||
def synapses_csv(output_format = 'array')
|
||||
output = []
|
||||
|
|
10
config/initializers/warden_hooks.rb
Normal file
10
config/initializers/warden_hooks.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
Warden::Manager.after_set_user do |user,auth,opts|
|
||||
scope = opts[:scope]
|
||||
auth.cookies.signed["#{scope}.id"] = user.id
|
||||
auth.cookies.signed["#{scope}.expires_at"] = 30.minutes.from_now
|
||||
end
|
||||
Warden::Manager.before_logout do |user, auth, opts|
|
||||
scope = opts[:scope]
|
||||
auth.cookies.signed["#{scope}.id"] = nil
|
||||
auth.cookies.signed["#{scope}.expires_at"] = nil
|
||||
end
|
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
Metamaps::Application.routes.draw do
|
||||
use_doorkeeper
|
||||
mount ActionCable.server => '/cable'
|
||||
|
||||
root to: 'main#home', via: :get
|
||||
get 'request', to: 'main#requestinvite', as: :request
|
||||
|
|
39
frontend/src/Metamaps/Cable.js
Normal file
39
frontend/src/Metamaps/Cable.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
/* global $, ActionCable */
|
||||
|
||||
import Active from './Active'
|
||||
import DataModel from './DataModel'
|
||||
import Topic from './Topic'
|
||||
|
||||
const Cable = {
|
||||
init: () => {
|
||||
let self = Cable
|
||||
self.cable = ActionCable.createConsumer()
|
||||
},
|
||||
subTopic: id => {
|
||||
let self = Cable
|
||||
self.topicSubs[id] = self.cable.subscriptions.create({
|
||||
channel: 'TopicChannel',
|
||||
id: id
|
||||
}, {
|
||||
received: event => self[event.type](event.data)
|
||||
})
|
||||
},
|
||||
unsubAllTopics: () => {
|
||||
let self = Cable
|
||||
Object.keys(self.topicSubs).forEach(id => {
|
||||
self.topicSubs[id].unsubscribe()
|
||||
})
|
||||
self.topicSubs = {}
|
||||
},
|
||||
newSynapse: data => {
|
||||
const m = Active.Mapper
|
||||
const s = new DataModel.Synapse(data.synapse)
|
||||
const t1 = new DataModel.Topic(data.topic1)
|
||||
const t2 = new DataModel.Topic(data.topic2)
|
||||
if (t1.authorizeToShow(m) && t2.authorizeToShow(m) && s.authorizeToShow(m)) {
|
||||
Topic.fetchForTopicView(data.synapse.id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export default Cable
|
|
@ -87,6 +87,10 @@ const Synapse = Backbone.Model.extend({
|
|||
if (mapper && (this.get('permission') === 'commons' || this.get('collaborator_ids').includes(mapper.get('id')) || this.get('user_id') === mapper.get('id'))) return true
|
||||
else return false
|
||||
},
|
||||
authorizeToShow: function(mapper) {
|
||||
if (this.get('permission') !== 'private' || (mapper && this.get('collaborator_ids').includes(mapper.get('id')) || this.get('user_id') === mapper.get('id'))) return true
|
||||
else return false
|
||||
},
|
||||
authorizePermissionChange: function(mapper) {
|
||||
if (mapper && this.get('user_id') === mapper.get('id')) return true
|
||||
else return false
|
||||
|
|
|
@ -88,6 +88,10 @@ const Topic = Backbone.Model.extend({
|
|||
return false
|
||||
}
|
||||
},
|
||||
authorizeToShow: function(mapper) {
|
||||
if (this.get('permission') !== 'private' || (mapper && this.get('collaborator_ids').includes(mapper.get('id')) || this.get('user_id') === mapper.get('id'))) return true
|
||||
else return false
|
||||
},
|
||||
authorizePermissionChange: function(mapper) {
|
||||
if (mapper && this.get('user_id') === mapper.get('id')) return true
|
||||
else return false
|
||||
|
|
|
@ -2,9 +2,10 @@ import Account from './Account'
|
|||
import Active from './Active'
|
||||
import Admin from './Admin'
|
||||
import AutoLayout from './AutoLayout'
|
||||
import DataModel from './DataModel'
|
||||
import Cable from './Cable'
|
||||
import Control from './Control'
|
||||
import Create from './Create'
|
||||
import DataModel from './DataModel'
|
||||
import Debug from './Debug'
|
||||
import Filter from './Filter'
|
||||
import GlobalUI, {
|
||||
|
@ -38,9 +39,10 @@ Metamaps.Account = Account
|
|||
Metamaps.Active = Active
|
||||
Metamaps.Admin = Admin
|
||||
Metamaps.AutoLayout = AutoLayout
|
||||
Metamaps.DataModel = DataModel
|
||||
Metamaps.Cable = Cable
|
||||
Metamaps.Control = Control
|
||||
Metamaps.Create = Create
|
||||
Metamaps.DataModel = DataModel
|
||||
Metamaps.Debug = Debug
|
||||
Metamaps.Filter = Filter
|
||||
Metamaps.GlobalUI = GlobalUI
|
||||
|
|
Loading…
Add table
Reference in a new issue