Skip to content

Commit

Permalink
Merge branch 'master' into update-less
Browse files Browse the repository at this point in the history
  • Loading branch information
notbakaneko authored Dec 6, 2024
2 parents 09b00ee + 46ee426 commit 09c325e
Show file tree
Hide file tree
Showing 11 changed files with 365 additions and 3 deletions.
30 changes: 30 additions & 0 deletions app/Http/Controllers/TeamsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@

class TeamsController extends Controller
{
public function edit(string $id): Response
{
$team = Team::findOrFail($id);
priv_check('TeamUpdate', $team)->ensureCan();

return ext_view('teams.edit', compact('team'));
}

public function show(string $id): Response
{
$team = Team
Expand All @@ -23,4 +31,26 @@ public function show(string $id): Response

return ext_view('teams.show', compact('team'));
}

public function update(string $id): Response
{
$team = Team::findOrFail($id);
priv_check('TeamUpdate', $team)->ensureCan();
$params = get_params(\Request::all(), 'team', [
'default_ruleset_id:int',
'description',
'header:file',
'header_remove:bool',
'is_open:bool',
'logo:file',
'logo_remove:bool',
'url',
]);

$team->fill($params)->saveOrExplode();

\Session::flash('popup', osu_trans('teams.edit.saved'));

return response(null, 201);
}
}
35 changes: 35 additions & 0 deletions app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ public function setLogoAttribute(?string $value): void
}
}

public function setDefaultRulesetIdAttribute(?int $value): void
{
$this->attributes['default_ruleset_id'] = Beatmap::MODES[Beatmap::modeStr($value) ?? 'osu'];
}

public function setUrlAttribute(?string $value): void
{
$this->attributes['url'] = $value === null
? null
: (is_http($value)
? $value
: "https://{$value}"
);
}

public function descriptionHtml(): string
{
$description = presence($this->description);
Expand All @@ -70,6 +85,26 @@ public function header(): Uploader
);
}

public function isValid(): bool
{
$this->validationErrors()->reset();

if ($this->isDirty('url')) {
$url = $this->url;
if ($url !== null && !is_http($url)) {
$this->validationErrors()->add('url', 'url');
}
}

if ($this->isDirty('ruleset_id')) {
if (Beatmap::modeStr($this->ruleset_id) === null) {
$this->validationErrors()->add('ruleset_id', '.unknown_ruleset_id');
}
}

return $this->validationErrors()->isEmpty();
}

public function logo(): Uploader
{
return $this->logo ??= new Uploader(
Expand Down
8 changes: 8 additions & 0 deletions app/Singletons/OsuAuthorize.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use App\Models\OAuth\Client;
use App\Models\Score\Best\Model as ScoreBest;
use App\Models\Solo;
use App\Models\Team;
use App\Models\Traits\ReportableInterface;
use App\Models\User;
use App\Models\UserContestEntry;
Expand Down Expand Up @@ -1907,6 +1908,13 @@ public function checkScorePin(?User $user, ScoreBest|Solo\Score $score): string
return 'ok';
}

public function checkTeamUpdate(?User $user, Team $team): ?string
{
$this->ensureLoggedIn($user);

return $team->leader_id === $user->getKey() ? 'ok' : null;
}

public function checkUserGroupEventShowActor(?User $user, UserGroupEvent $event): string
{
if ($user?->isGroup($event->group)) {
Expand Down
2 changes: 2 additions & 0 deletions resources/css/bem-index.less
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@
@import "bem/team-info-entries";
@import "bem/team-info-entry";
@import "bem/team-members";
@import "bem/team-settings";
@import "bem/team-settings-description-preview";
@import "bem/team-summary";
@import "bem/textual-button";
@import "bem/title";
Expand Down
8 changes: 8 additions & 0 deletions resources/css/bem/team-settings-description-preview.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

.team-settings-description-preview {
padding: 0 var(--padding);
overflow-y: scroll;
max-height: calc(70 * var(--vh));
}
44 changes: 44 additions & 0 deletions resources/css/bem/team-settings.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

.team-settings {
display: grid;
gap: 5px;

&__description-preview {
--padding: 10px;
padding: var(--padding) 0;
background-color: hsl(var(--hsl-b3));
border-radius: @border-radius-large;
}

&__help {
color: hsl(var(--hsl-c2));
font-size: @font-size--normal;
}

&__image {
min-width: 0;
max-width: 100%;
border-radius: @border-radius-large;
object-fit: contain;
}

&__item {
display: grid;
grid-template-columns: 2fr 1fr;
gap: 15px;

&--buttons {
grid-template-columns: 1fr auto;
}

&--description {
grid-template-columns: 1fr 1fr;
}

&--image {
grid-template-columns: 1fr;
}
}
}
33 changes: 33 additions & 0 deletions resources/lang/en/teams.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@
// See the LICENCE file in the repository root for full licence text.

return [
'edit' => [
'saved' => 'Settings saved successfully',

'description' => [
'label' => 'Description',
'title' => 'Team Description',
],

'header' => [
'label' => 'Header Image',
'title' => 'Set Header Image',
],

'logo' => [
'label' => 'Team Flag',
'title' => 'Set Team Flag',
],

'settings' => [
'application' => 'Team Application',
'application_help' => 'Whether to allow people to apply for the team',
'default_ruleset' => 'Default Ruleset',
'default_ruleset_help' => 'The ruleset to be selected by default when visiting the team page',
'title' => 'Team Settings',
'url' => 'URL',

'application_state' => [
'state_0' => 'Closed',
'state_1' => 'Open',
],
],
],

'show' => [
'bar' => [
'settings' => 'Settings',
Expand Down
Loading

0 comments on commit 09c325e

Please sign in to comment.