|
25 | 25 | :jane "http://mu.semte.ch/sessions/janeuuid" |
26 | 26 | :joll "http://mu.semte.ch/sessions/adminuuid")) |
27 | 27 |
|
| 28 | +;;;; Our services are :admin (read and write public-data), and :catalog (read public) |
| 29 | +(defparameter *known-service-scopes* |
| 30 | + (list |
| 31 | + :admin "http://services.semantic.works/admin-service" |
| 32 | + :catalog "http://services.semantic.works/catalog-service")) |
| 33 | + |
28 | 34 | (defun clean-up-graphs () |
29 | 35 | (client:query (coerce |
30 | 36 | "DELETE { |
|
175 | 181 | :to acl::push-updates |
176 | 182 | :for "public") |
177 | 183 |
|
| 184 | + (acl:grant (acl::read acl::write) |
| 185 | + :to-graph acl::public-data |
| 186 | + :for-allowed-group "public" |
| 187 | + :scopes '("http://services.semantic.works/admin-service")) |
| 188 | + |
| 189 | + (acl:grant (acl::read) |
| 190 | + :to-graph acl::public-data |
| 191 | + :for-allowed-group "public" |
| 192 | + :scopes '("http://services.semantic.works/catalog-service")) |
178 | 193 | ,@body)) |
179 | 194 |
|
180 | 195 | ;; TODO: Copied and modified from `with-acl-config', could probably reduce the code duplication |
|
222 | 237 | (:mu-session-id (getf *known-session-ids* ,user)) |
223 | 238 | ,@body)) |
224 | 239 |
|
| 240 | +(defmacro with-scope-for (service &body body) |
| 241 | + "Impersonates SERVICE by setting its scope." |
| 242 | + `(server::with-call-context |
| 243 | + (:mu-call-scope (getf *known-service-scopes* ,service)) |
| 244 | + ,@body)) |
| 245 | + |
225 | 246 | (defun store-initial-session-data () |
226 | 247 | "Stores the initial session data in the triplestore." |
227 | 248 | (client:query (coerce |
@@ -380,7 +401,7 @@ this point and likely a redpencil image too.") |
380 | 401 |
|
381 | 402 | ASK { |
382 | 403 | favorites:me ext:hasFavoriteAuthor ?author. |
383 | | - }") |
| 404 | + }") |
384 | 405 | ;; then let's describe the values |
385 | 406 | (format t "~&Jack can describe favorite authors.~%") |
386 | 407 | (server:execute-query-for-context |
@@ -604,7 +625,114 @@ this point and likely a redpencil image too.") |
604 | 625 | ext:myDisplay a ext:NoNameOrLabel; |
605 | 626 | ext:score ?score; |
606 | 627 | ext:level ?level. |
607 | | - }"))) |
| 628 | + }")) |
| 629 | + |
| 630 | + (format t "~&Admin service can read and write~%") |
| 631 | + (with-scope-for :admin |
| 632 | + (format t "~&Can add authors.~%") |
| 633 | + (server:execute-query-for-context |
| 634 | + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
| 635 | + PREFIX schema: <http://schema.org/> |
| 636 | + PREFIX authors: <http://example.com/authors/> |
| 637 | +
|
| 638 | + INSERT DATA { |
| 639 | + authors:david-graeber a foaf:Person; |
| 640 | + foaf:name \"David Graeber\". |
| 641 | + }") |
| 642 | + |
| 643 | + (format t "~&Can add a book for an author.~%") |
| 644 | + (server:execute-query-for-context |
| 645 | + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
| 646 | + PREFIX schema: <http://schema.org/> |
| 647 | + PREFIX authors: <http://example.com/authors/> |
| 648 | + PREFIX books: <http://example.com/books/> |
| 649 | +
|
| 650 | + INSERT DATA { |
| 651 | + books:dawn a schema:Book; |
| 652 | + schema:name \"The Dawn of Everything\"; |
| 653 | + schema:creator authors:david-graeber . |
| 654 | + }") |
| 655 | + |
| 656 | + (format t "~&Can add extra author to book.~%") |
| 657 | + (server:execute-query-for-context |
| 658 | + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
| 659 | + PREFIX schema: <http://schema.org/> |
| 660 | + PREFIX authors: <http://example.com/authors/> |
| 661 | + PREFIX books: <http://example.com/books/> |
| 662 | +
|
| 663 | + INSERT DATA { |
| 664 | + authors:david-wengrow a foaf:Person ; |
| 665 | + schema:name \"David Wengrow\" . |
| 666 | + books:dawn schema:creator authors:david-wengrow . |
| 667 | + }") |
| 668 | + |
| 669 | + (format t "~&Cannot add a favorite.~%") |
| 670 | + (handler-case |
| 671 | + (progn |
| 672 | + (server:execute-query-for-context |
| 673 | + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
| 674 | + PREFIX schema: <http://schema.org/> |
| 675 | + PREFIX authors: <http://example.com/authors/> |
| 676 | + PREFIX books: <http://example.com/books/> |
| 677 | + PREFIX favorites: <http://mu.semte.ch/favorites/> |
| 678 | + PREFIX ext: <http://mu.semte.ch/vocabularies/ext/> |
| 679 | +
|
| 680 | + INSERT DATA { |
| 681 | + favorites:me ext:hasBook books:gtd, books:fastAndSlow. |
| 682 | + }") |
| 683 | + (format t "~&ERROR: Oh noes, Admin service should not be able to add a favorite author!~%")) |
| 684 | + (error (e) (declare (ignore e)) t))) |
| 685 | + |
| 686 | + (format t "~&Catalog service can only read~%") |
| 687 | + (with-scope-for :catalog |
| 688 | + (format t "~&Cannot add authors.") |
| 689 | + (handler-case |
| 690 | + (progn |
| 691 | + (server:execute-query-for-context |
| 692 | + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
| 693 | + PREFIX schema: <http://schema.org/> |
| 694 | + PREFIX authors: <http://example.com/authors/> |
| 695 | +
|
| 696 | + INSERT DATA { |
| 697 | + authors:david-graeber a foaf:Person; |
| 698 | + foaf:name \"David Graeber\". |
| 699 | + }") |
| 700 | + (format t "~&ERROR: Oh noes, Catalog service should not be able to add an author!~%")) |
| 701 | + (error (e) (declare (ignore e)) t)) |
| 702 | + |
| 703 | + (format t "~&Cannot add book.~%") |
| 704 | + (handler-case |
| 705 | + (progn |
| 706 | + (server:execute-query-for-context |
| 707 | + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
| 708 | + PREFIX schema: <http://schema.org/> |
| 709 | + PREFIX authors: <http://example.com/authors/> |
| 710 | + PREFIX books: <http://example.com/books/> |
| 711 | +
|
| 712 | + INSERT DATA { |
| 713 | + books:dawn a schema:Book; |
| 714 | + schema:name \"The Dawn of Everything\"; |
| 715 | + schema:creator authors:david-graeber . |
| 716 | + }") |
| 717 | + (format t "~&ERROR: Oh noes, Catalog service should not be able to add a book!~%")) |
| 718 | + (error (e) (declare (ignore e)) t)) |
| 719 | + |
| 720 | + (format t "~&Cannot add a favorite.~%") |
| 721 | + (handler-case |
| 722 | + (progn |
| 723 | + (server:execute-query-for-context |
| 724 | + "PREFIX foaf: <http://xmlns.com/foaf/0.1/> |
| 725 | + PREFIX schema: <http://schema.org/> |
| 726 | + PREFIX authors: <http://example.com/authors/> |
| 727 | + PREFIX books: <http://example.com/books/> |
| 728 | + PREFIX favorites: <http://mu.semte.ch/favorites/> |
| 729 | + PREFIX ext: <http://mu.semte.ch/vocabularies/ext/> |
| 730 | +
|
| 731 | + INSERT DATA { |
| 732 | + favorites:me ext:hasBook books:gtd, books:fastAndSlow. |
| 733 | + }") |
| 734 | + (format t "~&ERROR: Oh noes, Catalog service should not be able to add a favorite author!~%")) |
| 735 | + (error (e) (declare (ignore e)) t)))) |
608 | 736 |
|
609 | 737 | (defun delta-only-assertion-tests () |
610 | 738 | (client:query (coerce |
|
0 commit comments