Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add group history page #10430

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
34 changes: 27 additions & 7 deletions app/Http/Controllers/GroupHistoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace App\Http\Controllers;

use App\Models\Group;
use App\Models\User;
use App\Models\UserGroupEvent;

Expand All @@ -16,11 +17,10 @@ public function index()
{
$rawParams = request()->all();
$params = get_params($rawParams, null, [
'group:string',
'group',
'max_date:time',
'min_date:time',
'sort:string',
'user:string',
'user',
], ['null_missing' => true]);
$query = UserGroupEvent::visibleForUser(auth()->user());

Expand All @@ -35,11 +35,19 @@ public function index()
}

if ($params['max_date'] !== null) {
$params['max_date']->endOfDay();

$query->where('created_at', '<=', $params['max_date']);

$params['max_date'] = json_date($params['max_date']);
}

if ($params['min_date'] !== null) {
$params['min_date']->startOfDay();

$query->where('created_at', '>=', $params['min_date']);

$params['min_date'] = json_date($params['min_date']);
}

if ($params['user'] !== null) {
Expand All @@ -52,16 +60,28 @@ public function index()
}
}

$cursorHelper = UserGroupEvent::makeDbCursorHelper($params['sort']);
$cursorHelper = UserGroupEvent::makeDbCursorHelper($rawParams['sort'] ?? null);
$params['sort'] = $cursorHelper->getSortName();
[$events, $hasMore] = $query
->cursorSort($cursorHelper, cursor_from_params($rawParams))
->limit(50)
->getWithHasMore();
$cursor = $cursorHelper->next($events, $hasMore);

return [
$eventGroupIds = $events->pluck('group_id');
$groups = app('groups')->all()->filter(
fn (Group $group) =>
$eventGroupIds->contains($group->getKey()) ||
priv_check('GroupShow', $group)->can(),
);
$json = [
...cursor_for_response($cursorHelper->next($events, $hasMore)),
'events' => json_collection($events, 'UserGroupEvent'),
...cursor_for_response($cursor),
'groups' => json_collection($groups, 'Group'),
'params' => $params,
];

return is_json_request()
? $json
: ext_view('group_history.index', compact('json'));
}
}
14 changes: 14 additions & 0 deletions app/Singletons/OsuAuthorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use App\Models\Forum\Topic;
use App\Models\Forum\TopicCover;
use App\Models\Genre;
use App\Models\Group;
use App\Models\Language;
use App\Models\LegacyMatch\LegacyMatch;
use App\Models\Multiplayer\Room;
Expand Down Expand Up @@ -1805,6 +1806,15 @@ public function checkForumTopicVote(?User $user, Topic $topic): string
return 'ok';
}

public function checkGroupShow(?User $user, Group $group): string
{
if ($group->hasListing() || $user?->isGroup($group)) {
return 'ok';
}

return 'unauthorized';
}

