Example #1
0
    def validate_all_sub_templates(self, original, template):
        if original in template.templates:
            raise errors.not_permitted(
                f'SIPEndpointTemplate({template.uuid}) already include this template'
            )

        for template in template.templates:
            self.validate_all_sub_templates(original, template)
Example #2
0
 def validate_no_users_have_same_line(self, users):
     all_lines = [user.lines[0] for user in users]
     for line in all_lines:
         if all_lines.count(line) > 1:
             raise errors.not_permitted(
                 'Cannot associate different users with the same line',
                 line_id=line.id,
             )
Example #3
0
    def associate(self, user, template):
        if template.private:
            raise errors.not_permitted(
                "Cannot associate a private template with a user",
                template_id=template.id)

        user.func_key_template_id = template.id
        self.user_dao.edit(user)
        self.device_updater.update_for_user(user)
Example #4
0
    def _build_path(self, *fragments):
        fragments = [fragment for fragment in fragments if fragment]

        dangerous_fragments = [
            fragment for fragment in fragments
            if '..' in fragment or '/' in fragment
        ]
        if dangerous_fragments:
            raise errors.not_permitted(
                'Dangerous path fragment: "{}"'.format(dangerous_fragments))

        return os.path.join(self._base_path, *fragments)
Example #5
0
    def attach_line_resources(self, entry, user_line):
        entry.line = self.line_dao.get(user_line.line_id)
        if user_line.extension_id:
            entry.extension = self.extension_dao.get(user_line.extension_id)

        if entry.line.endpoint == "sip":
            entry.sip = self.sip_dao.get(entry.line.endpoint_id)
        elif entry.line.endpoint == "sccp":
            entry.sccp = self.sccp_dao.get(entry.line.endpoint_id)

        line_incalls = self.incall_dao.find_all_line_extensions_by_line_id(user_line.line_id)
        if len(line_incalls) > 1:
            raise errors.not_permitted('Cannot update when user has multiple incalls')
        elif len(line_incalls) == 1:
            entry.incall = self.extension_dao.get(line_incalls[0].extension_id)
Example #6
0
    def get_entry(self, row):
        entry_dict = row.parse()
        entry = Entry(row.position, entry_dict)
        uuid = entry.extract_field('user', 'uuid')
        user = entry.user = self.user_dao.get_by(uuid=uuid)

        # Avoid to GET /users/uuid on wazo-auth
        email = {'address': user.email, 'confirmed': True} if user.email else None
        entry.wazo_user = {
            'uuid': user.uuid,
            'firstname': user.firstname,
            'lastname': user.lastname,
            'username': user.username,
            'emails': [email] if email else [],
        }

        user_call_permissions = self.user_call_permission_dao.find_all_by(
            user_id=user.id
        )
        for user_call_permission in user_call_permissions:
            entry.call_permissions.append(
                self.call_permission_dao.get_by(
                    id=user_call_permission.call_permission_id
                )
            )

        user_voicemail = self.user_voicemail_dao.find_by_user_id(user.id)
        if user_voicemail:
            entry.voicemail = self.voicemail_dao.get(user_voicemail.voicemail_id)

        user_line = self.user_line_dao.find_by(user_id=user.id, main_line=True)
        if user_line:
            self.attach_line_resources(entry, user_line)

        incalls = self.incall_dao.find_all_by(user_id=user.id)
        if len(incalls) > 1:
            raise errors.not_permitted('Cannot update when user has multiple incalls')
        elif len(incalls) == 1:
            entry.extension_incall = self.extension_dao.get_by(
                type='incall', typeval=str(incalls[0].id)
            )
            entry.incall = incalls[0]

        return entry
Example #7
0
    def associate_all_lines(self, user, lines):
        if len(lines) != len(set(lines)):
            raise errors.not_permitted('Cannot associate same line more than once')

        for existing_line in user.lines:
            if existing_line not in lines:
                self.validator.validate_dissociation(user, existing_line)

        for line in lines:
            if line not in user.lines:
                self.validator.validate_association(user, line)

        for existing_line in user.lines:
            if existing_line not in lines:
                user_line = self.find_by(user_id=user.id, line_id=existing_line.id)
                self.notifier.dissociated(user_line)

        user_lines = self.dao.associate_all_lines(user, lines)

        for user_line in user_lines:
            self.notifier.associated(user_line)
Example #8
0
 def validate_no_duplicate_user(self, users):
     if len(users) != len(set(users)):
         raise errors.not_permitted(
             'Cannot associate same user more than once')
Example #9
0
 def validate(self, user, template):
     if template.private:
         raise errors.not_permitted(
             "Cannot associate a private template with a user",
             template_id=template.id,
         )
Example #10
0
 def validate(self, template):
     if template.private:
         raise errors.not_permitted(
             "Deleting private templates is not allowed",
             template_id=template.id)
Example #11
0
 def validate_no_more_than_one_user(self, users):
     if len(users) > 1:
         raise errors.not_permitted(
             'Cannot associate more than one recipient')
Example #12
0
 def validate(self, template):
     if template.private:
         raise errors.not_permitted("Deleting private templates is not allowed",
                                    template_id=template.id)
Example #13
0
 def validate_no_self_context(self, context, contexts):
     if context in contexts:
         raise errors.not_permitted('Cannot include context inside itself')
Example #14
0
 def validate_no_duplicate_context(self, contexts):
     if len(contexts) != len(set(contexts)):
         raise errors.not_permitted(
             'Cannot include same context more than once')
Example #15
0
 def validate_no_duplicate_extension(self, extensions):
     if any(extensions.count(extension) > 1 for extension in extensions):
         raise errors.not_permitted(
             'Cannot associate same extensions more than once')
Example #16
0
 def validate_no_duplicate_trunk(self, trunks):
     if len(trunks) != len(set(trunks)):
         raise errors.not_permitted(
             'Cannot associate same trunk more than once')
Example #17
0
 def validate_no_duplicate_group(self, groups):
     if len(groups) != len(set(groups)):
         raise errors.not_permitted(
             'Cannot associate same group more than once')
Example #18
0
    def validate_not_include_itself(self, template):
        if template in template.templates:
            raise errors.not_permitted('Cannot use itself as template')

        self.validate_all_sub_templates(template, template)