Skip to content

Commit

Permalink
Access Control: adapt to recent core changes #262.
Browse files Browse the repository at this point in the history
Functionality is restored.

See ticket 262
  • Loading branch information
jri committed Jul 24, 2012
1 parent 4da6c66 commit d98e2ba
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 36 deletions.
32 changes: 10 additions & 22 deletions modules/dm4-accesscontrol/src/main/resources/web/script/plugin.js
Expand Up @@ -174,21 +174,21 @@ dm4c.add_plugin("de.deepamehta.accesscontrol", function() {
var username = user.get("dm4.accesscontrol.username")
js.set_cookie("dm4_username", username)
//
adjust_create_widget()
login_widget.show_user(username)
dm4c.restore_selection()
//
dm4c.trigger_plugin_hook("user_logged_in", user)
dm4c.reload_types(function() {
login_widget.show_user(username)
dm4c.restore_selection()
dm4c.trigger_plugin_hook("user_logged_in", user)
})
}

this.do_logout = function() {
js.remove_cookie("dm4_username")
//
adjust_create_widget()
login_widget.show_login()
dm4c.restore_selection()
//
dm4c.trigger_plugin_hook("user_logged_out")
dm4c.reload_types(function() {
login_widget.show_login()
dm4c.restore_selection()
dm4c.trigger_plugin_hook("user_logged_out")
})
}

// ---
Expand Down Expand Up @@ -250,16 +250,4 @@ dm4c.add_plugin("de.deepamehta.accesscontrol", function() {
function encrypt_password(password) {
return ENCRYPTED_PASSWORD_PREFIX + SHA256(password)
}

// ---

function adjust_create_widget() {
dm4c.reload_types()
var menu = dm4c.refresh_create_menu()
if (menu.get_item_count()) {
$("#create-widget").show()
} else {
$("#create-widget").hide()
}
}
})
Expand Up @@ -47,6 +47,7 @@ List<Object> fireEvent(CoreEvent event, Object... params) {
if (listeners == null) {
return results;
}
// ### FIXME: ConcurrentModificationException might occur
for (Listener listener : listeners) {
Object result = deliverEvent(listener, event, params);
if (result != null) {
Expand Down
Expand Up @@ -371,7 +371,9 @@ private void addService(Object service, String serviceInterface) {
logger.info("Adding DeepaMehta 4 core service to " + this);
setCoreService((EmbeddedService) service);
openPluginServiceTrackers();
registerListeners();
// Note: registering the listeners is deferred until the plugin is installed and the
// CoreEvent.POST_INSTALL_PLUGIN is delivered. See activate() below.
// Consider the Access Control plugin: it can't set a topic's creator before the "admin" user is created.
checkServiceAvailability();
} else if (service instanceof WebPublishingService) {
logger.info("Adding Web Publishing service to " + this);
Expand Down Expand Up @@ -470,6 +472,7 @@ private synchronized boolean activate() {
//
logger.info("----- Activating " + this + " -----");
installPluginInDB(); // relies on DeepaMehtaService
registerListeners(); // relies on DeepaMehtaService
registerPlugin(); // relies on DeepaMehtaService (and committed migrations)
logger.info("----- Activation of " + this + " complete -----");
return true;
Expand Down
37 changes: 25 additions & 12 deletions modules/dm4-webclient/src/main/resources/web/script/webclient.js
Expand Up @@ -697,7 +697,7 @@ function Webclient() {
dataType: "script",
async: async || false,
error: function(jq_xhr, text_status, error_thrown) {
throw "WebclientError: loading script failed (" + text_status + ": " + error_thrown + ")"
throw "WebclientError: loading script " + url + " failed (" + text_status + ": " + error_thrown + ")"
}
})
}
Expand Down Expand Up @@ -815,9 +815,15 @@ function Webclient() {

// ---

this.reload_types = function() {
this.reload_types = function(callback) {
// setup tracker
var tracker = new LoadTracker(2, function() { // 2 loads: topic types and association types
adjust_create_widget()
callback()
})
// reload types
type_cache.clear()
load_types()
type_cache.load_types(tracker)
}

// === View Configuration ===
Expand Down Expand Up @@ -978,14 +984,12 @@ function Webclient() {
*/
function setup_gui() {
dm4c.log("Setting up GUI")
//
// 1) Setting up the create widget
// Note: the create menu must be popularized *after* the plugins are loaded.
// Two hooks are involved: post_refresh_create_menu() and has_create_permission().
dm4c.refresh_create_menu()
adjust_create_widget()
//
if (!dm4c.toolbar.create_menu.get_item_count()) {
dm4c.toolbar.create_widget.hide()
}
// 2) Initialize plugins
// Note: in order to let a plugin provide the initial canvas rendering (the deepamehta-topicmaps plugin
// does!) the "init" hook is triggered *after* creating the canvas.
Expand All @@ -995,6 +999,16 @@ function Webclient() {
dm4c.trigger_plugin_hook("init")
}

function adjust_create_widget() {
dm4c.refresh_create_menu()
//
if (dm4c.toolbar.create_menu.get_item_count()) {
dm4c.toolbar.create_widget.show()
} else {
dm4c.toolbar.create_widget.hide()
}
}

/**
* Save the page panel before the user opens a menu.
*
Expand Down Expand Up @@ -1024,7 +1038,7 @@ function Webclient() {
// ---

/**
* Refreshes a menu so it reflects the current set of known topic types.
* Refreshes a type menu to reflect the updated type cache (after adding/removing/renaming a type).
* <p>
* Utility method for plugin developers.
*
Expand Down Expand Up @@ -1055,6 +1069,8 @@ function Webclient() {
}

/**
* Refreshes the create menu to reflect the updated type cache (after adding/removing/renaming a type).
* <p>
* Utility method for plugin developers.
*/
this.refresh_create_menu = function() {
Expand All @@ -1063,8 +1079,6 @@ function Webclient() {
})
//
dm4c.trigger_plugin_hook("post_refresh_create_menu", dm4c.toolbar.create_menu)
//
return dm4c.toolbar.create_menu
}

// === Images ===
Expand Down Expand Up @@ -1282,8 +1296,7 @@ function Webclient() {
//
// 2) Setup Load Tracker
var items_to_load = pm.retrieve_plugin_list()
var number_of_loads = items_to_load + 2 // +2 loads: topic types and association types
var tracker = new LoadTracker(number_of_loads, setup_gui)
var tracker = new LoadTracker(items_to_load + 2, setup_gui) // +2 loads: topic types and association types
//
// 3) Load Plugins
pm.load_plugins(tracker)
Expand Down
Expand Up @@ -274,7 +274,11 @@ public TopicType getTopicType(@PathParam("uri") String uri, @HeaderParam("Cookie
@Path("/topictype/all")
public Set<TopicType> getAllTopicTypes(@HeaderParam("Cookie") ClientState clientState) {
try {
return dms.getAllTopicTypes(clientState);
Set<TopicType> topicTypes = dms.getAllTopicTypes(clientState);
//
firePreSend(topicTypes, clientState);
//
return topicTypes;
} catch (Exception e) {
throw new WebApplicationException(e);
}
Expand Down Expand Up @@ -443,6 +447,12 @@ private void firePreSend(ResultSet<Topic> topics, ClientState clientState) {
}
}

private void firePreSend(Set<TopicType> topicTypes, ClientState clientState) {
for (TopicType topicType : topicTypes) {
firePreSend(topicType, clientState);
}
}

private void firePreSend(Directives directives, ClientState clientState) {
for (Directives.Entry entry : directives) {
switch (entry.dir) {
Expand Down

0 comments on commit d98e2ba

Please sign in to comment.