|
@@ -66,8 +66,14 @@ Integer function get_relation_to_model(user_id : String, model_id : String):
|
|
|
// We are not related whatsoever
|
|
|
return 2!
|
|
|
|
|
|
-Boolean function allow_read(user_id : String, model_id : String):
|
|
|
+Boolean function is_admin(user_id : String):
|
|
|
if (read_attribute(core, user_id, "admin")):
|
|
|
+ return True!
|
|
|
+ else:
|
|
|
+ return False!
|
|
|
+
|
|
|
+Boolean function allow_read(user_id : String, model_id : String):
|
|
|
+ if (is_admin(user_id)):
|
|
|
// Is admin, so always allow
|
|
|
return True!
|
|
|
else:
|
|
@@ -80,7 +86,7 @@ Boolean function allow_read(user_id : String, model_id : String):
|
|
|
return False!
|
|
|
|
|
|
Boolean function allow_write(user_id : String, model_id : String):
|
|
|
- if (read_attribute(core, user_id, "admin")):
|
|
|
+ if (is_admin(user_id)):
|
|
|
// Is admin, so always allow
|
|
|
return True!
|
|
|
else:
|
|
@@ -92,7 +98,21 @@ Boolean function allow_write(user_id : String, model_id : String):
|
|
|
else:
|
|
|
return False!
|
|
|
|
|
|
+Boolean function allow_change_metadata(user_id : String, model_id : String):
|
|
|
+ if (is_admin(user_id)):
|
|
|
+ // Is admin, so always allow
|
|
|
+ return True!
|
|
|
+ else:
|
|
|
+ if (get_relation_to_model(user_id, model_id) == "0"):
|
|
|
+ // Only owner can chmod
|
|
|
+ return True!
|
|
|
+ else:
|
|
|
+ return False!
|
|
|
+
|
|
|
Void function user_function():
|
|
|
+ // Now the username is bound to the task ID, so there is no problem
|
|
|
+ // TODO check whether username isn't registered yet
|
|
|
+
|
|
|
// Add user to Core Formalism
|
|
|
String user_id
|
|
|
user_id = instantiate_node(core, "User", "")
|
|
@@ -105,13 +125,203 @@ Void function user_function():
|
|
|
// User destroyed already, so just stop execution
|
|
|
return !
|
|
|
|
|
|
+String function get_model_id(name : String):
|
|
|
+ Element models
|
|
|
+ String model
|
|
|
+
|
|
|
+ models = allInstances(core, "Model")
|
|
|
+ while (read_nr_out(models) > 0):
|
|
|
+ model = set_pop(models)
|
|
|
+ if (read_attribute(core, model, "name") == name):
|
|
|
+ return model!
|
|
|
+
|
|
|
+ return ""!
|
|
|
+
|
|
|
Void function user_function_skip_init(user_id : String)
|
|
|
Boolean do_continue
|
|
|
+ String cmd
|
|
|
|
|
|
do_continue = True
|
|
|
|
|
|
+ output("Welcome to the Model Management Interface v2.0!")
|
|
|
+ output("Use the 'help' command for a list of possible commands")
|
|
|
+
|
|
|
while (do_continue):
|
|
|
- // TODO model management interface with access control restrictions
|
|
|
+ output("Ready for command...")
|
|
|
+ cmd = input()
|
|
|
+ if (cmd == "help"):
|
|
|
+ output("Model operations")
|
|
|
+ output(" model_add -- Add a new model")
|
|
|
+ output(" model_modify -- Modify an existing model")
|
|
|
+ output(" model_delete -- [TODO] Delete a model and all related transformations")
|
|
|
+ output(" model_list -- List all models")
|
|
|
+ output(" model_list_full -- List all models with full info")
|
|
|
+ output("")
|
|
|
+ output("Transformation-specific operations")
|
|
|
+ output(" transformation_add -- TODO")
|
|
|
+ output(" transformation_source_add -- TODO")
|
|
|
+ output(" transformation_source_delete -- TODO")
|
|
|
+ output(" transformation_target_add -- TODO")
|
|
|
+ output(" transformation_target_delete -- TODO")
|
|
|
+ output(" transformation_execute -- TODO")
|
|
|
+ output("")
|
|
|
+ output("Model permission operations")
|
|
|
+ output(" permission_modify -- TODO")
|
|
|
+ output(" permission_owner -- TODO")
|
|
|
+ output(" permission_group -- TODO")
|
|
|
+ output("")
|
|
|
+ output("Group operations")
|
|
|
+ output(" group_create -- TODO")
|
|
|
+ output(" group_delete -- TODO")
|
|
|
+ output(" group_owner -- TODO")
|
|
|
+ output(" group_join -- TODO")
|
|
|
+ output(" group_kick -- TODO")
|
|
|
+ output("")
|
|
|
+ output("Admin operations")
|
|
|
+ output(" admin_promote -- Promote a user to admin status")
|
|
|
+ output(" admin_demote -- Demote a user to normal status")
|
|
|
+ output("")
|
|
|
+ output("General operations")
|
|
|
+ output(" account_delete -- Remove current user and revoke all permissions ")
|
|
|
+
|
|
|
+ elif (cmd == "model_add"):
|
|
|
+ // Model addition operation, which uses model upload commands of the compiler
|
|
|
+ String name
|
|
|
+ String type
|
|
|
+ String location
|
|
|
+ Element new_model
|
|
|
+
|
|
|
+ output("Creating new model!")
|
|
|
+ output("Model type?")
|
|
|
+ type_id = get_model_id(input())
|
|
|
+ if (type_id != ""):
|
|
|
+ // Type exists
|
|
|
+ if (allow_read(user_id, type_id)):
|
|
|
+ // And is readable
|
|
|
+ output("Model name?")
|
|
|
+ name = input()
|
|
|
+ if (get_model_id(name) == ""):
|
|
|
+ // Model doesn't exist yet
|
|
|
+ output("Waiting for model constructors...")
|
|
|
+ // TODO update for access control
|
|
|
+ new_model = construct_model(read_attribute(core, type_id, "location"))
|
|
|
+ output("Model upload success!")
|
|
|
+ location = "/models/" + cast_id2s(new_model)
|
|
|
+ export_node(new_model, location)
|
|
|
+
|
|
|
+ // Manage meta-info
|
|
|
+ new_model_id = instantiate_node(core, "Model", "")
|
|
|
+ instantiate_attribute(core, new_model_id, "name", name)
|
|
|
+ instantiate_attribute(core, new_model_id, "location", location)
|
|
|
+ instantiate_attribute(core, new_model_id, "permissions", "300")
|
|
|
+ instantiate_link(core, "owner", "", new_model_id, user_id)
|
|
|
+ instantiate_link(core, "instanceOf", "", new_model_id, type_id)
|
|
|
+ output("Meta-info correctly set!")
|
|
|
+ else:
|
|
|
+ output("Model with that name already exists!")
|
|
|
+ else:
|
|
|
+ output("You are not allowed to read this type model!")
|
|
|
+ else:
|
|
|
+ output("Could not find type model!")
|
|
|
+
|
|
|
+ elif (cmd == "model_modify"):
|
|
|
+ // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
|
|
|
+ String model_id
|
|
|
+
|
|
|
+ output("Which model do you want to modify?")
|
|
|
+ model_id = get_model_id(input())
|
|
|
+
|
|
|
+ if (model_id != ""):
|
|
|
+ if (allow_read(user_id, model_id)):
|
|
|
+ mini_modify(import_node(read_attribute(core, model_id, "location")), allow_write(user_id, model_id))
|
|
|
+ else:
|
|
|
+ output("You are not allowed to read this model!")
|
|
|
+ else:
|
|
|
+ output("Could not find model!")
|
|
|
+
|
|
|
+ elif (cmd == "model_delete"):
|
|
|
+ // Delete a model and all of its related transformations
|
|
|
+ String model_id
|
|
|
+
|
|
|
+ output("=================================================")
|
|
|
+ output("WARNING: Deletion is a very destructive operation")
|
|
|
+ output(" as it also deletes all transformations ")
|
|
|
+ output(" defined which make use of this model! ")
|
|
|
+ output("=================================================")
|
|
|
+
|
|
|
+ output("")
|
|
|
+ output("Currently not supported!")
|
|
|
+
|
|
|
+ elif (cmd == "model_list"):
|
|
|
+ // List all models
|
|
|
+ Element models
|
|
|
+ String m
|
|
|
+
|
|
|
+ models = allInstances(core, "Model")
|
|
|
+ while (read_nr_out(models) > 0):
|
|
|
+ m = set_pop(models)
|
|
|
+ output((" " + (read_attribute(core, m, "name")) + " : ") + read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name"))
|
|
|
+
|
|
|
+ elif (cmd == "model_list_full")
|
|
|
+ // List all models with full info
|
|
|
+ Element models
|
|
|
+ String m
|
|
|
+ String permissions
|
|
|
+ String owner
|
|
|
+ String group
|
|
|
+ String name
|
|
|
+ String type
|
|
|
+
|
|
|
+ models = allInstances(core, "Model")
|
|
|
+ while (read_nr_out(models) > 0):
|
|
|
+ m = set_pop(models)
|
|
|
+ permissions = read_attribute(core, m, "permissions")
|
|
|
+ owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
|
|
|
+ group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
|
|
|
+ name = read_attribute(core, m, "name")
|
|
|
+ size = read_nr_out(dict_read(import_node(read_attribute(core, m, "location")), "model"))
|
|
|
+ type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
|
|
|
+ output(((((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + size) + " ") + name) + " : ") + type)
|
|
|
+
|
|
|
+ elif (cmd == "admin_promote"):
|
|
|
+ // Promote a user to admin status
|
|
|
+ if (is_admin(user_id)):
|
|
|
+ String other_user_id
|
|
|
+
|
|
|
+ output("Which user do you want to promote?")
|
|
|
+ other_user_id = get_user_id(input())
|
|
|
+ if (other_user_id != ""):
|
|
|
+ unset_attribute(core, other_user_id, "admin")
|
|
|
+ instantiate_attribute(core, other_user_id, "admin", True)
|
|
|
+ output("Permissions granted!")
|
|
|
+ else:
|
|
|
+ output("No such user!")
|
|
|
+ else:
|
|
|
+ output("Permission denied!")
|
|
|
+
|
|
|
+ elif (cmd == "admin_demote"):
|
|
|
+ // Demote a user to normal status
|
|
|
+ if (is_admin(user_id)):
|
|
|
+ String other_user_id
|
|
|
+
|
|
|
+ output("Which user do you want to demote?")
|
|
|
+ other_user_id = get_user_id(input())
|
|
|
+ if (other_user_id != ""):
|
|
|
+ unset_attribute(core, other_user_id, "admin")
|
|
|
+ instantiate_attribute(core, other_user_id, "admin", False)
|
|
|
+ output("Permissions revoked!")
|
|
|
+ else:
|
|
|
+ output("No such user!")
|
|
|
+ else:
|
|
|
+ output("Permission denied!")
|
|
|
+
|
|
|
+ elif (cmd == "exit"):
|
|
|
+ // Exit by actually removing the user and decoupling it from all of its models
|
|
|
+ // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
|
|
|
+ do_continue = False
|
|
|
|
|
|
// Delete user from Core Formalism
|
|
|
+ model_delete_element(core, user_id)
|
|
|
+ output("Goodbye!")
|
|
|
+
|
|
|
return !
|