core_algorithm.alc 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  1. include "modelling.alh"
  2. include "library.alh"
  3. include "primitives.alh"
  4. include "constructors.alh"
  5. include "object_operations.alh"
  6. include "mini_modify.alh"
  7. include "model_management.alh"
  8. Element core = ?
  9. Void function main():
  10. // Initialize the Core Formalism
  11. String core_location
  12. String core_model
  13. String admin_group
  14. String admin_user
  15. core_location = "models/CoreFormalism"
  16. // Create the Model itself and make public
  17. core = instantiate_model(import_node(core_location))
  18. // Create admin group
  19. admin_group = instantiate_node(core, "Group", "")
  20. instantiate_attribute(core, admin_group, "name", "admin")
  21. // Create admin user
  22. admin_user = instantiate_node(core, "User", "")
  23. output("Desired username for admin user?")
  24. instantiate_attribute(core, admin_user, "name", input())
  25. instantiate_attribute(core, admin_user, "admin", True)
  26. // Create link between admin user and group
  27. instantiate_link(core, "ownedBy", "", admin_group, admin_user)
  28. instantiate_link(core, "belongsTo", "", admin_user, admin_group)
  29. // Add the core formalism already
  30. core_model = instantiate_node(core, "Model", "")
  31. instantiate_attribute(core, core_model, "name", "CoreFormalism")
  32. instantiate_attribute(core, core_model, "location", core_location)
  33. instantiate_attribute(core, core_model, "permissions", "220")
  34. // Make necessary links for the formalism to the owners
  35. instantiate_link(core, "group", "", core_model, admin_group)
  36. instantiate_link(core, "owner", "", core_model, admin_user)
  37. // Switch all new users to the user_function
  38. // This accesses the bootstrap level, so do not change this unless you know what you are doing
  39. Element root
  40. root = read_root()
  41. dict_delete(root["__hierarchy"], "__IP")
  42. dict_add(root["__hierarchy"], "__IP", user_function)
  43. // Call this for ourselves as well
  44. user_function_skip_init(admin_user)
  45. // Done, so finish up
  46. // Admin user will have been deleted by the user_function as usual
  47. // Note that if there are no admin users left, it will be very difficult to manage, as nobody will have admin permissions!
  48. return !
  49. Integer function get_relation_to_model(user_id : String, model_id : String):
  50. if (set_in(allAssociationDestinations(core, model_id, "owner"), user_id)):
  51. // We are the owner
  52. return 0!
  53. else:
  54. String group_id
  55. group_id = set_pop(allAssociationDestinations(core, model_id, "group"))
  56. if (set_in(allAssociationDestinations(core, user_id, "belongsTo"), group_id)):
  57. // We are in the owning group
  58. return 1!
  59. else:
  60. // We are not related whatsoever
  61. return 2!
  62. Boolean function is_admin(user_id : String):
  63. if (read_attribute(core, user_id, "admin")):
  64. return True!
  65. else:
  66. return False!
  67. Boolean function allow_read(user_id : String, model_id : String):
  68. if (is_admin(user_id)):
  69. // Is admin, so always allow
  70. return True!
  71. else:
  72. // Check permissions
  73. String permission
  74. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  75. if (bool_or(permission == "1", permission == "2")):
  76. return True!
  77. else:
  78. return False!
  79. Boolean function allow_write(user_id : String, model_id : String):
  80. if (is_admin(user_id)):
  81. // Is admin, so always allow
  82. return True!
  83. else:
  84. // Check permissions
  85. String permission
  86. permission = string_get(read_attribute(core, model_id, "permissions"), get_relation_to_model(user_id, model_id))
  87. if (permission == "2"):
  88. return True!
  89. else:
  90. return False!
  91. Boolean function allow_change_metadata(user_id : String, model_id : String):
  92. if (is_admin(user_id)):
  93. // Is admin, so always allow
  94. return True!
  95. else:
  96. if (get_relation_to_model(user_id, model_id) == 0):
  97. // Only owner can chmod
  98. return True!
  99. else:
  100. return False!
  101. Boolean function allow_group_modify(user_id : String, group_id : String):
  102. if (is_admin(user_id)):
  103. // Is admin, so always allow
  104. return True!
  105. else:
  106. if (read_nr_out(set_overlap(allIncomingAssociationInstances(core, user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))) > 0):
  107. // We are an owner
  108. return True!
  109. else:
  110. return False!
  111. Boolean function check_login(user_id : String):
  112. // TODO
  113. return False!
  114. Element function user_function():
  115. String username
  116. String user_id
  117. output("Log on as which user?")
  118. output("non-existing user will be created")
  119. username = input()
  120. user_id = get_user_id(username)
  121. if (user_id == ""):
  122. // New user
  123. // Add user to Core Formalism
  124. user_id = instantiate_node(core, "User", "")
  125. instantiate_attribute(core, user_id, "name", username)
  126. instantiate_attribute(core, user_id, "admin", False)
  127. // Now call with user created
  128. user_function_skip_init(user_id)
  129. else:
  130. if (check_login(user_id)):
  131. user_function_skip_init(user_id)
  132. // User destroyed already, so just stop execution
  133. return create_node()!
  134. String function get_model_id(name : String):
  135. Element models
  136. String model
  137. models = allInstances(core, "Model")
  138. while (read_nr_out(models) > 0):
  139. model = set_pop(models)
  140. if (value_eq(name, read_attribute(core, model, "name"))):
  141. return model!
  142. return ""!
  143. String function get_user_id(name : String):
  144. Element users
  145. String user
  146. users = allInstances(core, "User")
  147. while (read_nr_out(users) > 0):
  148. user = set_pop(users)
  149. if (value_eq(read_attribute(core, user, "name"), name)):
  150. return user!
  151. return ""!
  152. String function get_group_id(name : String):
  153. Element groups
  154. String group
  155. groups = allInstances(core, "Group")
  156. while (read_nr_out(groups) > 0):
  157. group = set_pop(groups)
  158. if (value_eq(read_attribute(core, group, "name"), name)):
  159. return group!
  160. return ""!
  161. Void function user_function_skip_init(user_id : String):
  162. Boolean do_continue
  163. String cmd
  164. do_continue = True
  165. output("Welcome to the Model Management Interface v2.0!")
  166. output("Use the 'help' command for a list of possible commands")
  167. while (do_continue):
  168. output("Ready for command...")
  169. cmd = input()
  170. if (cmd == "help"):
  171. output("Model operations")
  172. output(" model_add -- Add a new model")
  173. output(" model_modify -- Modify an existing model")
  174. output(" model_delete -- [TODO] Delete a model and all related transformations")
  175. output(" model_list -- List all models")
  176. output(" model_list_full -- List all models with full info")
  177. output("")
  178. output("Transformation-specific operations")
  179. output(" transformation_add_MT_language -- TODO")
  180. output(" transformation_add_MT -- TODO")
  181. output(" transformation_add_AL -- TODO")
  182. output(" transformation_source_add -- TODO")
  183. output(" transformation_source_delete -- TODO")
  184. output(" transformation_target_add -- TODO")
  185. output(" transformation_target_delete -- TODO")
  186. output(" transformation_execute -- TODO")
  187. output("")
  188. output("Model permission operations")
  189. output(" permission_modify -- Change model permissions")
  190. output(" permission_owner -- Change model owner")
  191. output(" permission_group -- Change model group")
  192. output("")
  193. output("Group operations")
  194. output(" group_create -- Create a group")
  195. output(" group_delete -- Delete a group")
  196. output(" group_owner_add -- Add group owner")
  197. output(" group_owner_delete -- Remove group owner")
  198. output(" group_join -- Add someone to your group")
  199. output(" group_kick -- Kick someone from your group")
  200. output(" group_list -- List all groups you are a member of")
  201. output("")
  202. output("Admin operations")
  203. output(" admin_promote -- Promote a user to admin status")
  204. output(" admin_demote -- Demote a user to normal status")
  205. output("")
  206. output("General operations")
  207. output(" account_delete -- Remove current user and revoke all permissions ")
  208. elif (cmd == "model_add"):
  209. // Model addition operation, which uses model upload commands of the compiler
  210. String name
  211. String type
  212. String location
  213. String type_id
  214. Element new_model
  215. String new_model_id
  216. output("Creating new model!")
  217. output("Model type?")
  218. type_id = get_model_id(input())
  219. if (type_id != ""):
  220. // Type exists
  221. if (allow_read(user_id, type_id)):
  222. // And is readable
  223. output("Model name?")
  224. name = input()
  225. if (get_model_id(name) == ""):
  226. // Model doesn't exist yet
  227. output("Waiting for model constructors...")
  228. // TODO Update construct_model call to this interface
  229. // new_model = construct_model(read_attribute(core, type_id, "location"))
  230. output("Model upload success!")
  231. location = "/models/" + cast_id2s(new_model)
  232. export_node(new_model, location)
  233. // Manage meta-info
  234. new_model_id = instantiate_node(core, "Model", "")
  235. instantiate_attribute(core, new_model_id, "name", name)
  236. instantiate_attribute(core, new_model_id, "location", location)
  237. instantiate_attribute(core, new_model_id, "permissions", "200")
  238. instantiate_link(core, "owner", "", new_model_id, user_id)
  239. instantiate_link(core, "instanceOf", "", new_model_id, type_id)
  240. output("Meta-info correctly set!")
  241. else:
  242. output("Model with that name already exists!")
  243. else:
  244. output("You are not allowed to read this type model!")
  245. else:
  246. output("Could not find type model!")
  247. elif (cmd == "model_modify"):
  248. // Model modify operation, which uses the mini_modify.alc operations, though with extensions for access control
  249. String model_id
  250. String type_id
  251. output("Which model do you want to modify?")
  252. model_id = get_model_id(input())
  253. if (model_id != ""):
  254. if (allow_read(user_id, model_id)):
  255. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  256. if (allow_read(user_id, type_id)):
  257. modify(import_node(read_attribute(core, model_id, "location")), allow_write(user_id, model_id))
  258. else:
  259. output("You are not allowed to read the type model!")
  260. else:
  261. output("You are not allowed to read this model!")
  262. else:
  263. output("Could not find model!")
  264. elif (cmd == "model_delete"):
  265. // Delete a model and all of its related transformations
  266. String model_id
  267. output("=================================================")
  268. output("WARNING: Deletion is a very destructive operation")
  269. output(" as it also deletes all transformations ")
  270. output(" defined which make use of this model! ")
  271. output("=================================================")
  272. output("")
  273. output("Currently not supported!")
  274. elif (cmd == "model_list"):
  275. // List all models
  276. Element models
  277. String m
  278. models = allInstances(core, "Model")
  279. while (read_nr_out(models) > 0):
  280. m = set_pop(models)
  281. output(string_join((string_join(" ", read_attribute(core, m, "name")) + " : "), read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")))
  282. elif (cmd == "model_list_full"):
  283. // List all models with full info
  284. Element models
  285. String m
  286. String permissions
  287. String owner
  288. String group
  289. String name
  290. String type
  291. String size
  292. models = allInstances(core, "Model")
  293. while (read_nr_out(models) > 0):
  294. m = set_pop(models)
  295. permissions = read_attribute(core, m, "permissions")
  296. owner = read_attribute(core, set_pop(allAssociationDestinations(core, m, "owner")), "name")
  297. group = read_attribute(core, set_pop(allAssociationDestinations(core, m, "group")), "name")
  298. name = read_attribute(core, m, "name")
  299. size = cast_i2s(read_nr_out(dict_read(import_node(read_attribute(core, m, "location")), "model")))
  300. type = read_attribute(core, set_pop(allAssociationDestinations(core, m, "instanceOf")), "name")
  301. output(((((((((((" " + permissions) + " ") + owner) + " ") + group) + " ") + size) + " ") + name) + " : ") + type)
  302. elif (cmd == "transformation_add_MT_language"):
  303. // Create a model transformation language from a set of input and output formalisms
  304. String name
  305. String model_id
  306. Element source
  307. Element target
  308. Element all_formalisms
  309. Element merged_formalism
  310. String old_type_id
  311. String type_id
  312. String location
  313. String new_model_id
  314. source = create_node()
  315. target = create_node()
  316. old_type_id = ""
  317. output("Source formalisms (terminate with empty string)?")
  318. name = input()
  319. while (name != ""):
  320. model_id = get_model_id(name)
  321. if (model_id != ""):
  322. if (allow_read(user_id, model_id)):
  323. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  324. if (bool_or(old_type_id == "", type_id == old_type_id)):
  325. set_add(source, model_id)
  326. set_add(all_formalisms, create_tuple(name, import_node(read_attribute(core, model_id, "location"))))
  327. old_type_id = type_id
  328. elif (old_type_id != type_id):
  329. // Already have a previous type_id and now another: CLASH
  330. output("Cannot add model as types not compatible with previous models; try again")
  331. else:
  332. output("Model not readable; try again")
  333. name = input()
  334. else:
  335. output("No such model; try again")
  336. output("Target formalisms (terminate with empty string)?")
  337. name = input()
  338. while (name != ""):
  339. model_id = get_model_id(name)
  340. if (model_id != ""):
  341. if (allow_read(user_id, model_id)):
  342. type_id = set_pop(allAssociationDestinations(core, model_id, "instanceOf"))
  343. if (bool_or(old_type_id == "", type_id == old_type_id)):
  344. set_add(target, model_id)
  345. if (bool_not(set_in(source, model_id))):
  346. set_add(all_formalisms, create_tuple(name, import_node(read_attribute(core, model_id, "location"))))
  347. old_type_id = type_id
  348. elif (old_type_id != type_id):
  349. // Already have a previous type_id and now another: CLASH
  350. output("Cannot add model as types not compatible with previous models; try again")
  351. else:
  352. output("Model not readable; try again")
  353. name = input()
  354. else:
  355. output("No such model; try again")
  356. if (read_nr_out(source) > 0):
  357. if (read_nr_out(target) > 0):
  358. output("Name of the new tranformation?")
  359. name = input()
  360. if (get_model_id(name) == ""):
  361. // New location is available, so write
  362. merged_formalism = model_fuse(all_formalisms)
  363. location = "/models/" + cast_id2s(merged_formalism)
  364. export_node(merged_formalism, location)
  365. // Manage meta-info
  366. new_model_id = instantiate_node(core, "Model", "")
  367. instantiate_attribute(core, new_model_id, "name", name)
  368. instantiate_attribute(core, new_model_id, "location", location)
  369. instantiate_attribute(core, new_model_id, "permissions", "200")
  370. instantiate_link(core, "owner", "", new_model_id, user_id)
  371. instantiate_link(core, "instanceOf", "", new_model_id, type_id)
  372. else:
  373. output("Model already exists!")
  374. else:
  375. output("At least one target formalism is required")
  376. else:
  377. output("At least one source formalism is required")
  378. elif (cmd == "permission_modify"):
  379. String permissions
  380. Integer permission
  381. String model_id
  382. output("Which model do you want to change permissions of?")
  383. model_id = get_model_id(input())
  384. if (model_id != ""):
  385. if (get_relation_to_model(user_id, model_id) == 0):
  386. output("New permissions?")
  387. permissions = input()
  388. Boolean fail
  389. Integer i
  390. i = 0
  391. if (string_len(permissions) != 3):
  392. fail = True
  393. while (bool_and(bool_not(fail), i < 3)):
  394. permission = cast_s2i(string_get(permissions, i))
  395. if (bool_or(permission < 0, permission > 2)):
  396. fail = True
  397. if (bool_not(fail)):
  398. unset_attribute(core, model_id, "permissions")
  399. instantiate_attribute(core, model_id, "permissions", permissions)
  400. else:
  401. output("Permissions must be a string of three characters with each character being a digit between 0 and 2")
  402. else:
  403. output("Permission denied!")
  404. else:
  405. output("No such model!")
  406. elif (cmd == "permission_owner"):
  407. String permissions
  408. String model_id
  409. String user_id
  410. output("Which model do you want to change owner of?")
  411. model_id = get_model_id(input())
  412. if (model_id != ""):
  413. if (get_relation_to_model(user_id, model_id) == 0):
  414. output("New owner?")
  415. user_id = get_user_id(input())
  416. if (user_id != ""):
  417. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "owner")))
  418. instantiate_link(core, "owner", "", model_id, user_id)
  419. else:
  420. output("No such user!")
  421. else:
  422. output("Permission denied!")
  423. else:
  424. output("No such model!")
  425. elif (cmd == "permission_group"):
  426. String permissions
  427. String model_id
  428. String group_id
  429. output("Which model do you want to change permissions of?")
  430. model_id = get_model_id(input())
  431. if (model_id != ""):
  432. if (get_relation_to_model(user_id, model_id) == 0):
  433. output("New group?")
  434. group_id = get_group_id(input())
  435. if (group_id != ""):
  436. model_delete_element(core, set_pop(allOutgoingAssociationInstances(core, model_id, "group")))
  437. instantiate_link(core, "group", "", model_id, group_id)
  438. else:
  439. output("No such group!")
  440. else:
  441. output("Permission denied!")
  442. else:
  443. output("No such model!")
  444. elif (cmd == "group_create"):
  445. // Create a new group and become its owner
  446. String group_id
  447. String name
  448. output("Which group do you want to create?")
  449. name = input()
  450. group_id = get_group_id(name)
  451. if (group_id == ""):
  452. group_id = instantiate_node(core, "Group", "")
  453. instantiate_attribute(core, group_id, "name", name)
  454. instantiate_link(core, "belongsTo", "", user_id, group_id)
  455. instantiate_link(core, "owner", "", group_id, user_id)
  456. output("Group created!")
  457. else:
  458. output("Group already exists")
  459. elif (cmd == "group_delete"):
  460. // Delete an existing group
  461. String group_id
  462. String name
  463. output("Which group do you want to delete?")
  464. name = input()
  465. group_id = get_group_id(name)
  466. if (group_id != ""):
  467. if (allow_group_modify(user_id, group_id)):
  468. model_delete_element(core, group_id)
  469. else:
  470. output("Permission denied")
  471. else:
  472. output("No such group")
  473. elif (cmd == "group_owner_add"):
  474. // Add an owner to your group
  475. String group_id
  476. String other_user_id
  477. output("Which group do you want to add an owner to?")
  478. group_id = get_group_id(input())
  479. if (group_id != ""):
  480. if (allow_group_modify(user_id, group_id)):
  481. output("Which user do you want to make an owner?")
  482. other_user_id = get_user_id(input())
  483. if (other_user_id != ""):
  484. Element overlap
  485. overlap = set_overlap(allIncomingAssociationInstances(core, user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  486. if (read_nr_out(overlap) == 0):
  487. instantiate_link(core, "owner", "", group_id, user_id)
  488. overlap = set_overlap(allOutgoingAssociationInstances(core, user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  489. if (read_nr_out(overlap) == 0):
  490. instantiate_link(core, "belongsTo", "", user_id, group_id)
  491. output("New owner added to group!")
  492. else:
  493. output("User is already an owner!")
  494. else:
  495. output("No such user")
  496. else:
  497. output("Permission denied!")
  498. else:
  499. output("No such group")
  500. elif (cmd == "group_owner_delete"):
  501. // Remove an owner from your group
  502. String group_id
  503. String other_user_id
  504. output("Which group do you want to disown someone from?")
  505. group_id = get_group_id(input())
  506. if (group_id != ""):
  507. if (allow_group_modify(user_id, group_id)):
  508. output("Which user do you want to disown?")
  509. other_user_id = get_user_id(input())
  510. if (other_user_id != ""):
  511. Element overlap
  512. overlap = set_overlap(allOutgoingAssociationInstances(core, user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  513. if (read_nr_out(overlap) > 0):
  514. overlap = set_overlap(allIncomingAssociationInstances(core, user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  515. if (read_nr_out(overlap) > 0):
  516. model_delete_element(core, set_pop(overlap))
  517. output("Disowned group from user!")
  518. else:
  519. output("User is not even an owner of the group!")
  520. else:
  521. output("User is not even a member of the group!")
  522. else:
  523. output("No such user")
  524. else:
  525. output("Permission denied!")
  526. else:
  527. output("No such group")
  528. elif (cmd == "group_join"):
  529. // Add someone to your group
  530. String group_id
  531. String other_user_id
  532. output("Which group do you want to add someone to?")
  533. group_id = get_group_id(input())
  534. if (group_id != ""):
  535. if (allow_group_modify(user_id, group_id)):
  536. output("Which user do you want to add?")
  537. other_user_id = get_user_id(input())
  538. if (other_user_id != ""):
  539. Element overlap
  540. overlap = set_overlap(allOutgoingAssociationInstances(core, user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  541. if (read_nr_out(overlap) == 0):
  542. instantiate_link(core, "belongsTo", "", user_id, group_id)
  543. output("User added to the group!")
  544. else:
  545. output("User is already a member of the group!")
  546. else:
  547. output("No such user")
  548. else:
  549. output("Permission denied!")
  550. else:
  551. output("No such group")
  552. elif (cmd == "group_kick"):
  553. // Remove someone from your group
  554. String group_id
  555. String other_user_id
  556. output("Which group do you want to kick someone from?")
  557. group_id = get_group_id(input())
  558. if (group_id != ""):
  559. if (allow_group_modify(user_id, group_id)):
  560. output("Which user do you want to kick?")
  561. other_user_id = get_user_id(input())
  562. if (other_user_id != ""):
  563. Element overlap
  564. overlap = set_overlap(allOutgoingAssociationInstances(core, user_id, "belongsTo"), allIncomingAssociationInstances(core, group_id, "belongsTo"))
  565. if (read_nr_out(overlap) > 0):
  566. model_delete_element(core, set_pop(overlap))
  567. // Check if user was an owner as well
  568. overlap = set_overlap(allIncomingAssociationInstances(core, user_id, "owner"), allOutgoingAssociationInstances(core, group_id, "owner"))
  569. if (read_nr_out(overlap) > 0):
  570. model_delete_element(core, set_pop(overlap))
  571. output("User kicked!")
  572. else:
  573. output("User is not even a member of the group!")
  574. else:
  575. output("No such user")
  576. else:
  577. output("Permission denied!")
  578. else:
  579. output("No such group")
  580. elif (cmd == "group_list"):
  581. // List all groups you are a member of (and whether you are admin or not!)
  582. Element groups
  583. String group_id
  584. String admin
  585. groups = allAssociationDestinations(core, user_id, "belongsTo")
  586. while (True):
  587. group_id = set_pop(groups)
  588. if (set_in(allOutgoingAssociationInstances(core, group_id, "owner"), user_id)):
  589. admin = " A "
  590. else:
  591. admin = " "
  592. output(string_join(admin, read_attribute(core, group_id, "name")))
  593. elif (cmd == "admin_promote"):
  594. // Promote a user to admin status
  595. if (is_admin(user_id)):
  596. String other_user_id
  597. output("Which user do you want to promote?")
  598. other_user_id = get_user_id(input())
  599. if (other_user_id != ""):
  600. unset_attribute(core, other_user_id, "admin")
  601. instantiate_attribute(core, other_user_id, "admin", True)
  602. output("Permissions granted!")
  603. else:
  604. output("No such user!")
  605. else:
  606. output("Permission denied!")
  607. elif (cmd == "admin_demote"):
  608. // Demote a user to normal status
  609. if (is_admin(user_id)):
  610. String other_user_id
  611. output("Which user do you want to demote?")
  612. other_user_id = get_user_id(input())
  613. if (other_user_id != ""):
  614. unset_attribute(core, other_user_id, "admin")
  615. instantiate_attribute(core, other_user_id, "admin", False)
  616. output("Permissions revoked!")
  617. else:
  618. output("No such user!")
  619. else:
  620. output("Permission denied!")
  621. elif (cmd == "exit"):
  622. // Exit by actually removing the user and decoupling it from all of its models
  623. // Restarting with the same user name will NOT grant you access to anything of the previous user with that same name
  624. do_continue = False
  625. // Delete user from Core Formalism
  626. model_delete_element(core, user_id)
  627. output("Goodbye!")
  628. return !