Skip to content

Commit

Permalink
Merge branch 'develop' into ui/exam_card
Browse files Browse the repository at this point in the history
  • Loading branch information
thePeras authored Oct 2, 2024
2 parents 8a9b185 + d3b0323 commit 17db031
Show file tree
Hide file tree
Showing 141 changed files with 2,262 additions and 2,260 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ jobs:
flutter build appbundle
- name: Upload App Bundle
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: appbundle
if-no-files-found: error
Expand All @@ -147,7 +147,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Get App Bundle
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: appbundle

Expand Down
2 changes: 1 addition & 1 deletion packages/uni_app/app_version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.9.0-beta.24+287
1.10.0-beta.14+314
2 changes: 1 addition & 1 deletion packages/uni_app/ios/Flutter/AppFrameworkInfo.plist
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>11.0</string>
<string>12.0</string>
</dict>
</plist>
2 changes: 1 addition & 1 deletion packages/uni_app/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
end
2 changes: 1 addition & 1 deletion packages/uni_app/ios/Runner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
97C146E61CF9000F007C117D /* Project object */ = {
isa = PBXProject;
attributes = {
LastUpgradeCheck = 1430;
LastUpgradeCheck = 1510;
ORGANIZATIONNAME = "";
TargetAttributes = {
378A17102ACF02E100B89C1C = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1510"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
34 changes: 34 additions & 0 deletions packages/uni_app/lib/app_links/uni_app_links.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'dart:async';

import 'package:app_links/app_links.dart';
import 'package:uni/utils/uri.dart';

final _authUri = Uri(scheme: 'pt.up.fe.ni.uni', host: 'auth');

class UniAppLinks {
final login = _AuthenticationAppLink(
redirectUri: _authUri.replace(path: '/login'),
);

final logout = _AuthenticationAppLink(
redirectUri: _authUri.replace(path: '/logout'),
);
}

class _AuthenticationAppLink {
_AuthenticationAppLink({required this.redirectUri});

final AppLinks _appLinks = AppLinks();
final Uri redirectUri;

Future<Uri> intercept(
FutureOr<void> Function(Uri redirectUri) callback,
) async {
final interceptedUri = _appLinks.uriLinkStream
.firstWhere((uri) => redirectUri == uri.stripQueryComponent());

await callback(redirectUri);
final data = await interceptedUri;
return data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import 'package:tuple/tuple.dart';
import 'package:uni/controller/background_workers/notifications/tuition_notification.dart';
import 'package:uni/controller/local_storage/notification_timeout_storage.dart';
import 'package:uni/controller/local_storage/preferences_controller.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/session/flows/base/session.dart';
import 'package:workmanager/workmanager.dart';

///
Expand Down Expand Up @@ -143,44 +142,14 @@ class NotificationManager {

static Future<void> updateAndTriggerNotifications() async {
PreferencesController.prefs = await SharedPreferences.getInstance();
final userInfo = await PreferencesController.getPersistentUserInfo();
final faculties = PreferencesController.getUserFaculties();
final refreshToken = await PreferencesController.getSessionRefreshToken();
final savedSession = await PreferencesController.getSavedSession();

if (faculties.isEmpty) {
if (savedSession == null) {
return;
}
if (userInfo == null && refreshToken == null) {
return; // Session not persistent
}

Session? session;
if (userInfo != null) {
session = await NetworkRouter.login(
userInfo.item1,
userInfo.item2,
faculties,
persistentSession: false,
);
}

if (refreshToken != null) {
final token = await NetworkRouter.getAccessToken(refreshToken);
final studentNumber = await PreferencesController.getUserNumber();
if (token == null || studentNumber == null) {
return;
}
session = await NetworkRouter.loginWithToken(
token,
studentNumber,
faculties,
persistentSession: false,
);
}

if (session == null) {
return;
}
final request = savedSession.createRefreshRequest();
final session = await request.perform();

// Get the .json file that contains the last time that the
// notification has ran
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:uni/controller/background_workers/notifications.dart';
import 'package:uni/controller/fetchers/fees_fetcher.dart';
import 'package:uni/controller/local_storage/preferences_controller.dart';
import 'package:uni/controller/parsers/parser_fees.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/session/flows/base/session.dart';
import 'package:uni/utils/duration_string_formatter.dart';

class TuitionNotification extends Notification {
Expand Down
6 changes: 1 addition & 5 deletions packages/uni_app/lib/controller/cleanup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,12 @@ import 'package:uni/controller/local_storage/database/app_last_user_info_update_
import 'package:uni/controller/local_storage/database/app_lectures_database.dart';
import 'package:uni/controller/local_storage/database/app_user_database.dart';
import 'package:uni/controller/local_storage/preferences_controller.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/model/providers/state_providers.dart';

Future<void> cleanupStoredData(BuildContext context) async {
StateProviders.fromContext(context).invalidate();

final prefs = await SharedPreferences.getInstance();
final faculties = PreferencesController.getUserFaculties();
await prefs.clear();

await Future.wait([
Expand All @@ -31,9 +29,7 @@ Future<void> cleanupStoredData(BuildContext context) async {
AppLastUserInfoUpdateDatabase().deleteLastUpdate(),
AppBusStopDatabase().deleteBusStops(),
AppCourseUnitsDatabase().deleteCourseUnits(),
NetworkRouter.killSigarraAuthentication(faculties),
PreferencesController.removePersistentUserInfo(),
PreferencesController.removeSessionRefreshToken(),
PreferencesController.removeSavedSession(),
]);

final toCleanDirectory = await getApplicationDocumentsDirectory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:uni/controller/fetchers/session_dependant_fetcher.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/controller/parsers/parser_calendar.dart';
import 'package:uni/model/entities/calendar_event.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/session/flows/base/session.dart';

/// Fetch the school calendar from HTML
class CalendarFetcherHtml implements SessionDependantFetcher {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/controller/parsers/parser_course_units.dart';
import 'package:uni/model/entities/course.dart';
import 'package:uni/model/entities/course_units/course_unit.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/session/flows/base/session.dart';

class AllCourseUnitsFetcher {
Future<List<CourseUnit>?> getAllCourseUnitsAndCourseAverages(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:uni/model/entities/course_units/course_unit_class.dart';
import 'package:uni/model/entities/course_units/course_unit_directory.dart';
import 'package:uni/model/entities/course_units/course_unit_sheet.dart';
import 'package:uni/model/entities/course_units/sheet.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/session/flows/base/session.dart';

class CourseUnitsInfoFetcher implements SessionDependantFetcher {
@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'dart:convert';
import 'package:uni/controller/fetchers/session_dependant_fetcher.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/model/entities/course_units/course_unit.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/session/flows/base/session.dart';

class CurrentCourseUnitsFetcher implements SessionDependantFetcher {
@override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import 'package:http/http.dart';
import 'package:uni/controller/fetchers/session_dependant_fetcher.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/model/entities/course_units/course_unit.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/session/flows/base/session.dart';

/// Returns the user's current list of [CourseUnit].
class CoursesFetcher implements SessionDependantFetcher {
Expand Down
2 changes: 1 addition & 1 deletion packages/uni_app/lib/controller/fetchers/exam_fetcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:uni/controller/parsers/parser_exams.dart';
import 'package:uni/model/entities/course.dart';
import 'package:uni/model/entities/course_units/course_unit.dart';
import 'package:uni/model/entities/exam.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/session/flows/base/session.dart';

class ExamFetcher implements SessionDependantFetcher {
ExamFetcher(this.courses, this.userUcs);
Expand Down
19 changes: 12 additions & 7 deletions packages/uni_app/lib/controller/fetchers/faculties_fetcher.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
import 'package:html/parser.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/model/entities/session.dart';
import 'package:http/http.dart' as http;
import 'package:uni/http/client/cookie.dart';
import 'package:uni/session/flows/base/session.dart';

Future<List<String>> getStudentFaculties(Session session) async {
final response = await NetworkRouter.getWithCookies(
'https://sigarra.up.pt/up/pt/vld_entidades_geral.entidade_pagina',
{'pct_codigo': session.username},
session,
Future<List<String>> getStudentFaculties(
Session session,
http.Client httpClient,
) async {
final client = CookieClient(httpClient, cookies: () => session.cookies);

final response = await client.get(
Uri.parse('https://sigarra.up.pt/up/pt/vld_entidades_geral.entidade_pagina')
.replace(queryParameters: {'pct_codigo': session.username}),
);

final document = parse(response.body);
Expand Down
2 changes: 1 addition & 1 deletion packages/uni_app/lib/controller/fetchers/fees_fetcher.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:http/http.dart';
import 'package:uni/controller/fetchers/session_dependant_fetcher.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/session/flows/base/session.dart';

class FeesFetcher implements SessionDependantFetcher {
@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,60 @@
import 'package:uni/controller/fetchers/session_dependant_fetcher.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/controller/parsers/parser_library_occupation.dart';
import 'dart:convert';

import 'package:collection/collection.dart';
import 'package:http/http.dart' as http;
import 'package:http/http.dart';
import 'package:tuple/tuple.dart';
import 'package:uni/model/entities/library_occupation.dart';
import 'package:uni/model/entities/session.dart';

/// Fetch the library occupation from Google Sheets
class LibraryOccupationFetcherSheets implements SessionDependantFetcher {
@override
List<String> getEndpoints(Session session) {
const baseUrl = 'https://docs.google.com/spreadsheets/d/';
const sheetId = '1gZRbEX4y8vNW7vrl15FCdAQ3pVNRJw_uRZtVL6ORP0g';
const url =
'$baseUrl$sheetId/gviz/tq?tqx=out:json&sheet=MANUAL&range=C2:E7&tq=SELECT+C,E';
return [url];
class LibraryOccupationFetcher {
String baseUrl = 'https://webapi.affluences.com/api/fillRate?';

static const List<Tuple2<String, int>> floorMaxSeats = [
Tuple2('BruV6IlujdwAe1', 72),
Tuple2('cEhyzJZvC5nHSr', 114),
Tuple2('iceVfgwZWaZRhV', 114),
Tuple2('1yLPz9X0CNsg27', 114),
Tuple2('keu1j5zERlQn90', 40),
Tuple2('bY7K1v43HiAq55', 90),
];

Future<LibraryOccupation> getLibraryOccupation() async {
final libraryOccupation = LibraryOccupation(0, 0);

await Future.wait(
floorMaxSeats.mapIndexed((i, entry) async {
final url = Uri.parse(baseUrl).replace(
queryParameters: {
'token': entry.item1,
},
);

final response = await http.get(url);

final floorOccupation =
processFloorOccupation(response, entry.item2, i);

libraryOccupation.addFloor(floorOccupation);
}),
);

return libraryOccupation;
}

Future<LibraryOccupation> getLibraryOccupationFromSheets(
Session session,
) async {
final url = getEndpoints(session)[0];
final response = NetworkRouter.getWithCookies(url, {}, session);
final occupation = await response.then(parseLibraryOccupationFromSheets);
return occupation;
FloorOccupation processFloorOccupation(
Response response,
int floorCapacity,
int floor,
) {
final responseBody = jsonDecode(response.body) as Map<String, dynamic>;

final floorOccupation = responseBody['progress'] as int? ?? 0;

return FloorOccupation(
floor + 1,
(floorOccupation * floorCapacity / 100).round(),
floorCapacity,
);
}
}
4 changes: 2 additions & 2 deletions packages/uni_app/lib/controller/fetchers/print_fetcher.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:http/http.dart' as http;
import 'package:uni/controller/fetchers/session_dependant_fetcher.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/session/flows/base/session.dart';

class PrintFetcher implements SessionDependantFetcher {
@override
Expand Down Expand Up @@ -36,7 +36,7 @@ class PrintFetcher implements SessionDependantFetcher {
};

final headers = <String, String>{};
headers['cookie'] = session.cookies;
headers['cookie'] = session.cookies.join('; ');
headers['content-type'] = 'application/x-www-form-urlencoded';

final response = await http.post(url.toUri(), headers: headers, body: data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:uni/controller/fetchers/session_dependant_fetcher.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/controller/parsers/parser_courses.dart';
import 'package:uni/model/entities/profile.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/session/flows/base/session.dart';

class ProfileFetcher implements SessionDependantFetcher {
@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:http/http.dart';
import 'package:uni/controller/fetchers/session_dependant_fetcher.dart';
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/session/flows/base/session.dart';

class ReferenceFetcher implements SessionDependantFetcher {
@override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:uni/controller/networking/network_router.dart';
import 'package:uni/controller/parsers/parser_restaurants.dart';
import 'package:uni/model/entities/restaurant.dart';
import 'package:uni/model/entities/session.dart';
import 'package:uni/session/flows/base/session.dart';

/// Class for fetching the menu
class RestaurantFetcher {
Expand Down
Loading

0 comments on commit 17db031

Please sign in to comment.