Skip to content

Commit 2e670e0

Browse files
committed
WIP: impr(frontend): Handle alphanumeric GL3 access codes
1 parent 76ce491 commit 2e670e0

File tree

8 files changed

+93
-11
lines changed

8 files changed

+93
-11
lines changed

app/Http/Middleware/RoomAuthenticate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function handle($request, Closure $next, $allowUnAuthenticated = false)
8585

8686
$accessCode = $request->header('Access-Code');
8787
// check if access code is correct
88-
if (is_numeric($accessCode) && $room->access_code == $accessCode) {
88+
if ($room->access_code == $accessCode) {
8989
$authenticated = true;
9090
} else {
9191
Counter::get('room_authentication_errors_total')->inc('access_code_invalid');

app/Http/Requests/UpdateRoomSettings.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ public function rules()
4242
*/
4343
private function getAccessCodeValidationRule(): array
4444
{
45-
// Support keeping old 6-digit codes (Greenlight v2)
45+
// Support keeping
46+
// * old 6-digit numeric codes (Greenlight v2)
47+
// * old 6-digit alphanumeric codes (Greenlight v3)
4648
$current = $this->room->access_code ?? '';
4749
$incoming = $this->str('access_code') ?? '';
50+
$alphanumeric = $current == $incoming && ! is_numeric($current);
4851
$digits = ($current == $incoming && strlen($current) == 6) ? 6 : 9;
4952

50-
$rules = ['numeric', 'digits:'.$digits, 'bail'];
53+
$rules = $alphanumeric
54+
? ['alpha_num:ascii', 'lowercase', 'size:6', 'bail']
55+
: ['numeric', 'digits:'.$digits, 'bail'];
5156

5257
// Make sure that the given room type id is a number
5358
if (is_numeric($this->input('room_type'))) {

app/Models/Room.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ public function getModeratorOnlyMessage()
383383
$message = __('rooms.invitation.room', ['roomname' => $this->name, 'platform' => $appName]).'<br>';
384384
$message .= __('rooms.invitation.link').': '.config('app.url').'/rooms/'.$this->id;
385385
if ($this->access_code != null) {
386-
$message .= '<br>'.__('rooms.invitation.code').': '.implode('-', str_split($this->access_code, 3));
386+
$message .= '<br>'.__('rooms.invitation.code').': ';
387+
$message .= $this->legacy_code ? implode('-', str_split($this->access_code, 3)) : $this->access_code;
387388
}
388389

389390
return $message;

resources/js/components/RoomShareButton.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,10 @@ const roomUrl = computed(() => {
115115
});
116116
117117
const formattedAccessCode = computed(() => {
118-
return String(props.room.access_code)
119-
.match(/.{1,3}/g)
120-
.join("-");
118+
return isNaN(props.room.access_code)
119+
? props.room.access_code
120+
: String(props.room.access_code)
121+
.match(/.{1,3}/g)
122+
.join("-");
121123
});
122124
</script>

resources/js/views/RoomsView.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@
119119
id="access-code"
120120
v-model="accessCodeInput"
121121
autofocus
122-
:mask="room.legacy_code ? '999-999' : '999-999-999'"
123-
:placeholder="room.legacy_code ? '123-456' : '123-456-789'"
122+
:mask="room.legacy_code ? '******' : '999-999-999'"
123+
:placeholder="room.legacy_code ? '123abc' : '123-456-789'"
124124
:invalid="accessCodeInvalid"
125125
:disabled="authThrottledFor > 0"
126126
class="text-center"

tests/Backend/Feature/api/v1/Room/RoomTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,13 @@ public function test_access_code_guests()
557557
$this->withHeaders(['Access-Code' => '012345'])->getJson(route('api.v1.rooms.show', ['room' => $room]))
558558
->assertStatus(200)
559559
->assertJsonFragment(['authenticated' => true]);
560+
561+
// Try with legacy alphanumeric access code
562+
$room->access_code = '012abc';
563+
$room->save();
564+
$this->withHeaders(['Access-Code' => '012abc'])->getJson(route('api.v1.rooms.show', ['room' => $room]))
565+
->assertStatus(200)
566+
->assertJsonFragment(['authenticated' => true]);
560567
}
561568

562569
/**

tests/Frontend/e2e/RoomsViewGeneral.cy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ describe("Room View general", function () {
384384
cy.contains("rooms.require_access_code").should("be.visible");
385385

386386
// Submit valid access code
387-
cy.get("#access-code").type("012345");
387+
cy.get("#access-code").type("012abc");
388388
});
389389

390390
cy.fixture("room.json").then((room) => {
@@ -404,7 +404,7 @@ describe("Room View general", function () {
404404
cy.get('[data-test="room-login-button"]').click();
405405

406406
cy.wait("@roomRequest").then((interception) => {
407-
expect(interception.request.headers["access-code"]).to.eq("012345");
407+
expect(interception.request.headers["access-code"]).to.eq("012abc");
408408
});
409409

410410
cy.get('[data-test="room-access-code-overlay"]').should("not.exist");

tests/Frontend/e2e/RoomsViewSettings.cy.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1236,6 +1236,73 @@ describe("Rooms view settings", function () {
12361236
);
12371237
});
12381238

1239+
it("change settings with GL3 access code", function () {
1240+
cy.fixture("roomSettings.json").then((roomSettings) => {
1241+
roomSettings.data.access_code = "fck4fd";
1242+
cy.intercept("GET", "api/v1/rooms/abc-def-123/settings", {
1243+
statusCode: 200,
1244+
body: roomSettings,
1245+
}).as("roomSettingsRequest");
1246+
});
1247+
1248+
cy.visit("/rooms/abc-def-123#tab=settings");
1249+
cy.wait("@roomSettingsRequest");
1250+
1251+
cy.get("#room-setting-access_code")
1252+
.should("have.value", "fck4fd")
1253+
.and("not.be.disabled");
1254+
1255+
// Change settings
1256+
cy.get("#room-setting-name").clear();
1257+
cy.get("#room-setting-name").type("Meeting Two");
1258+
1259+
// Save settings
1260+
cy.fixture("roomTypesWithSettings.json").then(() => {
1261+
cy.fixture("roomSettings.json").then((roomSettings) => {
1262+
roomSettings.data.name = "Meeting Two";
1263+
roomSettings.data.access_code = "fck4fd";
1264+
1265+
cy.intercept("PUT", "api/v1/rooms/abc-def-123", {
1266+
statusCode: 200,
1267+
body: roomSettings,
1268+
}).as("roomSettingsSaveRequest");
1269+
1270+
cy.get('[data-test="room-settings-save-button"]').click();
1271+
});
1272+
});
1273+
1274+
cy.wait("@roomSettingsSaveRequest").then((interception) => {
1275+
expect(interception.request.body).to.eql({
1276+
name: "Meeting Two",
1277+
expert_mode: true,
1278+
welcome: "Welcome message",
1279+
short_description: "Short description",
1280+
access_code: "fck4fd",
1281+
room_type: 2,
1282+
mute_on_start: true,
1283+
lock_settings_disable_cam: false,
1284+
webcams_only_for_moderator: true,
1285+
lock_settings_disable_mic: false,
1286+
lock_settings_disable_private_chat: false,
1287+
lock_settings_disable_public_chat: true,
1288+
lock_settings_disable_note: true,
1289+
lock_settings_hide_user_list: true,
1290+
everyone_can_start: false,
1291+
allow_membership: false,
1292+
allow_guests: true,
1293+
default_role: 1,
1294+
lobby: 2,
1295+
visibility: 1,
1296+
record_attendance: false,
1297+
record: false,
1298+
auto_start_recording: false,
1299+
});
1300+
});
1301+
1302+
// Check that settings are shown correctly
1303+
cy.get("#room-setting-name").should("have.value", "Meeting Two");
1304+
});
1305+
12391306
it("change settings errors", function () {
12401307
cy.fixture("roomTypesWithSettings.json").then((roomTypes) => {
12411308
cy.fixture("roomSettings.json").then((roomSettings) => {

0 commit comments

Comments
 (0)