Пример #1
0
 def save(self, with_history=True):
     u"""
     Saves :attr:`object` and records its history in the database.
     If *with_history* is False, the history is not recorded.
     """
     super(GroupController, self).save(with_history)
     update_index.delay("plmapp", "groupinfo", self.object.pk)
Пример #2
0
 def sponsor(self, new_user, is_contributor=True):
     self.check_contributor()
     email = new_user.email
     try:
         # checks *email*
         if settings.RESTRICT_EMAIL_TO_DOMAINS:
             # i don't know if a domain can contains a '@'
             domain = email.rsplit("@", 1)[1]
             if domain not in Site.objects.values_list("domain", flat=True):
                 raise PermissionError("Email's domain not valid") 
     except AttributeError:
         # restriction disabled if the setting is not set
         pass
     password = generate_password()
     new_user.set_password(password)
     new_user.save()
     new_user.get_profile().is_contributor = is_contributor
     new_user.get_profile().save()
     link = models.DelegationLink(delegator=self._user, delegatee=new_user,
             role=models.ROLE_SPONSOR)
     link.save()
     ctx = {
             "new_user" : new_user,
             "sponsor" : self._user,
             "password" : password,
            }
     update_index.delay("auth", "user", new_user.pk)
     self._send_mail(send_mail, "New account on openPLM", [new_user],
             ctx, "mails/new_account") 
     models.UserHistory.objects.create(action="Create", user=self._user,
             plmobject=self._user, details="New user: %s" % new_user.username)
     models.UserHistory.objects.create(action="Create", user=self._user,
             plmobject=new_user, details="Account created")
Пример #3
0
    def create(cls, name, description, user, data={}):
        profile = user.profile
        if not (profile.is_contributor or profile.is_administrator):
            raise PermissionError("%s is not a contributor" % user)
        if profile.restricted:
            raise PermissionError("Restricted account can not create a group.")
        if not user.is_active:
            raise PermissionError(u"%s's account is inactive" % user)
        if not name:
            raise ValueError("name must not be empty")
        try:
            validate_reference(name)
        except:
            raise ValueError("Name contains a '/' or a '..'")

        obj = models.GroupInfo(name=name, description=description)
        obj.creator = user
        obj.owner = user
        if data:
            for key, value in data.iteritems():
                if key not in ["name", "description"]:
                    setattr(obj, key, value)
        obj.save()
        infos = {"name" : name, "description" : description}
        infos.update(data)
        details = ",".join("%s : %s" % (k, v) for k, v in infos.items())
        res = cls(obj, user)
        user.groups.add(obj)
        res._save_histo("Create", details)
        update_index.delay("plmapp", "groupinfo", obj.pk)
        return res
Пример #4
0
 def save(self, with_history=True):
     u"""
     Saves :attr:`object` and records its history in the database.
     If *with_history* is False, the history is not recorded.
     """
     self.object.get_profile().save()
     super(UserController, self).save(with_history)
     update_index.delay("auth", "user", self.object.pk)
Пример #5
0
 def save(self, with_history=True):
     u"""
     Saves :attr:`object` and records its history in the database.
     If *with_history* is False, the history is not recorded.
     """
     self.object.profile.save()
     super(UserController, self).save(with_history)
     update_index.delay("auth", "user", self.object.pk)
Пример #6
0
 def sponsor(self, new_user, is_contributor=True, restricted=False):
     self.check_contributor()
     if is_contributor and restricted:
         raise ValueError(
             "An restricted account can not be a contributor account")
     email = new_user.email
     try:
         # checks *email*
         if settings.RESTRICT_EMAIL_TO_DOMAINS:
             # i don't know if a domain can contains a '@'
             domain = email.rsplit("@", 1)[1]
             if domain not in Site.objects.values_list("domain", flat=True):
                 raise PermissionError("Email's domain not valid")
     except AttributeError:
         # restriction disabled if the setting is not set
         pass
     password = generate_password()
     new_user.set_password(password)
     new_user.save()
     new_user.profile.is_contributor = is_contributor
     new_user.profile.restricted = restricted
     new_user.profile.save()
     link = models.DelegationLink(delegator=self._user,
                                  delegatee=new_user,
                                  role=models.ROLE_SPONSOR)
     link.save()
     ctx = {
         "new_user": new_user,
         "sponsor": self._user,
         "password": password,
     }
     update_index.delay("auth", "user", new_user.pk)
     self._send_mail(send_mail, self.get_sponsor_subject(new_user),
                     [new_user], ctx, "mails/new_account")
     models.UserHistory.objects.create(action="Create",
                                       user=self._user,
                                       plmobject=self._user,
                                       details="New user: %s" %
                                       new_user.username)
     models.UserHistory.objects.create(action="Create",
                                       user=self._user,
                                       plmobject=new_user,
                                       details="Account created")
Пример #7
0
    def create(cls, name, description, user, data={}):
        if not name:
            raise ValueError("name must not be empty")
        if rx_bad_ref.search(name):
            raise ValueError("Name contains a '/' or a '..'")

        obj = models.GroupInfo(name=name, description=description)
        obj.creator = user
        obj.owner = user
        if data:
            for key, value in data.iteritems():
                if key not in ["name", "description"]:
                    setattr(obj, key, value)
        obj.save()
        infos = {"name" : name, "description" : description}
        infos.update(data)
        details = ",".join("%s : %s" % (k, v) for k, v in infos.items())
        res = cls(obj, user)
        user.groups.add(obj)
        res._save_histo("Create", details)
        update_index.delay("plmapp", "groupinfo", obj.pk)
        return res
Пример #8
0
 def enqueue_save(self, instance, **kwargs):
     if not getattr(instance, "no_index", False):
         update_index.delay(instance._meta.app_label,
                            instance._meta.module_name,
                            instance._get_pk_val())
Пример #9
0
 def enqueue_save(self, instance, **kwargs):
     if not getattr(instance, "no_index", False):
         update_index.delay(instance._meta.app_label,
                 instance._meta.module_name, instance._get_pk_val())