Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions nextcloudappstore/core/migrations/0041_app_rating_reply.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Generated by Django 4.2.30 on 2026-11-16 14:33
#
# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: AGPL-3.0-or-later

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('core', '0040_app_release_date'),
]

operations = [
migrations.AddField(
model_name='apprating',
name='replied_at',
field=models.DateTimeField(blank=True, null=True, verbose_name='Replied at'),
),
migrations.AddField(
model_name='apprating',
name='reply',
field=models.TextField(blank=True, default='', help_text='Reply from the app owner in Markdown. One reply per rating; editing replaces it.', verbose_name='Reply'),
),
]
7 changes: 7 additions & 0 deletions nextcloudappstore/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,13 @@ class AppRating(TranslatableModel):
)
)
appeal = BooleanField(default=False, verbose_name=_("Appeal"))
reply = TextField(
verbose_name=_("Reply"),
default="",
blank=True,
help_text=_("Reply from the app owner in Markdown. One reply per rating; editing replaces it."),
)
replied_at = DateTimeField(verbose_name=_("Replied at"), null=True, blank=True)

class Meta:
unique_together = (("app", "user"),)
Expand Down
7 changes: 7 additions & 0 deletions nextcloudappstore/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class AppRatingSerializer(serializers.ModelSerializer):
user = UserSerializer(many=False, read_only=True)
translations = TranslatedFieldsField(shared_model=AppRating)
relative_rated_at = SerializerMethodField()
relative_replied_at = SerializerMethodField()

class Meta:
model = AppRating
Expand All @@ -29,7 +30,13 @@ class Meta:
"app",
"relative_rated_at",
"appeal",
"reply",
"replied_at",
"relative_replied_at",
)

def get_relative_rated_at(self, obj):
return naturaltime(obj.rated_at)

def get_relative_replied_at(self, obj):
return naturaltime(obj.replied_at) if obj.replied_at else ""
24 changes: 24 additions & 0 deletions nextcloudappstore/core/static/assets/app/api/Ratings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface IRating {
value: number;
};
appeal: boolean;
reply: string;
relativeRepliedAt: string;
}

interface IApiRating {
Expand All @@ -39,6 +41,8 @@ interface IApiRating {
lastName: string;
};
appeal: boolean;
reply?: string;
relativeRepliedAt?: string;
}

export function filterEmptyComments(ratings: IApiRating[],
Expand Down Expand Up @@ -91,6 +95,8 @@ export function convertRating(rating: IApiRating, lang: string): IRating {
value: rating.rating,
},
relativeRatedAt: rating.relativeRatedAt,
relativeRepliedAt: rating.relativeRepliedAt || '',
reply: rating.reply || '',
};
}

Expand Down Expand Up @@ -148,3 +154,21 @@ export function deleteRating(url: string, token: string, rating: IRating, admin
url,
}, token);
}

/**
* Saves the app owner's reply to a rating; an empty reply removes it
* @param url
* @param token
* @param rating
* @param reply
*/
export function replyToRating(url: string, token: string, rating: IRating, reply: string) {
return pageRequest({
data: {
comment_id: rating.id,
reply,
},
method: HttpMethod.POST,
url,
}, token);
}
50 changes: 50 additions & 0 deletions nextcloudappstore/core/static/assets/app/api/RatingsSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,54 @@ describe('Ratings and comments', () => {
expect(result.rating.name).toBe('bad');
});

it('convert ratings with an owner reply', () => {
const data = {
appeal: false,
id: 66,
ratedAt: '2017-03-22T16:54:32.168975Z',
rating: 0.0,
relativeRatedAt: '',
relativeRepliedAt: '2 days ago',
reply: 'Fixed in 2.1, thanks!',
translations: {
de: {
comment: 'blah',
},
},
user: {
firstName: 'Tom',
lastName: 'Jones',
},
};

const result = convertRating(data, 'de');

expect(result.reply).toBe('Fixed in 2.1, thanks!');
expect(result.relativeRepliedAt).toBe('2 days ago');
});

it('convert ratings without a reply', () => {
const data = {
appeal: false,
id: 66,
ratedAt: '2017-03-22T16:54:32.168975Z',
rating: 1.0,
relativeRatedAt: '',
translations: {
de: {
comment: 'blah',
},
},
user: {
firstName: 'Tom',
lastName: 'Jones',
},
};

const result = convertRating(data, 'de');

expect(result.reply).toBe('');
expect(result.relativeRepliedAt).toBe('');
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import {appealRating, deleteRating, IRating} from '../../api/Ratings';
import {appealRating, deleteRating, IRating, replyToRating} from '../../api/Ratings';
import {renderMd} from '../../dom/Markdown';
import {render, Unescaped} from '../../dom/Templating';
import {queryAll, queryOrThrow} from '../../dom/Facades';
Expand All @@ -13,12 +13,17 @@ export function renderRating(template: HTMLTemplateElement,
const context = {
'.author': rating.fullUserName,
'.comment': new Unescaped(renderMd(rating.comment)),
'.comment-reply__date': rating.relativeRepliedAt,
'.comment-reply__text': new Unescaped(renderMd(rating.reply)),
'.date': rating.relativeRatedAt,
};

const root = render(template, context);
root.id = `rating-${rating.id}`; // Set the id attribute
root.classList.add(rating.rating.name);
if (rating.reply === '') {
queryAll('.comment-reply', root).forEach((reply) => reply.remove());
}
return root;
}

Expand Down Expand Up @@ -48,6 +53,8 @@ export function renderRatingActions(template: HTMLTemplateElement,
// Ignoring
}
}
initReplyForm(root, rating, lang);

// Init event listeners for comment actions buttons
const commentActions = queryAll('.comment-actions-button', root);
commentActions.forEach((commentActionButton: HTMLButtonElement) => {
Expand All @@ -69,12 +76,59 @@ export function renderRatingActions(template: HTMLTemplateElement,
appealRating(url, token, rating, false).then(() => reloadWithRatingParams());
} else if (commentActionButton.classList.contains('comment-actions__appeal_cancel_admin')) {
deleteRating(url, token, rating, true).then(() => reloadWithRatingParams(true));
} else if (commentActionButton.classList.contains('comment-actions__reply')) {
const form = queryOrThrow('.comment-reply-form', HTMLFormElement, root);
form.hidden = !form.hidden;
if (!form.hidden) {
queryOrThrow('.comment-reply-form__text', HTMLTextAreaElement, form).focus();
}
}
});
});
return root;
}

