Skip to content

Commit

Permalink
fixup: changes after @ybon's review.
Browse files Browse the repository at this point in the history
  • Loading branch information
almet committed May 31, 2024
1 parent ba96212 commit d4db078
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 32 deletions.
5 changes: 3 additions & 2 deletions umap/static/umap/js/modules/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,15 @@ export const SCHEMA = {
},
outlink: {
type: String,
impacts: ['data'],
impacts: [],
label: translate('Link to…'),
helpEntries: 'outlink',
placeholder: 'http://...',
inheritable: true,
},
outlinkTarget: {
type: String,
impacts: ['data'],
impacts: [],
label: translate('Open link in…'),
inheritable: true,
default: 'blank',
Expand Down Expand Up @@ -511,6 +511,7 @@ export const SCHEMA = {
label: translate('Default zoom level'),
inheritable: true,
},
// FIXME This is an internal Leaflet property, we might want to do this differently.
_latlng: {
type: Object,
impacts: ['data'],
Expand Down
4 changes: 2 additions & 2 deletions umap/static/umap/js/modules/sync/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MapUpdater, DataLayerUpdater, FeatureUpdater } from './updaters.js'
export class SyncEngine {
constructor(map) {
this.map = map
this.receiver = new MessagesDispatcher(this.map)
this.dispatcher = new MessagesDispatcher(this.map)
this._initialize()
}
_initialize() {
Expand All @@ -22,7 +22,7 @@ export class SyncEngine {
}

start(webSocketURI, authToken) {
this.transport = new WebSocketTransport(webSocketURI, authToken, this.receiver)
this.transport = new WebSocketTransport(webSocketURI, authToken, this.dispatcher)
this.sender = new MessagesSender(this.transport)
this.upsert = this.sender.upsert.bind(this.sender)
this.update = this.sender.update.bind(this.sender)
Expand Down
17 changes: 4 additions & 13 deletions umap/static/umap/js/modules/sync/updaters.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export class DataLayerUpdater extends BaseUpdater {
upsert({ value }) {
// Inserts does not happen (we use multiple updates instead).
this.map.createDataLayer(value, false)
this.map.render()
}

update({ key, metadata, value }) {
Expand All @@ -60,14 +61,6 @@ export class DataLayerUpdater extends BaseUpdater {
}
}

/**
* This is an abstract base class
* And needs to be subclassed to be used.
*
* The child classes need to expose:
* - `featureClass`: the name of the class to create the feature
* - `featureArgument`: an object with the properties to pass to the class when bulding it.
**/
export class FeatureUpdater extends BaseUpdater {
getFeatureFromMetadata({ id, layerId }) {
const datalayer = this.getDataLayerFromID(layerId)
Expand All @@ -79,16 +72,14 @@ export class FeatureUpdater extends BaseUpdater {
let { id, layerId } = metadata
const datalayer = this.getDataLayerFromID(layerId)
let feature = this.getFeatureFromMetadata(metadata, value)
if (feature === undefined) {
console.log(`Unable to find feature with id = ${metadata.id}. Creating a new one`)
}

feature = datalayer.geometryToFeature({
geometry: value.geometry,
geojson: value,
id,
feature,
})
feature.addTo(datalayer)
datalayer.addLayer(feature)
}

// Update a property of an object
Expand All @@ -103,9 +94,9 @@ export class FeatureUpdater extends BaseUpdater {
datalayer.geometryToFeature({ geometry: value, id: metadata.id, feature })
default:
this.updateObjectValue(feature, key, value)
feature.datalayer.indexProperties(feature)
}

feature.datalayer.indexProperties(feature)
feature.render([key])
}

Expand Down
25 changes: 10 additions & 15 deletions umap/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -792,23 +792,18 @@ def get_websocket_auth_token(request, map_id, map_inst):
"""
map_object: Map = Map.objects.get(pk=map_id)

if map_object.can_edit(request.user, request):
permissions = ["edit"]
if map_object.is_owner(request.user, request):
permissions.append("owner")
permissions = ["edit"]
if map_object.is_owner(request.user, request):
permissions.append("owner")

if request.user.is_authenticated:
user = request.user.pk
else:
user = "anonymous"
signed_token = TimestampSigner().sign_object(
{"user": user, "map_id": map_id, "permissions": permissions}
)
return simple_json_response(token=signed_token)
if request.user.is_authenticated:
user = request.user.pk
else:
return HttpResponseForbidden(
_("You cannot edit this map with your current permissions.")
)
user = "anonymous"
signed_token = TimestampSigner().sign_object(
{"user": user, "map_id": map_id, "permissions": permissions}
)
return simple_json_response(token=signed_token)


class MapUpdate(FormLessEditMixin, PermissionsMixin, UpdateView):
Expand Down

0 comments on commit d4db078

Please sign in to comment.