minor stuff

Signed-off-by: MiniDigger <admin@minidigger.me>
This commit is contained in:
MiniDigger 2021-05-13 15:39:37 +02:00
parent add4d0265b
commit 7b41a49dd1
9 changed files with 46 additions and 34 deletions

View File

@ -305,6 +305,8 @@ const msgs: LocaleMessageObject = {
discuss: { discuss: {
login: 'Log in', login: 'Log in',
toReply: 'to reply to this discussion', toReply: 'to reply to this discussion',
noTopic: 'There is no discussion for this project',
send: 'Reply posted!',
}, },
}, },
page: { page: {

View File

@ -1,21 +1,28 @@
<template> <template>
<div> <div>
<div id="discourse-comments"> <template v-if="project.topicId">
<iframe <div id="discourse-comments">
id="discourse-embed-frame" <iframe
ref="iframe" id="discourse-embed-frame"
:src="url" ref="iframe"
referrerpolicy="no-referrer-when-downgrade" :src="url"
sandbox="allow-scripts allow-popups allow-popups-to-escape-sandbox" referrerpolicy="no-referrer-when-downgrade"
></iframe> sandbox="allow-scripts allow-popups allow-popups-to-escape-sandbox"
</div> ></iframe>
<div v-if="isLoggedIn"> </div>
<MarkdownEditor ref="editor" saveable editing :cancellable="false" :deletable="false" @save="postReply"></MarkdownEditor> <div v-if="isLoggedIn">
</div> <MarkdownEditor ref="editor" saveable editing :cancellable="false" :deletable="false" @save="postReply"></MarkdownEditor>
<div v-else> </div>
<a @click="$auth.login($route.fullPath)">{{ $t('project.discuss.login') }}</a> <div v-else>
{{ $t('project.discuss.toReply') }} <a @click="$auth.login($route.fullPath)">{{ $t('project.discuss.login') }}</a>
</div> {{ $t('project.discuss.toReply') }}
</div>
</template>
<template v-else>
<v-alert type="info">
{{ $t('project.discuss.noTopic') }}
</v-alert>
</template>
</div> </div>
</template> </template>
@ -36,8 +43,13 @@ interface DiscourseEmbed {
components: { MarkdownEditor }, components: { MarkdownEditor },
}) })
export default class ProjectDiscussPage extends HangarProjectMixin { export default class ProjectDiscussPage extends HangarProjectMixin {
// TODO get topic id from project, get discourse url from backend // TODO get discourse url from backend
DE: DiscourseEmbed = { discourseUrl: 'http://localhost/', topicId: 13, discourseUserName: null, discourseEmbedUrl: null }; DE: DiscourseEmbed = {
discourseUrl: 'http://localhost/',
topicId: this.project.topicId,
discourseUserName: null,
discourseEmbedUrl: null,
};
$refs!: { $refs!: {
iframe: any; iframe: any;
@ -48,12 +60,12 @@ export default class ProjectDiscussPage extends HangarProjectMixin {
window.addEventListener('message', this.postMessageReceived, false); window.addEventListener('message', this.postMessageReceived, false);
} }
// TODO implement
async postReply(message: string) { async postReply(message: string) {
await this.$api.requestInternal('discourse/' + this.project.id + '/comment', true, 'POST', { content: message }); await this.$api.requestInternal('discourse/' + this.project.id + '/comment', true, 'POST', { content: message });
this.$refs.editor.isEditing = true; this.$refs.editor.isEditing = true;
this.$refs.editor.loading.save = false; this.$refs.editor.loading.save = false;
this.$refs.editor.rawEdited = ''; this.$refs.editor.rawEdited = '';
this.$util.success(this.$t('project.discuss.send'));
} }
get url() { get url() {

View File

@ -64,8 +64,8 @@
</v-btn> </v-btn>
</template> </template>
<v-list> <v-list>
<!--todo route for user action log--> <!--todo route for user action log, with filtering-->
<v-list-item v-if="$perms.canViewLogs" nuxt :to="`ddd`"> <v-list-item v-if="$perms.canViewLogs" nuxt :to="`/admin/log`">
<v-list-item-title> <v-list-item-title>
{{ $t('version.page.userAdminLogs') }} {{ $t('version.page.userAdminLogs') }}
</v-list-item-title> </v-list-item-title>

View File

@ -68,6 +68,8 @@ declare module 'hangar-api' {
lastUpdated: Date; lastUpdated: Date;
userActions: UserActions; userActions: UserActions;
settings: ProjectSettings; settings: ProjectSettings;
postId: number;
topicId: number;
promotedVersions: PromotedVersion[]; promotedVersions: PromotedVersion[];
} }
} }

View File

@ -84,6 +84,10 @@ public class LoginController extends HangarComponent {
@ResponseStatus(HttpStatus.NO_CONTENT) @ResponseStatus(HttpStatus.NO_CONTENT)
public void invalidateRefreshToken(@CookieValue(name = SecurityConfig.AUTH_NAME_REFRESH_COOKIE) String refreshToken) { public void invalidateRefreshToken(@CookieValue(name = SecurityConfig.AUTH_NAME_REFRESH_COOKIE) String refreshToken) {
tokenService.invalidateToken(refreshToken); tokenService.invalidateToken(refreshToken);
HttpSession session = request.getSession(false);
if (session != null) {
session.invalidate();
}
} }
// TODO needed? // TODO needed?
@ -95,13 +99,6 @@ public class LoginController extends HangarComponent {
return redirectToSso(ssoService.getVerifyUrl(config.getBaseUrl() + returnPath)); return redirectToSso(ssoService.getVerifyUrl(config.getBaseUrl() + returnPath));
} }
// TODO needed?
@GetMapping("/logout")
public ModelAndView logout(HttpSession session) {
session.invalidate();
return Routes.getRedirectToUrl(config.getAuthUrl() + "/accounts/logout/");
}
@GetMapping("/signup") @GetMapping("/signup")
public RedirectView signUp(@RequestParam(defaultValue = "") String returnUrl) { public RedirectView signUp(@RequestParam(defaultValue = "") String returnUrl) {
if (config.fakeUser.isEnabled()) { if (config.fakeUser.isEnabled()) {

View File

@ -29,12 +29,10 @@ public interface HangarUsersDAO {
@SqlUpdate("DELETE FROM project_stars WHERE user_id = :userId AND project_id = :projectId") @SqlUpdate("DELETE FROM project_stars WHERE user_id = :userId AND project_id = :projectId")
void setNotStarred(long projectId, long userId); void setNotStarred(long projectId, long userId);
// TODO useful to have a un-star all for users
@SqlUpdate("INSERT INTO project_watchers VALUES (:projectId, :userId)") @SqlUpdate("INSERT INTO project_watchers VALUES (:projectId, :userId)")
void setWatching(long projectId, long userId); void setWatching(long projectId, long userId);
@SqlUpdate("DELETE FROM project_watchers WHERE project_id = :projectId AND user_id = :userId") @SqlUpdate("DELETE FROM project_watchers WHERE project_id = :projectId AND user_id = :userId")
void setNotWatching(long projectId, long userId); void setNotWatching(long projectId, long userId);
// TODO useful to have an un-watch all for users
} }

View File

@ -94,6 +94,8 @@ public interface ProjectsApiDAO {
" p.license_url," + " p.license_url," +
" p.keywords," + " p.keywords," +
" p.forum_sync," + " p.forum_sync," +
" p.topic_id," +
" p.post_id," +
" p.donation_enabled," + " p.donation_enabled," +
" p.donation_email," + " p.donation_email," +
" p.donation_default_amount," + " p.donation_default_amount," +

View File

@ -45,7 +45,6 @@ public class MultiHangarApiException extends ResponseStatusException {
gen.writeBooleanField("isHangarApiException", true); gen.writeBooleanField("isHangarApiException", true);
gen.writeArrayFieldStart("exceptions"); gen.writeArrayFieldStart("exceptions");
for (HangarApiException exception : value.exceptions) { for (HangarApiException exception : value.exceptions) {
// TODO for some reason, can't use serializers.defaultSerializeValue
String message = exception.getReason(); String message = exception.getReason();
if (message == null || message.isBlank()) { if (message == null || message.isBlank()) {
message = exception.getStatus().getReasonPhrase(); message = exception.getStatus().getReasonPhrase();

View File

@ -62,15 +62,15 @@ public class ProjectsApiService extends HangarComponent {
relevance = "ts_rank(hp.search_words, websearch_to_tsquery('english', :query)) DESC"; relevance = "ts_rank(hp.search_words, websearch_to_tsquery('english', :query)) DESC";
} }
String orderingFirstHalf; String orderingFirstHalf;
// 1483056000 is the Ore epoch TODO change to hangar epoch // 1609459200 is the hangar epoch
// 86400 seconds to days // 86400 seconds to days
// 604800 seconds to weeks // 604800 seconds to weeks
switch(sort){ switch(sort){
case STARS: orderingFirstHalf = "hp.stars * "; break; case STARS: orderingFirstHalf = "hp.stars * "; break;
case DOWNLOADS: orderingFirstHalf ="(hp.downloads / 100) * "; break; case DOWNLOADS: orderingFirstHalf ="(hp.downloads / 100) * "; break;
case VIEWS: orderingFirstHalf ="(hp.views / 200) *"; break; case VIEWS: orderingFirstHalf ="(hp.views / 200) *"; break;
case NEWEST: orderingFirstHalf ="((EXTRACT(EPOCH FROM hp.created_at) - 1483056000) / 86400) *"; break; case NEWEST: orderingFirstHalf ="((EXTRACT(EPOCH FROM hp.created_at) - 1609459200) / 86400) *"; break;
case UPDATED: orderingFirstHalf ="((EXTRACT(EPOCH FROM hp.last_updated) - 1483056000) / 604800) *"; break; case UPDATED: orderingFirstHalf ="((EXTRACT(EPOCH FROM hp.last_updated) - 1609459200) / 604800) *"; break;
case ONLY_RELEVANCE: orderingFirstHalf = ""; break; case ONLY_RELEVANCE: orderingFirstHalf = ""; break;
case RECENT_DOWNLOADS : orderingFirstHalf ="hp.recent_views *"; break; case RECENT_DOWNLOADS : orderingFirstHalf ="hp.recent_views *"; break;
case RECENT_VIEWS: orderingFirstHalf ="hp.recent_downloads *"; break; case RECENT_VIEWS: orderingFirstHalf ="hp.recent_downloads *"; break;