def test_alt_parent_inherit_user(self):
     # Test inheritance of "user" scope definitions
     coll_id = "newcoll"
     newcoll = Collection.create(self.testsite, coll_id, collection_create_values(coll_id))
     user1   = AnnalistUser.create(self.testcoll, "user1", annalistuser_create_values(user_id="user1"))
     user2   = AnnalistUser.create(newcoll,       "user2", annalistuser_create_values(user_id="user2"))
     altparents = newcoll.set_alt_entities(self.testcoll)
     parentids  = [ p.get_id() for p in altparents ]
     self.assertEqual(parentids, ["newcoll", "testcoll", layout.SITEDATA_ID])
     self.assertFalse(AnnalistUser.exists(newcoll, "user1", altscope="user"))
     self.assertTrue(AnnalistUser.exists(newcoll, "_default_user_perms", altscope="user"))   # Access site data
     self.assertTrue(AnnalistUser.exists(newcoll, "user2", altscope="user"))
     testuser = AnnalistUser.load(newcoll, "user2", altscope="user")
     self.assertEquals(testuser["rdfs:label"], "Test User")
     return
Esempio n. 2
0
 def post(self, request):
     if request.POST.get('continue', None):
         # Check if user permissions are defined
         user_id, user_uri = self.get_user_identity()
         site_coll = self.site().site_data_collection()
         user_perms = site_coll.get_user_permissions(user_id, user_uri)
         if not user_perms:
             default_perms = site_coll.get_user_permissions(
                 "_default_user_perms", "annal:User/_default_user_perms")
             new_perms_values = default_perms.get_values()
             new_perms_values.update({
                 "annal:id":
                 None,
                 "rdfs:label":
                 "Permissions for %s" % user_id,
                 "rdfs:comment":
                 "# Permissions for %s\r\n\r\n" % user_id +
                 "Permissions for user %s (copied from default)" % user_id,
                 "annal:user_uri":
                 user_uri
             })
             new_perms = AnnalistUser.create(site_coll, user_id,
                                             new_perms_values)
     continuation_url = request.POST.get("continuation_url", "../")
     return HttpResponseRedirect(continuation_url)
Esempio n. 3
0
 def test_get_local_user_uri_mismatch(self):
     c = self.testcoll
     usr = AnnalistUser.create(c, "user1",
                               annalistuser_create_values(user_id="user1"))
     ugp = c.get_user_permissions("user1", "mailto:[email protected]")
     self.assertIsNone(ugp)
     return
Esempio n. 4
0
 def post(self, request):
     if request.POST.get('continue', None):
         # Check if user permissions are defined
         user_id, user_uri = self.get_user_identity()
         site_coll = self.site().site_data_collection()
         user_perms = site_coll.get_user_permissions(user_id, user_uri)
         if not user_perms:
             # Initialize new user permissions from system defaults
             # (NOTE: site-specific default permissions are incorporate dynamically)
             default_perms = site_coll.get_user_permissions(
                 default_user_id, default_user_uri)
             new_perms_values = default_perms.get_values()
             new_perms_values.update({
                 "annal:id":
                 None,
                 "rdfs:label":
                 "Permissions for %s" % user_id,
                 "rdfs:comment":
                 "# Permissions for %s\r\n\r\n" % user_id +
                 "Permissions for user %s (copied from default)" % user_id,
                 "annal:user_uri":
                 user_uri
             })
             new_perms = AnnalistUser.create(site_coll, user_id,
                                             new_perms_values)
     continuation_url = request.POST.get("continuation_url", "../")
     return HttpResponseRedirect(continuation_url)
Esempio n. 5
0
 def test_annalistuser_create_load(self):
     usr = AnnalistUser.create(self.testcoll, "user1",
                               annalistuser_create_values(user_id="user1"))
     uld = AnnalistUser.load(self.testcoll, "user1").get_values()
     ued = annalistuser_read_values(user_id="user1")
     self.assertKeysMatch(uld, ued)
     self.assertDictionaryMatch(uld, ued)
     return
 def test_get_local_user_missing_fields(self):
     # E.g. what happens if user record is created through default view?  Don't return value.
     d = annalistuser_create_values(user_id="user1")
     d.pop(ANNAL.CURIE.user_permission)
     usr = AnnalistUser.create(self.testcoll, "user1", d)
     ugp = self.testcoll.get_user_permissions("user1", "mailto:[email protected]")
     self.assertIsNone(ugp)
     return
