コード例 #1
0
ファイル: serializers.py プロジェクト: laomouzi/taiga-back
class ProjectMemberSerializer(serializers.ModelSerializer):
    id = serializers.IntegerField(source="user.id", read_only=True)
    username = serializers.CharField(source='user.username', read_only=True)
    full_name = serializers.CharField(source='user.full_name', read_only=True)
    full_name_display = serializers.CharField(source='user.get_full_name', read_only=True)
    color = serializers.CharField(source='user.color', read_only=True)
    photo = serializers.SerializerMethodField("get_photo")
    is_active = serializers.BooleanField(source='user.is_active', read_only=True)
    role_name = serializers.CharField(source='role.name', read_only=True, i18n=True)

    class Meta:
        model = models.Membership
        exclude = ("project", "email", "created_at", "token", "invited_by", "invitation_extra_text", "user_order")

    def get_photo(self, membership):
        return get_photo_or_gravatar_url(membership.user)
コード例 #2
0
ファイル: serializers.py プロジェクト: bdang2012/taiga-back
class ProjectMembershipSerializer(serializers.ModelSerializer):
    role_name = serializers.CharField(source='role.name',
                                      required=False,
                                      i18n=True)
    full_name = serializers.CharField(source='user.get_full_name',
                                      required=False)
    username = serializers.CharField(source='user.username', required=False)
    color = serializers.CharField(source='user.color', required=False)
    is_active = serializers.BooleanField(source='user.is_active',
                                         required=False)
    photo = serializers.SerializerMethodField("get_photo")

    class Meta:
        model = models.Membership

    def get_photo(self, project):
        return get_photo_or_gravatar_url(project.user)
コード例 #3
0
class ProjectMemberSerializer(serializers.ModelSerializer):
    id = serializers.IntegerField(source="user.id", read_only=True)
    username = serializers.CharField(source='user.username', read_only=True)
    full_name = serializers.CharField(source='user.full_name', read_only=True)
    full_name_display = serializers.CharField(source='user.get_full_name',
                                              read_only=True)
    color = serializers.CharField(source='user.color', read_only=True)
    photo = serializers.SerializerMethodField("get_photo")
    is_active = serializers.BooleanField(source='user.is_active',
                                         read_only=True)
    role_name = serializers.CharField(source='role.name',
                                      read_only=True,
                                      i18n=True)

    class Meta:
        model = models.Membership

    def get_photo(self, membership):
        return get_photo_or_gravatar_url(membership.user)
コード例 #4
0
class DuplicateProjectValidator(validators.Validator):
    name = serializers.CharField()
    description = serializers.CharField()
    is_private = serializers.BooleanField()
    users = DuplicateProjectMemberValidator(many=True)
コード例 #5
0
class MembershipSerializer(serializers.ModelSerializer):
    role_name = serializers.CharField(source='role.name', required=False, read_only=True, i18n=True)
    full_name = serializers.CharField(source='user.get_full_name', required=False, read_only=True)
    user_email = serializers.EmailField(source='user.email', required=False, read_only=True)
    is_user_active = serializers.BooleanField(source='user.is_active', required=False,
                                              read_only=True)
    email = serializers.EmailField(required=True)
    color = serializers.CharField(source='user.color', required=False, read_only=True)
    photo = serializers.SerializerMethodField("get_photo")
    project_name = serializers.SerializerMethodField("get_project_name")
    project_slug = serializers.SerializerMethodField("get_project_slug")
    invited_by = UserBasicInfoSerializer(read_only=True)
    is_owner = serializers.SerializerMethodField("get_is_owner")

    class Meta:
        model = models.Membership
        # IMPORTANT: Maintain the MembershipAdminSerializer Meta up to date
        # with this info (excluding here user_email and email)
        read_only_fields = ("user",)
        exclude = ("token", "user_email", "email")

    def get_photo(self, project):
        return get_photo_or_gravatar_url(project.user)

    def get_project_name(self, obj):
        return obj.project.name if obj and obj.project else ""

    def get_project_slug(self, obj):
        return obj.project.slug if obj and obj.project else ""

    def get_is_owner(self, obj):
        return (obj and obj.user_id and obj.project_id and obj.project.owner_id and
                obj.user_id == obj.project.owner_id)

    def validate_email(self, attrs, source):
        project = attrs.get("project", None)
        if project is None:
            project = self.object.project

        email = attrs[source]

        qs = models.Membership.objects.all()

        # If self.object is not None, the serializer is in update
        # mode, and for it, it should exclude self.
        if self.object:
            qs = qs.exclude(pk=self.object.pk)

        qs = qs.filter(Q(project_id=project.id, user__email=email) |
                       Q(project_id=project.id, email=email))

        if qs.count() > 0:
            raise serializers.ValidationError(_("Email address is already taken"))

        return attrs

    def validate_role(self, attrs, source):
        project = attrs.get("project", None)
        if project is None:
            project = self.object.project

        role = attrs[source]

        if project.roles.filter(id=role.id).count() == 0:
            raise serializers.ValidationError(_("Invalid role for the project"))

        return attrs

    def validate_is_admin(self, attrs, source):
        project = attrs.get("project", None)
        if project is None:
            project = self.object.project

        if (self.object and self.object.user):
            if self.object.user.id == project.owner_id and attrs[source] != True:
                raise serializers.ValidationError(_("The project owner must be admin."))

            if not services.project_has_valid_admins(project, exclude_user=self.object.user):
                raise serializers.ValidationError(_("At least one user must be an active admin for this project."))

        return attrs
コード例 #6
0
 class _validator(validators.Validator):
     existing = serializers.BooleanField()
コード例 #7
0
ファイル: api.py プロジェクト: bdang2012/taiga-back
 class _serializer(serializers.Serializer):
     existing = serializers.BooleanField()