Exemplo n.º 1
0
class ProjectExportSerializer(serializers.ModelSerializer):
    owner = UserRelatedField(required=False)
    default_points = serializers.SlugRelatedField(slug_field="name", required=False)
    default_us_status = serializers.SlugRelatedField(slug_field="name", required=False)
    default_task_status = serializers.SlugRelatedField(slug_field="name", required=False)
    default_priority = serializers.SlugRelatedField(slug_field="name", required=False)
    default_severity = serializers.SlugRelatedField(slug_field="name", required=False)
    default_issue_status = serializers.SlugRelatedField(slug_field="name", required=False)
    default_issue_type = serializers.SlugRelatedField(slug_field="name", required=False)
    memberships = MembershipExportSerializer(many=True, required=False)
    points = PointsExportSerializer(many=True, required=False)
    us_statuses = UserStoryStatusExportSerializer(many=True, required=False)
    task_statuses = TaskStatusExportSerializer(many=True, required=False)
    issue_statuses = IssueStatusExportSerializer(many=True, required=False)
    priorities = PriorityExportSerializer(many=True, required=False)
    severities = SeverityExportSerializer(many=True, required=False)
    issue_types = IssueTypeExportSerializer(many=True, required=False)
    roles = RoleExportSerializer(many=True, required=False)
    milestones = MilestoneExportSerializer(many=True, required=False)
    wiki_pages = WikiPageExportSerializer(many=True, required=False)
    wiki_links = WikiLinkExportSerializer(many=True, required=False)
    user_stories = UserStoryExportSerializer(many=True, required=False)
    tasks = TaskExportSerializer(many=True, required=False)
    issues = IssueExportSerializer(many=True, required=False)
    tags_colors = JsonField(required=False)
    anon_permissions = PgArrayField(required=False)
    public_permissions = PgArrayField(required=False)
    modified_date = serializers.DateTimeField(required=False)

    class Meta:
        model = projects_models.Project
        exclude = ('id', 'creation_template', 'members')
Exemplo n.º 2
0
class ProjectSerializer(ModelSerializer):
    tags = PgArrayField(required=False)
    anon_permissions = PgArrayField(required=False)
    public_permissions = PgArrayField(required=False)
    stars = serializers.SerializerMethodField("get_stars_number")
    my_permissions = serializers.SerializerMethodField("get_my_permissions")
    i_am_owner = serializers.SerializerMethodField("get_i_am_owner")
    tags_colors = TagsColorsField(required=False)

    class Meta:
        model = models.Project
        read_only_fields = ("created_date", "modified_date", "owner")
        exclude = ("last_us_ref", "last_task_ref", "last_issue_ref")

    def get_stars_number(self, obj):
        # The "stars_count" attribute is attached in the get_queryset of the viewset.
        return getattr(obj, "stars_count", 0)

    def get_my_permissions(self, obj):
        if "request" in self.context:
            return get_user_project_permissions(self.context["request"].user,
                                                obj)
        return []

    def get_i_am_owner(self, obj):
        if "request" in self.context:
            return is_project_owner(self.context["request"].user, obj)
        return False
Exemplo n.º 3
0
class ProjectSerializer(ModelSerializer):
    tags = PgArrayField(required=False)
    anon_permissions = PgArrayField(required=False)
    public_permissions = PgArrayField(required=False)
    stars = serializers.SerializerMethodField("get_stars_number")
    my_permissions = serializers.SerializerMethodField("get_my_permissions")
    i_am_owner = serializers.SerializerMethodField("get_i_am_owner")
    tags_colors = TagsColorsField(required=False)
    users = serializers.SerializerMethodField("get_users")
    total_closed_milestones = serializers.SerializerMethodField(
        "get_total_closed_milestones")

    class Meta:
        model = models.Project
        read_only_fields = ("created_date", "modified_date", "owner")
        exclude = ("last_us_ref", "last_task_ref", "last_issue_ref",
                   "issues_csv_uuid", "tasks_csv_uuid", "userstories_csv_uuid")

    def get_stars_number(self, obj):
        # The "stars_count" attribute is attached in the get_queryset of the viewset.
        return getattr(obj, "stars_count", 0)

    def get_my_permissions(self, obj):
        if "request" in self.context:
            return get_user_project_permissions(self.context["request"].user,
                                                obj)
        return []

    def get_i_am_owner(self, obj):
        if "request" in self.context:
            return is_project_owner(self.context["request"].user, obj)
        return False

    def get_users(self, obj):
        return UserSerializer(obj.members.all(), many=True).data

    def get_total_closed_milestones(self, obj):
        return obj.milestones.filter(closed=True).count()

    def validate_total_milestones(self, attrs, source):
        """
        Check that total_milestones is not null, it's an optional parameter but
        not nullable in the model.
        """
        value = attrs[source]
        if value is None:
            raise serializers.ValidationError(
                "Total milestones must be major or equal to zero")
        return attrs