Esempio n. 7
0
 def test_get_user_uri_mismatch(self):
     s = self.testsite
     c = s.site_data_collection()
     # Create local permissions
     usr = AnnalistUser.create(c, "user1", annalistuser_create_values(user_id="user1"))
     # Test access to permissions defined locally in collection
     ugp = s.get_user_permissions("user1", "mailto:[email protected]")
     self.assertIsNone(ugp)
     return
Esempio n. 8
0
 def test_annalistuser_create_load(self):
     usr = AnnalistUser.create(
         self.testcoll, "user1", annalistuser_create_values(user_id="user1")
         )
     uld = AnnalistUser.load(self.testcoll, "user1").get_values()
     ued = annalistuser_read_values(user_id="user1")
     self.assertKeysMatch(ued, uld)
     self.assertDictionaryMatch(ued, uld)
     return
Esempio n. 9
0
 def test_get_user_uri_mismatch(self):
     s = self.testsite
     c = s.site_data_collection()
     # Create local permissions
     usr = AnnalistUser.create(c, "user1", annalistuser_create_values(user_id="user1"))
     # Test access to permissions defined locally in collection
     ugp = s.get_user_permissions("user1", "mailto:[email protected]")
     self.assertIsNone(ugp)
     return
Esempio n. 10
0
def create_user_permissions(site, user_id, user_uri, user_name, user_comment, user_permissions):
    user_values = (
        { ANNAL.CURIE.type:             ANNAL.CURIE.User
        , RDFS.CURIE.label:             user_name
        , RDFS.CURIE.comment:           user_comment
        , ANNAL.CURIE.user_uri:         "%s"%(user_uri)
        , ANNAL.CURIE.user_permissions: user_permissions
        })
    user = AnnalistUser.create(site.site_data_collection(), user_id, user_values)
    return user
Esempio n. 11
0
def create_user_permissions(site, user_id, user_uri, user_name, user_comment, user_permissions):
    user_values = (
        { ANNAL.CURIE.type:             ANNAL.CURIE.User
        , RDFS.CURIE.label:             user_name
        , RDFS.CURIE.comment:           user_comment
        , ANNAL.CURIE.user_uri:         "%s"%(user_uri)
        , ANNAL.CURIE.user_permissions: user_permissions
        })
    user = AnnalistUser.create(site, user_id, user_values, use_altpath=True)
    return user
Esempio n. 12
0
 def test_get_local_user_permissions(self):
     # Create local permissions
     usr = AnnalistUser.create(self.testcoll, "user1", annalistuser_create_values(user_id="user1"))
     # Test access to permissions defined locally in collection
     ugp = self.testcoll.get_user_permissions("user1", "mailto:[email protected]")
     self.assertEqual(ugp[ANNAL.CURIE.id],                 "user1")
     self.assertEqual(ugp[ANNAL.CURIE.type_id],            "_user")
     self.assertEqual(ugp[RDFS.CURIE.label],               "Test User")
     self.assertEqual(ugp[RDFS.CURIE.comment],             "User user1: permissions for Test User in collection testcoll")
     self.assertEqual(ugp[ANNAL.CURIE.user_uri],           "mailto:[email protected]")
     self.assertEqual(ugp[ANNAL.CURIE.user_permission],    ["VIEW", "CREATE", "UPDATE", "DELETE", "CONFIG", "ADMIN"])
     return
Esempio n. 13
0
def create_user_permissions(site, user_id, user_uri, user_name, user_comment,
                            user_permissions):
    user_values = ({
        ANNAL.CURIE.type: ANNAL.CURIE.User,
        RDFS.CURIE.label: user_name,
        RDFS.CURIE.comment: user_comment,
        ANNAL.CURIE.user_uri: "%s" % (user_uri),
        ANNAL.CURIE.user_permissions: user_permissions
    })
    user = AnnalistUser.create(site.site_data_collection(), user_id,
                               user_values)
    return user
Esempio n. 14
0
 def create_user_permissions(self, user_id, user_uri,
         user_name, user_description,
         user_permissions=["VIEW"]
         ):
     user_values = (
         { ANNAL.CURIE.type:             ANNAL.CURIE.User
         , RDFS.CURIE.label:             user_name
         , RDFS.CURIE.comment:           user_description
         , ANNAL.CURIE.user_uri:         user_uri
         , ANNAL.CURIE.user_permission:  user_permissions
         })
     user = AnnalistUser.create(self, user_id, user_values)
     return user
