|
@@ -3,6 +3,8 @@ include "library.alh"
|
|
|
include "primitives.alh"
|
|
|
include "constructors.alh"
|
|
|
include "object_operations.alh"
|
|
|
+include "mini_modify.alh"
|
|
|
+include "model_management.alh"
|
|
|
|
|
|
Element core = ?
|
|
|
|
|
@@ -114,6 +116,17 @@ Boolean function allow_change_metadata(user_id : String, model_id : String):
|
|
|
else:
|
|
|
return False!
|
|
|
|
|
|
+Boolean function allow_group_modify(user_id : String, group_id : String):
|
|
|
+ if (is_admin(user_id)):
|
|
|
+ // Is admin, so always allow
|
|
|
+ return True!
|
|
|
+ else:
|
|
|
+ if (read_nr_out(set_overlap(allIncomingAssociationInstances(core, user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))) > 0):
|
|
|
+ // We are an owner
|
|
|
+ return True!
|
|
|
+ else:
|
|
|
+ return False!
|
|
|
+
|
|
|
Boolean function check_login(user_id : String):
|
|
|
// TODO
|
|
|
return False!
|
|
@@ -168,6 +181,18 @@ String function get_user_id(name : String):
|
|
|
|
|
|
return ""!
|
|
|
|
|
|
+String function get_group_id(name : String):
|
|
|
+ Element groups
|
|
|
+ String group
|
|
|
+
|
|
|
+ groups = allInstances(core, "Group")
|
|
|
+ while (read_nr_out(groups) > 0):
|
|
|
+ group = set_pop(groups)
|
|
|
+ if (value_eq(read_attribute(core, group, "name"), name)):
|
|
|
+ return group!
|
|
|
+
|
|
|
+ return ""!
|
|
|
+
|
|
|
Void function user_function_skip_init(user_id : String):
|
|
|
Boolean do_continue
|
|
|
String cmd
|
|
@@ -226,6 +251,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
String location
|
|
|
String type_id
|
|
|
Element new_model
|
|
|
+ String new_model_id
|
|
|
|
|
|
output("Creating new model!")
|
|
|
output("Model type?")
|
|
@@ -239,8 +265,10 @@ Void function user_function_skip_init(user_id : String):
|
|
|
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"))
|
|
|
+
|
|
|
+ // TODO Update construct_model call to this interface
|
|
|
+ // 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)
|
|
@@ -263,6 +291,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
elif (cmd == "model_modify"):
|
|
|
// Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
|
|
|
String model_id
|
|
|
+ String type_id
|
|
|
|
|
|
output("Which model do you want to modify?")
|
|
|
model_id = get_model_id(input())
|
|
@@ -271,7 +300,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
if (allow_read(user_id, model_id)):
|
|
|
type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
|
|
|
if (allow_read(user_id, type_id)):
|
|
|
- mini_modify(import_node(read_attribute(core, model_id, "location")), allow_write(user_id, model_id))
|
|
|
+ modify(import_node(read_attribute(core, model_id, "location")), allow_write(user_id, model_id))
|
|
|
else:
|
|
|
output("You are not allowed to read the type model!")
|
|
|
else:
|
|
@@ -300,7 +329,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
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"))
|
|
|
+ output(string_join((string_join(" ", 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
|
|
@@ -311,6 +340,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
String group
|
|
|
String name
|
|
|
String type
|
|
|
+ String size
|
|
|
|
|
|
models = allInstances(core, "Model")
|
|
|
while (read_nr_out(models) > 0):
|
|
@@ -319,7 +349,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
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"))
|
|
|
+ size = cast_i2s(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)
|
|
|
|
|
@@ -333,6 +363,8 @@ Void function user_function_skip_init(user_id : String):
|
|
|
Element merged_formalism
|
|
|
String old_type_id
|
|
|
String type_id
|
|
|
+ String location
|
|
|
+ String new_model_id
|
|
|
|
|
|
source = create_node()
|
|
|
target = create_node()
|
|
@@ -347,7 +379,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
|
|
|
if (bool_or(old_type_id == "", type_id == old_type_id)):
|
|
|
set_add(source, model_id)
|
|
|
- set_add(all_formalisms, create_tuple(name, model_id))
|
|
|
+ set_add(all_formalisms, create_tuple(name, import_node(read_attribute(core, model_id, "location"))))
|
|
|
old_type_id = type_id
|
|
|
elif (old_type_id != type_id):
|
|
|
// Already have a previous type_id and now another: CLASH
|
|
@@ -368,7 +400,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
if (bool_or(old_type_id == "", type_id == old_type_id)):
|
|
|
set_add(target, model_id)
|
|
|
if (bool_not(set_in(source, model_id))):
|
|
|
- set_add(all_formalisms, create_tuple(name, model_id))
|
|
|
+ set_add(all_formalisms, create_tuple(name, import_node(read_attribute(core, model_id, "location"))))
|
|
|
old_type_id = type_id
|
|
|
elif (old_type_id != type_id):
|
|
|
// Already have a previous type_id and now another: CLASH
|
|
@@ -406,6 +438,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
|
|
|
elif (cmd == "permission_modify"):
|
|
|
String permissions
|
|
|
+ Integer permission
|
|
|
String model_id
|
|
|
|
|
|
output("Which model do you want to change permissions of?")
|
|
@@ -418,10 +451,10 @@ Void function user_function_skip_init(user_id : String):
|
|
|
Boolean fail
|
|
|
Integer i
|
|
|
i = 0
|
|
|
- if (string_length(permissions) != 3):
|
|
|
+ if (string_len(permissions) != 3):
|
|
|
fail = True
|
|
|
while (bool_and(bool_not(fail), i < 3)):
|
|
|
- permission = cast_s2i(string_read(permissions, i))
|
|
|
+ permission = cast_s2i(string_get(permissions, i))
|
|
|
if (bool_or(permission < 0, permission > 2)):
|
|
|
fail = True
|
|
|
|
|
@@ -447,7 +480,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
output("New owner?")
|
|
|
user_id = get_user_id(input())
|
|
|
if (user_id != ""):
|
|
|
- model_delete_element(set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
|
|
|
+ model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
|
|
|
instantiate_link(core, "owner", "", model_id, user_id)
|
|
|
else:
|
|
|
output("No such user!")
|
|
@@ -468,7 +501,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
output("New group?")
|
|
|
group_id = get_group_id(input())
|
|
|
if (group_id != ""):
|
|
|
- model_delete_element(set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
|
|
|
+ model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
|
|
|
instantiate_link(core, "group", "", model_id, group_id)
|
|
|
else:
|
|
|
output("No such group!")
|
|
@@ -489,7 +522,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
group_id = instantiate_node(core, "Group", "")
|
|
|
instantiate_attribute(core, group_id, "name", name)
|
|
|
instantiate_link(core, "belongsTo", "", user_id, group_id)
|
|
|
- isntantiate_link(core, "owner", "", group_id, user_id)
|
|
|
+ instantiate_link(core, "owner", "", group_id, user_id)
|
|
|
output("Group created!")
|
|
|
else:
|
|
|
output("Group already exists")
|
|
@@ -513,6 +546,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
elif (cmd == "group_owner_add"):
|
|
|
// Add an owner to your group
|
|
|
String group_id
|
|
|
+ String other_user_id
|
|
|
|
|
|
output("Which group do you want to add an owner to?")
|
|
|
group_id = get_group_id(input())
|
|
@@ -545,6 +579,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
elif (cmd == "group_owner_delete"):
|
|
|
// Remove an owner from your group
|
|
|
String group_id
|
|
|
+ String other_user_id
|
|
|
|
|
|
output("Which group do you want to disown someone from?")
|
|
|
group_id = get_group_id(input())
|
|
@@ -575,6 +610,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
elif (cmd == "group_join"):
|
|
|
// Add someone to your group
|
|
|
String group_id
|
|
|
+ String other_user_id
|
|
|
|
|
|
output("Which group do you want to add someone to?")
|
|
|
group_id = get_group_id(input())
|
|
@@ -601,6 +637,7 @@ Void function user_function_skip_init(user_id : String):
|
|
|
elif (cmd == "group_kick"):
|
|
|
// Remove someone from your group
|
|
|
String group_id
|
|
|
+ String other_user_id
|
|
|
|
|
|
output("Which group do you want to kick someone from?")
|
|
|
group_id = get_group_id(input())
|
|
@@ -639,12 +676,12 @@ Void function user_function_skip_init(user_id : String):
|
|
|
groups = allAssociationDestinations(core, user_id, "belongsTo")
|
|
|
while (True):
|
|
|
group_id = set_pop(groups)
|
|
|
- if (set_in(allAssociation(core, group_id, "owner"), user_id)):
|
|
|
+ if (set_in(allOutgoingAssociationInstances(core, group_id, "owner"), user_id)):
|
|
|
admin = " A "
|
|
|
else:
|
|
|
admin = " "
|
|
|
|
|
|
- output(admin + read_attribute(core, group_id, "name"))
|
|
|
+ output(string_join(admin, read_attribute(core, group_id, "name")))
|
|
|
|
|
|
elif (cmd == "admin_promote"):
|
|
|
// Promote a user to admin status
|