Exemplo n.º 4
0
class TaskSerializer(WatchersValidator, ModelSerializer):
    tags = TagsField(required=False, default=[])
    external_reference = PgArrayField(required=False)
    comment = serializers.SerializerMethodField("get_comment")
    milestone_slug = serializers.SerializerMethodField("get_milestone_slug")
    blocked_note_html = serializers.SerializerMethodField("get_blocked_note_html")
    description_html = serializers.SerializerMethodField("get_description_html")
    is_closed =  serializers.SerializerMethodField("get_is_closed")

    class Meta:
        model = models.Task
        read_only_fields = ('id', 'ref', 'created_date', 'modified_date')

    def get_comment(self, obj):
        return ""

    def get_milestone_slug(self, obj):
        if obj.milestone:
            return obj.milestone.slug
        else:
            return None

    def get_blocked_note_html(self, obj):
        return mdrender(obj.project, obj.blocked_note)

    def get_description_html(self, obj):
        return mdrender(obj.project, obj.description)

    def get_is_closed(self, obj):
        return obj.status.is_closed
Exemplo n.º 5
0
class IssueSerializer(WatchersValidator, ModelSerializer):
    tags = TagsField(required=False)
    external_reference = PgArrayField(required=False)
    is_closed = serializers.Field(source="is_closed")
    comment = serializers.SerializerMethodField("get_comment")
    generated_user_stories = serializers.SerializerMethodField(
        "get_generated_user_stories")
    blocked_note_html = serializers.SerializerMethodField(
        "get_blocked_note_html")
    description_html = serializers.SerializerMethodField(
        "get_description_html")
    votes = serializers.SerializerMethodField("get_votes_number")

    class Meta:
        model = models.Issue
        read_only_fields = ('id', 'ref', 'created_date', 'modified_date')

    def get_comment(self, obj):
        # NOTE: This method and field is necessary to historical comments work
        return ""

    def get_generated_user_stories(self, obj):
        return obj.generated_user_stories.values("id", "ref", "subject")

    def get_blocked_note_html(self, obj):
        return mdrender(obj.project, obj.blocked_note)

    def get_description_html(self, obj):
        return mdrender(obj.project, obj.description)

    def get_votes_number(self, obj):
        # The "votes_count" attribute is attached in the get_queryset of the viewset.
        return getattr(obj, "votes_count", 0)
Exemplo n.º 6
0
class RoleSerializer(ModelSerializer):
    members_count = serializers.SerializerMethodField("get_members_count")
    permissions = PgArrayField(required=False)

    class Meta:
        model = Role
        fields = ('id', 'name', 'permissions', 'computable', 'project', 'order', 'members_count')

    def get_members_count(self, obj):
        return obj.memberships.count()
Exemplo n.º 7
0
class UserStorySerializer(serializers.ModelSerializer):
    tags = TagsField(default=[], required=False)
    external_reference = PgArrayField(required=False)
    owner = UserSerializer()
    assigned_to = UserSerializer()
    watchers = UserSerializer(many=True)
    points = PointSerializer(many=True)

    class Meta:
        model = us_models.UserStory
        exclude = ("backlog_order", "sprint_order", "kanban_order", "version")
Exemplo n.º 8
0
class UserStorySerializer(WatchersValidator, serializers.ModelSerializer):
    tags = TagsField(default=[], required=False)
    external_reference = PgArrayField(required=False)
    points = RolePointsField(source="role_points", required=False)
    total_points = serializers.SerializerMethodField("get_total_points")
    comment = serializers.SerializerMethodField("get_comment")
    milestone_slug = serializers.SerializerMethodField("get_milestone_slug")
    milestone_name = serializers.SerializerMethodField("get_milestone_name")
    origin_issue = serializers.SerializerMethodField("get_origin_issue")
    blocked_note_html = serializers.SerializerMethodField(
        "get_blocked_note_html")
    description_html = serializers.SerializerMethodField(
        "get_description_html")

    class Meta:
        model = models.UserStory
        depth = 0
        read_only_fields = ('created_date', 'modified_date')

    def get_total_points(self, obj):
        return obj.get_total_points()

    def get_comment(self, obj):
        # NOTE: This method and field is necessary to historical comments work
        return ""

    def get_milestone_slug(self, obj):
        if obj.milestone:
            return obj.milestone.slug
        else:
            return None

    def get_milestone_name(self, obj):
        if obj.milestone:
            return obj.milestone.name
        else:
            return None

    def get_origin_issue(self, obj):
        if obj.generated_from_issue:
            return {
                "id": obj.generated_from_issue.id,
                "ref": obj.generated_from_issue.ref,
                "subject": obj.generated_from_issue.subject,
            }
        return None

    def get_blocked_note_html(self, obj):
        return mdrender(obj.project, obj.blocked_note)

    def get_description_html(self, obj):
        return mdrender(obj.project, obj.description)
Exemplo n.º 9
0
class UserStorySerializer(CustomAttributesValuesWebhookSerializerMixin,
                          serializers.ModelSerializer):
    tags = TagsField(default=[], required=False)
    external_reference = PgArrayField(required=False)
    owner = UserSerializer()
    assigned_to = UserSerializer()
    watchers = UserSerializer(many=True)
    points = PointSerializer(many=True)

    class Meta:
        model = us_models.UserStory
        exclude = ("backlog_order", "sprint_order", "kanban_order", "version")

    def custom_attributes_queryset(self, project):
        return project.userstorycustomattributes.all()
Exemplo n.º 10
0
class RoleExportSerializer(serializers.ModelSerializer):
    permissions = PgArrayField(required=False)

    class Meta:
        model = users_models.Role
        exclude = ('id', 'project')