Esempio n. 15
0
 def create_user_permissions(self, user_id, user_uri,
         user_name, user_description,
         user_permissions=["VIEW"]
         ):
     user_values = (
         { ANNAL.CURIE.type:             ANNAL.CURIE.User
         , RDFS.CURIE.label:             user_name
         , RDFS.CURIE.comment:           user_description
         , ANNAL.CURIE.user_uri:         user_uri
         , ANNAL.CURIE.user_permission:  user_permissions
         })
     user = AnnalistUser.create(self, user_id, user_values)
     return user
Esempio n. 16
0
 def no_test_post_confirmed_remove_user(self):
     t = AnnalistUser.create(self.testcoll, "deleteuser",
                             annalistuser_create_values("deleteuser"))
     self.assertTrue(AnnalistUser.exists(self.testcoll, "deleteuser"))
     # Submit positive confirmation
     u = TestHostUri + annalistuser_edit_url("delete", "testcoll")
     f = annalistuser_delete_confirm_form_data("deleteuser")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     self.assertMatch(
         r['location'],
         "^" + TestHostUri + collection_edit_url("testcoll") +
         r"\?info_head=.*&info_message=.*deletetype.*testcoll.*$")
     # Confirm deletion
     self.assertFalse(AnnalistUser.exists(self.testcoll, "deletetype"))
     return
Esempio n. 17
0
 def no_test_post_confirmed_remove_user(self):
     t = AnnalistUser.create(self.testcoll, "deleteuser", annalistuser_create_values("deleteuser"))
     self.assertTrue(AnnalistUser.exists(self.testcoll, "deleteuser"))
     # Submit positive confirmation
     u = TestHostUri + annalistuser_edit_url("delete", "testcoll")
     f = annalistuser_delete_confirm_form_data("deleteuser")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,     302)
     self.assertEqual(r.reason_phrase,   "FOUND")
     self.assertEqual(r.content,         "")
     self.assertMatch(r['location'],    
         "^"+TestHostUri+
         collection_edit_url("testcoll")+
         r"\?info_head=.*&info_message=.*deletetype.*testcoll.*$"
         )
     # Confirm deletion
     self.assertFalse(AnnalistUser.exists(self.testcoll, "deletetype"))
     return
Esempio n. 18
0
def create_user_permissions(
        parent,
        user_id,
        user_permissions=["VIEW", "CREATE", "UPDATE", "DELETE", "CONFIG"]):
    user_values = ({
        'annal:type':
        "annal:User",
        'rdfs:label':
        "Test User",
        'rdfs:comment':
        "User %s: permissions for %s in collection %s" %
        (user_id, "Test User", parent.get_id()),
        'annal:user_uri':
        "mailto:%s@%s" % (user_id, TestHost),
        'annal:user_permission':
        user_permissions
    })
    user = AnnalistUser.create(parent, user_id, user_values)
    return user
Esempio n. 19
0
 def post(self, request):
     if request.POST.get('continue', None):
         # Check if user permissions are defined
         user_id, user_uri = self.get_user_identity()
         site_coll  = self.site().site_data_collection()
         user_perms = site_coll.get_user_permissions(user_id, user_uri)
         if not user_perms:
             default_perms = site_coll.get_user_permissions(
                 "_default_user_perms", "annal:User/_default_user_perms"
                 )
             new_perms_values = default_perms.get_values()
             new_perms_values.update(
                 { "annal:id":               None
                 , "rdfs:label":             "Permissions for %s"%user_id
                 , "rdfs:comment":           "# Permissions for %s\r\n\r\n"%user_id+
                                             "Permissions for user %s (copied from default)"%user_id
                 , "annal:user_uri":         user_uri
                 })
             new_perms = AnnalistUser.create(site_coll, user_id, new_perms_values)
     continuation_url  = request.POST.get("continuation_url", "../")
     return HttpResponseRedirect(continuation_url)
Esempio n. 20
0
 def post(self, request):
     if request.POST.get('continue', None):
         # Check if user permissions are defined
         user_id, user_uri = self.get_user_identity()
         site_coll  = self.site().site_data_collection()
         user_perms = site_coll.get_user_permissions(user_id, user_uri)
         if not user_perms:
             # Initialize new user permissions from system defaults
             # (NOTE: site-specific default permissions are incorporate dynamically)
             default_perms = site_coll.get_user_permissions(
                 default_user_id, default_user_uri
                 )
             new_perms_values = default_perms.get_values()
             new_perms_values.update(
                 { "annal:id":               None
                 , "rdfs:label":             "Permissions for %s"%user_id
                 , "rdfs:comment":           "# Permissions for %s\r\n\r\n"%user_id+
                                             "Permissions for user %s (copied from default)"%user_id
                 , "annal:user_uri":         user_uri
                 })
             new_perms = AnnalistUser.create(site_coll, user_id, new_perms_values)
     continuation_url  = request.POST.get("continuation_url", "../")
     return HttpResponseRedirect(continuation_url)
