Beispiel #1
0
 def createAddGroupIfNotExists(self, user_dn, user_name, gid_number):
     if user_dn is None or user_name is None or gid_number is None:
         return
     index = PluginRegistry.getInstance("ObjectIndex")
     res = index.search({
         "_type": "PosixGroup",
         "gidNumber": gid_number
     }, {"dn": 1})
     if len(res) == 0:
         # create group
         user = ObjectProxy(user_dn)
         group = ObjectProxy(user.get_adjusted_parent_dn(), "PosixGroup")
         group.cn = user_name
         group.description = N_("Group of user %s" % user_name)
         group.autoGid = False
         group.gidNumber = gid_number
         group.memberUid = [user_name]
         group.commit()
     elif len(res) == 1:
         group = ObjectProxy(res[0]["dn"])
         if user_name not in group.memberUid:
             group.memberUid.append(user_name)
             group.commit()
     else:
         raise GosaException(
             C.make_error('GROUP_ID_IS_AMBIGUOUS', gid=gid_number))
Beispiel #2
0
    def create_test_data():
        """
        Insert new data just for testing purposes
        """
        index = PluginRegistry.getInstance("ObjectIndex")
        res = index.search({"dn": "dc=test,dc=example,dc=net"}, {"dn": 1})
        if len(res) > 0:
            new_domain = ObjectProxy("dc=test,dc=example,dc=net")
            new_domain.remove(True)

        new_domain = ObjectProxy("dc=example,dc=net", "DomainComponent")
        new_domain.dc = "test"
        new_domain.description = "Domain for testing purposes"
        new_domain.commit()
        return "dc=test,dc=example,dc=net"
Beispiel #3
0
    def create_test_data():
        """
        Insert new data just for testing purposes
        """
        index = PluginRegistry.getInstance("ObjectIndex")
        res = index.search({"dn": "dc=test,dc=example,dc=net"}, {"dn": 1})
        if len(res) > 0:
            new_domain = ObjectProxy("dc=test,dc=example,dc=net")
            new_domain.remove(True)
            new_domain.commit()

        new_domain = ObjectProxy("dc=example,dc=net", "DomainComponent")
        new_domain.dc = "test"
        new_domain.description = "Domain for testing purposes"
        new_domain.commit()
        return "dc=test,dc=example,dc=net"
Beispiel #4
0
 def createAddGroupIfNotExists(self, user_dn, user_name, gid_number):
     if user_dn is None or user_name is None or gid_number is None:
         return
     index = PluginRegistry.getInstance("ObjectIndex")
     res = index.search({"_type": "PosixGroup", "gidNumber": gid_number}, {"dn": 1})
     if len(res) == 0:
         # create group
         user = ObjectProxy(user_dn)
         group = ObjectProxy(user.get_adjusted_parent_dn(), "PosixGroup")
         group.cn = user_name
         group.description = N_("Group of user %s" % user_name)
         group.autoGid = False
         group.gidNumber = gid_number
         group.memberUid = [user_name]
         group.commit()
     elif len(res) == 1:
         group = ObjectProxy(res[0]["dn"])
         if user_name not in group.memberUid:
             group.memberUid.append(user_name)
             group.commit()
     else:
         raise GosaException(C.make_error('GROUP_ID_IS_AMBIGUOUS', gid=gid_number))