public function checkIsOwnClient(?User $user, Client $client): string
{
if ($user === null || $user->getKey() !== $client->user_id) {
Expand Down Expand Up @@ -1954,6 +1964,10 @@ public function checkScorePin(?User $user, ScoreBest|Solo\Score $score): string

public function checkUserGroupEventShowActor(?User $user, UserGroupEvent $event): string
{
if ($event->group->identifier === 'default') {
return $user?->isPrivileged() ? 'ok' : 'unauthorized';
}

if ($user?->isGroup($event->group)) {
return 'ok';
}
Expand Down
3 changes: 3 additions & 0 deletions app/Singletons/RouteSection.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ class RouteSection
'friends_controller' => [
'_' => 'home',
],
'group_history_controller' => [
'_' => 'home',
],
'groups_controller' => [
'_' => 'home',
],
Expand Down
4 changes: 4 additions & 0 deletions app/Transformers/UserGroupEventTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function transform(UserGroupEvent $event): array

public function includeActor(UserGroupEvent $event): ResourceInterface
{
if ($event->actor_id === null) {
return $this->null();
}

return $this->primitive([
'id' => $event->actor_id,
'username' => $event->details['actor_name'],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
},
"dependencies": {
"@discordapp/twemoji": "^14.0.2",
"@fortawesome/fontawesome-free": "^5.6.3",
"@fortawesome/fontawesome-free": "^5.15.4",
"@types/autosize": "^4.0.1",
"@types/bootstrap": "^3.3.0",
"@types/cloudflare-turnstile": "^0.1.5",
Expand Down
3 changes: 3 additions & 0 deletions resources/css/bem-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@
@import "bem/game-mode-link";
@import "bem/github-user";
@import "bem/grid-items";
@import "bem/group-history";
@import "bem/group-history-event";
@import "bem/group-history-search-form";
@import "bem/header-buttons";
@import "bem/header-nav-mobile";
@import "bem/header-nav-v4";
Expand Down
13 changes: 13 additions & 0 deletions resources/css/bem/form-select.less
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// See the LICENCE file in the repository root for full licence text.

.form-select {
@_top: form-select;

.default-border-radius();
background-color: @osu-colour-b6;
color: @osu-colour-c1;
Expand Down Expand Up @@ -40,6 +42,12 @@
flex: 1;
}

&--group-history {
background-color: inherit;
font-size: @font-size--title-small-3;
margin: -5px -10px -5px -5px;
cl8n marked this conversation as resolved.
Show resolved Hide resolved
}

&--simple-form {
background-color: @osu-colour-b4;
color: @osu-colour-c1;
Expand All @@ -52,5 +60,10 @@
background-color: inherit;
border-radius: inherit;
max-width: 100%;

.@{_top}--group-history & {
text-overflow: ellipsis;
cl8n marked this conversation as resolved.
Show resolved Hide resolved
width: 100%;
}
}
}
65 changes: 65 additions & 0 deletions resources/css/bem/group-history-event.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

.group-history-event {
--message-weight: normal;
align-items: center;
display: flex;
font-size: @font-size--title-small;
gap: 15px;

@bold-events: group-add, group-remove, group-rename;
each(@bold-events, {
&--@{value} {
--message-weight: bold;
}
});
Comment on lines +11 to +16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

combine with below?


@icons: {
group-add: users;
group-remove: users-slash;
group-rename: users-cog;
user-add: user-plus;
user-add-playmodes: user-tag;
user-remove: user-minus;
user-remove-playmodes: user-tag;
user-set-default: user-cog;
cl8n marked this conversation as resolved.
Show resolved Hide resolved
};
each(@icons, {
&--@{key} {
@icon-var: 'fa-var-@{value}';
--icon: @@icon-var;
}
});

&__icon {
.fas();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can use an fa-fw equivalent as well

background-color: var(--group-colour, hsl(var(--hsl-b1)));
border-radius: 10000px;
color: hsl(var(--hsl-b6));
padding: 3px 6px;

&::before {
content: var(--icon);
}
}

&__info {
align-items: end;
cl8n marked this conversation as resolved.
Show resolved Hide resolved
color: hsl(var(--hsl-f1));
column-gap: 15px;
display: flex;
flex-direction: column;
flex-shrink: 0;
font-size: @font-size--normal;

@media @desktop {
flex-direction: row-reverse;
}
}

&__message {
flex-grow: 1;
font-weight: var(--message-weight);
}
}
49 changes: 49 additions & 0 deletions resources/css/bem/group-history-search-form.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

.group-history-search-form {
--input-bg: hsl(var(--hsl-b5));
--input-border-radius: @border-radius--large;
background: hsl(var(--hsl-b4));

&__content {
.default-gutter-v2();
padding-bottom: 20px;
padding-top: 20px;

&--buttons {
background-color: hsl(var(--hsl-b3));
display: flex;
gap: 10px;
justify-content: center;
padding-bottom: 10px;
padding-top: 10px;
}

&--inputs {
color-scheme: dark;
display: grid;
gap: 10px;
grid-template-columns: repeat(2, 1fr) repeat(2, 180px);

@media @mobile {
grid-template-columns: repeat(2, 1fr);

> :nth-child(-n + 2) {
grid-column: span 2;
}
Comment on lines +32 to +34
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set on the elements themselves?

}
}
}

&__input {
.reset-input();
font-size: @font-size--title-small-3;
width: 100%;
}

&__label {
color: var(--label-colour);
padding-bottom: 5px;
}
}
16 changes: 16 additions & 0 deletions resources/css/bem/group-history.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

.group-history {
&--events {
display: flex;
flex-direction: column;
gap: 10px;
}

&--none {
font-size: @font-size--title-small-3;
margin: 0;
text-align: center;
}
}
10 changes: 10 additions & 0 deletions resources/css/bem/osu-page.less
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,16 @@
.default();
}

&--group-history-footer {
.default();
.default-gutter-v2();
background-color: hsl(var(--hsl-b4));
font-size: @font-size--normal;
padding-bottom: 10px;
padding-top: 10px;
text-align: center;
}

&--info-bar {
.default-gutter-v2();
padding-top: 5px;
Expand Down
3 changes: 2 additions & 1 deletion resources/css/bem/show-more-link.less
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
margin: 40px 0;
}

&--chat-conversation-earlier-messages {
&--chat-conversation-earlier-messages,
&--group-history {
margin: 20px auto 0;
}

Expand Down
11 changes: 11 additions & 0 deletions resources/js/entrypoints/group-history.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import Main from 'group-history/main';
import core from 'osu-core-singleton';
import * as React from 'react';
import { parseJson } from 'utils/json';

core.reactTurbolinks.register('group-history', () => (
<Main {...parseJson('json-group-history')} />
));