(fix) felhős projekthez csak bejelentkezés után lehet csatlakozni, név megjelenítése a kapcsolatok mellett a terepbejárás nézetben.
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 6s
This commit is contained in:
@@ -6,6 +6,15 @@ import '../models/project.dart';
|
||||
import 'app_database.dart';
|
||||
import 'ts_sync_service.dart';
|
||||
|
||||
class ProjectRequiresLoginException implements Exception {
|
||||
final String message;
|
||||
ProjectRequiresLoginException(
|
||||
[this.message = 'Felhős projekt használatához be kell jelentkezni.']);
|
||||
|
||||
@override
|
||||
String toString() => message;
|
||||
}
|
||||
|
||||
class ProjectService extends GetxService {
|
||||
static ProjectService get to => Get.find();
|
||||
|
||||
@@ -19,6 +28,20 @@ class ProjectService extends GetxService {
|
||||
super.onInit();
|
||||
await _loadProjects();
|
||||
await _restoreActiveProject();
|
||||
|
||||
Supabase.instance.client.auth.onAuthStateChange.listen((data) {
|
||||
final loggedOut = data.session == null;
|
||||
final active = activeProject.value;
|
||||
|
||||
if (loggedOut && active != null && !active.isLocalOnly) {
|
||||
final fallback = projects.firstWhereOrNull((p) => p.isLocalOnly);
|
||||
if (fallback != null) {
|
||||
setActiveProject(fallback);
|
||||
} else {
|
||||
activeProject.value = null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _loadProjects() async {
|
||||
@@ -44,6 +67,11 @@ class ProjectService extends GetxService {
|
||||
}
|
||||
|
||||
Future<void> setActiveProject(Project project) async {
|
||||
if (!project.isLocalOnly &&
|
||||
Supabase.instance.client.auth.currentUser == null) {
|
||||
throw ProjectRequiresLoginException();
|
||||
}
|
||||
|
||||
activeProject.value = project;
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
await prefs.setInt('active_project_id', project.id!);
|
||||
@@ -164,13 +192,18 @@ class ProjectService extends GetxService {
|
||||
/// 3. azonnali szinkron, hogy a projekt eddigi adatai lejöjjenek.
|
||||
Future<Project> joinSharedProject(Map<String, dynamic> sharedRow) async {
|
||||
final client = Supabase.instance.client;
|
||||
final user = client.auth.currentUser;
|
||||
if (user == null) {
|
||||
throw ProjectRequiresLoginException(
|
||||
'Közös projekthez csatlakozáshoz be kell jelentkezni.');
|
||||
}
|
||||
final projectUuid = sharedRow['id'] as String;
|
||||
|
||||
// 1. Tagság (idempotens: ha már tag, nem hiba).
|
||||
await client.from('terepi_seged_project_members').upsert(
|
||||
{
|
||||
'project_id': projectUuid,
|
||||
'user_id': client.auth.currentUser!.id,
|
||||
'user_id': user.id,
|
||||
'role': 'editor',
|
||||
},
|
||||
ignoreDuplicates: true,
|
||||
@@ -193,11 +226,13 @@ class ProjectService extends GetxService {
|
||||
/// a lokális adat megmarad (archiválható külön).
|
||||
Future<void> leaveSharedProject(Project project) async {
|
||||
final client = Supabase.instance.client;
|
||||
final user = client.auth.currentUser;
|
||||
if (user == null) return; // nincs bejelentkezve — nincs mit tenni
|
||||
await client
|
||||
.from('terepi_seged_project_members')
|
||||
.delete()
|
||||
.eq('project_id', project.uuid)
|
||||
.eq('user_id', client.auth.currentUser!.id);
|
||||
.eq('user_id', user.id);
|
||||
}
|
||||
|
||||
// ═════════════════════════════════════════════════════════════════
|
||||
|
||||
Reference in New Issue
Block a user