/**
* Sets up the app owner's reply form, if the template contains one
* @param root rendered comment actions
* @param rating
* @param lang language the comment list is shown in
*/
function initReplyForm(root: HTMLElement, rating: IRating, lang: string) {
const form = root.querySelector<HTMLFormElement>('.comment-reply-form');
if (form === null) {
return;
}
const text = queryOrThrow('.comment-reply-form__text', HTMLTextAreaElement, form);
const label = queryOrThrow('.comment-actions__reply-label', HTMLSpanElement, root);
const deleteButton = queryOrThrow('.comment-reply-form__delete', HTMLButtonElement, form);
text.value = rating.reply;
if (rating.reply === '') {
queryOrThrow('.comment-reply-form__delete-row', HTMLDivElement, form).remove();
} else {
label.innerText = label.dataset.editLabel || label.innerText;
}

const save = (reply: string) => {
const token = queryOrThrow('input[name="csrfmiddlewaretoken"]', HTMLInputElement, root).value;
const url = queryOrThrow('input[name="comment-action-url"]', HTMLInputElement, root).value;
replyToRating(url, token, rating, reply).then(() => {
const params = `comment_id=${rating.id}&bad_comment_lang=${lang}`;
window.location.href = window.location.pathname + '?' + params;
});
};

form.addEventListener('submit', (event) => {
event.preventDefault();
save(text.value);
});
deleteButton.addEventListener('click', () => save(''));
queryOrThrow('.comment-reply-form__cancel', HTMLButtonElement, form).addEventListener('click', () => {
text.value = rating.reply;
form.hidden = true;
});
}

export function renderEmptyRatings(template: HTMLTemplateElement): HTMLElement {
return render(template, {});
}
43 changes: 43 additions & 0 deletions nextcloudappstore/core/static/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,49 @@ address {
margin-right: 0;
}

.rating-comment .comment-actions {
flex-wrap: wrap;
}

.rating-comment .comment-reply {
margin: 15px 25px 0;
padding: 10px 15px;
border-left: 3px solid var(--color-primary);
background-color: var(--color-main-background);
border-radius: var(--border-radius);
}

.rating-comment:has(> .comment-reply:last-child) {
padding-bottom: 25px;
}

.rating-comment .comment-reply__header {
display: flex;
justify-content: space-between;
margin-bottom: 5px;
}

.rating-comment .comment-reply__label {
font-weight: bold;
}

.rating-comment .comment-reply-form {
flex-basis: 100%;
margin-top: 15px;
}

.rating-comment .comment-reply-form__buttons {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 10px;
margin-top: 10px;
}

.rating-comment .comment-reply-form__buttons button {
margin: 0;
}

@media (max-width: 500px) {
.rating-comment header {
display: flex;
Expand Down
25 changes: 25 additions & 0 deletions nextcloudappstore/core/templates/app/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ <h2 id="downloads" class="section-heading">{% trans "Releases" %}</h2>
<div class="date"></div>
</header>
<div class="comment"></div>
<div class="comment-reply">
<div class="comment-reply__header">
<span class="comment-reply__label">{% with owner_name=object.owner.get_full_name %}{% if owner_name %}{% blocktrans %}Reply from {{ owner_name }} (app owner){% endblocktrans %}{% else %}{% trans 'Reply from the app owner' %}{% endif %}{% endwith %}</span>
<span class="comment-reply__date"></span>
</div>
<div class="comment-reply__text"></div>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -312,6 +319,24 @@ <h2 id="downloads" class="section-heading">{% trans "Releases" %}</h2>
{% trans 'Cancel spam appeal' %}
</button>
{% endif %}
{% if request.user == object.owner %}
<button class="btn btn-default comment-actions-button comment-actions__reply">
<span class="icon material-symbols-outlined">reply</span>
<span class="comment-actions__reply-label" data-add-label="{% trans 'Reply' %}" data-edit-label="{% trans 'Edit reply' %}">{% trans 'Reply' %}</span>
</button>
<form class="comment-reply-form" hidden>
<textarea class="form-control comment-reply-form__text" rows="4" maxlength="2000"
aria-label="{% trans 'Your reply' %}"
placeholder="{% trans 'Reply to this comment, for example to say that a reported issue is fixed. Markdown is supported. You can reply once and edit your reply later.' %}"></textarea>
<div class="comment-reply-form__buttons">
<button type="submit" class="btn btn-primary comment-reply-form__save">{% trans 'Save reply' %}</button>
<button type="button" class="btn btn-default comment-reply-form__cancel">{% trans 'Cancel' %}</button>
</div>
<div class="comment-reply-form__buttons comment-reply-form__delete-row">
<button type="button" class="btn btn-danger comment-reply-form__delete">{% trans 'Delete reply' %}</button>
</div>
</form>
{% endif %}
</div>
</template>

Expand Down
Loading
Loading