Esempio n. 21
0
 def test_get_local_user_uri_mismatch(self):
     usr = AnnalistUser.create(self.testcoll, "user1", annalistuser_create_values(user_id="user1"))
     ugp = self.testcoll.get_user_permissions("user1", "mailto:[email protected]")
     self.assertIsNone(ugp)
     return
Esempio n. 22
0
 def setUp(self):
     init_annalist_test_site()
     self.testsite = Site(TestBaseUri, TestBaseDir)
     self.testcoll = Collection(self.testsite, "testcoll")
     # populate site with different classes of users: admin, config, create, update, delete, view
     self.user_admin = AnnalistUser.create(
         self.testcoll, "user_admin",
         annalistuser_create_values(
             coll_id="testcoll",
             user_id="user_admin",
             user_name="Admin User",
             user_uri="mailto:user_admin@%s" % TestHost,
             user_permissions=[
                 "VIEW", "CREATE", "UPDATE", "DELETE", "CONFIG", "ADMIN"
             ]))
     self.user_config = AnnalistUser.create(
         self.testcoll, "user_config",
         annalistuser_create_values(
             coll_id="testcoll",
             user_id="user_config",
             user_name="Admin User",
             user_uri="mailto:user_config@%s" % TestHost,
             user_permissions=[
                 "VIEW", "CREATE", "UPDATE", "DELETE", "CONFIG"
             ]))
     self.user_create = AnnalistUser.create(
         self.testcoll, "user_create",
         annalistuser_create_values(
             coll_id="testcoll",
             user_id="user_create",
             user_name="Admin User",
             user_uri="mailto:user_create@%s" % TestHost,
             user_permissions=["VIEW", "UPDATE", "CREATE"]))
     self.user_update = AnnalistUser.create(
         self.testcoll, "user_update",
         annalistuser_create_values(coll_id="testcoll",
                                    user_id="user_update",
                                    user_name="Admin User",
                                    user_uri="mailto:user_update@%s" %
                                    TestHost,
                                    user_permissions=["VIEW", "UPDATE"]))
     self.user_delete = AnnalistUser.create(
         self.testcoll, "user_delete",
         annalistuser_create_values(
             coll_id="testcoll",
             user_id="user_delete",
             user_name="Admin User",
             user_uri="mailto:user_delete@%s" % TestHost,
             user_permissions=["VIEW", "UPDATE", "DELETE"]))
     self.user_view = AnnalistUser.create(
         self.testcoll, "user_view",
         annalistuser_create_values(coll_id="testcoll",
                                    user_id="user_view",
                                    user_name="Admin User",
                                    user_uri="mailto:user_view@%s" %
                                    TestHost,
                                    user_permissions=["VIEW"]))
     self.user_site_admin = AnnalistUser.create(
         self.testsite,
         "user_site_admin",
         annalistuser_create_values(
             coll_id="testcoll",
             user_id="user_site_admin",
             user_name="Site_admin User",
             user_uri="mailto:user_site_admin@%s" % TestHost,
             user_permissions=[
                 "VIEW", "CREATE", "UPDATE", "DELETE", "CONFIG", "ADMIN"
             ]),
         use_altpath=True)
     self.user_site_create_coll = AnnalistUser.create(
         self.testsite,
         "user_site_create_coll",
         annalistuser_create_values(
             coll_id="testcoll",
             user_id="user_site_create_coll",
             user_name="Site_create User",
             user_uri="mailto:user_site_create_coll@%s" % TestHost,
             user_permissions=["VIEW", "CREATE_COLLECTION"]),
         use_altpath=True)
     self.user_site_delete_coll = AnnalistUser.create(
         self.testsite,
         "user_site_delete_coll",
         annalistuser_create_values(
             coll_id="testcoll",
             user_id="user_site_delete_coll_coll",
             user_name="Site_delete User",
             user_uri="mailto:user_site_delete_coll@%s" % TestHost,
             user_permissions=[
                 "VIEW", "CREATE_COLLECTION", "DELETE_COLLECTION"
             ]),
         use_altpath=True)
     self.user_site_view = AnnalistUser.create(
         self.testsite,
         "user_site_view",
         annalistuser_create_values(coll_id="testcoll",
                                    user_id="user_site_view",
                                    user_name="Site_view User",
                                    user_uri="mailto:user_site_view@%s" %
                                    TestHost,
                                    user_permissions=["VIEW"]),
         use_altpath=True)
     return