update permission of topics and synapses as map perm changes, when defer_to_map
This commit is contained in:
parent
3c67f68d3b
commit
b09a98184c
7 changed files with 8 additions and 19 deletions
|
@ -36,11 +36,7 @@ class Synapse < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def calculated_permission
|
||||
defer_to_map&.permission || permission
|
||||
end
|
||||
|
||||
def as_json(_options = {})
|
||||
super(methods: [:user_name, :user_image, :calculated_permission, :collaborator_ids])
|
||||
super(methods: [:user_name, :user_image, :collaborator_ids])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -75,12 +75,8 @@ class Topic < ApplicationRecord
|
|||
Pundit.policy_scope(user, maps).map(&:id)
|
||||
end
|
||||
|
||||
def calculated_permission
|
||||
defer_to_map&.permission || permission
|
||||
end
|
||||
|
||||
def as_json(options = {})
|
||||
super(methods: [:user_name, :user_image, :calculated_permission, :collaborator_ids])
|
||||
super(methods: [:user_name, :user_image, :collaborator_ids])
|
||||
.merge(inmaps: inmaps(options[:user]), inmapsLinks: inmapsLinks(options[:user]),
|
||||
map_count: map_count(options[:user]), synapse_count: synapse_count(options[:user]))
|
||||
end
|
||||
|
|
|
@ -38,7 +38,6 @@ const Synapse = Backbone.Model.extend({
|
|||
|
||||
newOptions.success = function(model, response, opt) {
|
||||
if (s) s(model, response, opt)
|
||||
model.set('calculated_permission', model.get('permission'))
|
||||
model.trigger('saved')
|
||||
|
||||
if (permBefore === 'private' && model.get('permission') !== 'private') {
|
||||
|
@ -85,7 +84,7 @@ const Synapse = Backbone.Model.extend({
|
|||
</li>`
|
||||
},
|
||||
authorizeToEdit: function(mapper) {
|
||||
if (mapper && (this.get('calculated_permission') === 'commons' || this.get('collaborator_ids').includes(mapper.get('id')) || this.get('user_id') === mapper.get('id'))) return true
|
||||
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
|
||||
},
|
||||
authorizePermissionChange: function(mapper) {
|
||||
|
|
|
@ -37,7 +37,6 @@ const Topic = Backbone.Model.extend({
|
|||
|
||||
newOptions.success = function(model, response, opt) {
|
||||
if (s) s(model, response, opt)
|
||||
model.set('calculated_permission', model.get('permission'))
|
||||
model.trigger('saved')
|
||||
|
||||
if (permBefore === 'private' && model.get('permission') !== 'private') {
|
||||
|
@ -82,7 +81,7 @@ const Topic = Backbone.Model.extend({
|
|||
authorizeToEdit: function(mapper) {
|
||||
if (mapper &&
|
||||
(this.get('user_id') === mapper.get('id') ||
|
||||
this.get('calculated_permission') === 'commons' ||
|
||||
this.get('permission') === 'commons' ||
|
||||
this.get('collaborator_ids').includes(mapper.get('id')))) {
|
||||
return true
|
||||
} else {
|
||||
|
|
|
@ -295,8 +295,7 @@ const Import = {
|
|||
permission: topicPermision,
|
||||
defer_to_map_id: deferToMapId,
|
||||
desc: desc || '',
|
||||
link: link || '',
|
||||
calculated_permission: Active.Map.get('permission')
|
||||
link: link || ''
|
||||
})
|
||||
DataModel.Topics.add(topic)
|
||||
|
||||
|
|
|
@ -174,7 +174,7 @@ const SynapseCard = {
|
|||
|
||||
add_perms_form: function(synapse) {
|
||||
// permissions - if owner, also allow permission editing
|
||||
$('#editSynLowerBar').append('<div class="mapPerm ' + synapse.get('calculated_permission').substring(0, 2) + '"></div>')
|
||||
$('#editSynLowerBar').append('<div class="mapPerm ' + synapse.get('permission').substring(0, 2) + '"></div>')
|
||||
|
||||
// ability to change permission
|
||||
var selectingPermission = false
|
||||
|
|
|
@ -448,8 +448,8 @@ const TopicCard = {
|
|||
nodeValues.inmaps += '<li class="hideExtra extraText"><a href="' + url + '">' + inmapsAr[i] + '</a></li>'
|
||||
}
|
||||
}
|
||||
nodeValues.permission = topic.get('calculated_permission')
|
||||
nodeValues.mk_permission = topic.get('calculated_permission').substring(0, 2)
|
||||
nodeValues.permission = topic.get('permission')
|
||||
nodeValues.mk_permission = topic.get('permission').substring(0, 2)
|
||||
nodeValues.map_count = topic.get('map_count').toString()
|
||||
nodeValues.synapse_count = topic.get('synapse_count').toString()
|
||||
nodeValues.id = topic.isNew() ? topic.cid : topic.id
|
||||
|
|
Loading…
Add table
Reference in a new issue