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

Generalize form structure for permission requests #315

Open
wants to merge 50 commits into
base: master
Choose a base branch
from

Conversation

GhiaraD
Copy link
Member

@GhiaraD GhiaraD commented Oct 9, 2021

Bring the permission request form to the same structure as the class feedback form.
Additional changes:

  • fix bug where the cancel button for rewriting permission requests doesn't work;
  • fixed 'Report sent' strings in ro for app feedback ;
  • users can no longer access the page for requesting permissions if they already have permissions.

GhiaraD and others added 30 commits July 16, 2021 00:46
page reloads on button press
change how data is extracted from firebase
add revert button functionality
* reduce logic at ui level
* add 'accepted' and 'processedBy' fields for requests
* refactor and format some code for more clarity
* change date place to bottom left corner
* change 'deny' bottom colors
* add test for admin page
* reload only one card instead of all
# Conflicts:
#	pubspec.yaml
* sort request descending by date
* update pubspec.yaml
* update admin panel integration test
* resolve warnings
* delete unnecessary mocks
* fix Admin Page test
* add test for Admin Panel button
* fix typos
* reduce duplicated code
# Conflicts:
#	CONTRIBUTING.md
#	firestore.indexes.json
#	firestore.rules
…_forms

# Conflicts:
#	firestore.rules
#	lib/generated/l10n.dart
#	lib/main.dart
#	lib/pages/settings/model/request.dart
#	lib/pages/settings/service/admin_provider.dart
#	lib/pages/settings/service/request_provider.dart
#	lib/pages/settings/view/request_card.dart
#	pubspec.yaml
#	test/integration_test.dart
#	test/settings_test.dart
# Conflicts:
#	lib/main.dart
#	lib/pages/settings/view/request_card.dart
#	test/settings_test.dart
@GhiaraD GhiaraD linked an issue Oct 9, 2021 that may be closed by this pull request
@acs-upb-mobile-bot
Copy link
Member

acs-upb-mobile-bot commented Oct 9, 2021

1 Error
🚫 The pubspec.yaml file was updated, but not the version.
1 Warning
⚠️ Big PR

For more info on versioning, check out our PR guidelines.

Generated by 🚫 Danger

Fix response not appearing on cards
Format code
Copy link
Member

@IoanaAlexandru IoanaAlexandru left a comment

Choose a reason for hiding this comment

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

This is a good start, but we can make some improvements.

@@ -126,7 +126,7 @@ service cloud.firestore {
match /forms/{form=**} {
allow read: if true;
allow create: if isAuthenticated();
allow update: if isAdmin();
Copy link
Member

Choose a reason for hiding this comment

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

Could we at least have something like isAdmin() || isOwner()? Rather than let any authenticated user edit any document.

Copy link
Member Author

Choose a reason for hiding this comment

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

All requests are in the same document so everyone should be able to update, to create requests in the first place. A more thorough check is rather complicated.

@@ -303,8 +303,9 @@
"messageAlreadySeeingCurrentWeek": "Ești deja la săptămâna curentă!",
"messageAnotherQuestion": "Ai altă întrebare?",
"messageTalkToChatbot": "Vorbește cu Polly!",
"messageReportSent": "Reposrt sent successfully.",
"messageReportNotSent": "Reposrt could not be sent.",
"messageReportSent": "Răspuns trimis cu succes.",
Copy link
Member

Choose a reason for hiding this comment

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

Good catch, I actually asked Alex to fix this (#316) so you'll have to resolve some conflicts when you update your branch.

final String questionNumber;

Map<String, dynamic> toData() {
return {};
Copy link
Member

Choose a reason for hiding this comment

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

Don't leave this empty; even if we're not using it, it's a good idea to have a stub to fall back to when inheriting (e.g. if we forget to override). It should be a map with the answer & number.

@@ -82,14 +78,14 @@ class FeedbackProvider with ChangeNotifier {
}
}

Future<Map<String, FeedbackQuestion>> fetchQuestions() async {
Future<Map<String, FormQuestion>> fetchQuestions(String document) async {
Copy link
Member

Choose a reason for hiding this comment

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

WDYT about making this public, and adding two helper methods like fetchFeedbackQuestions and fetchPermissionRequestQuestions? And similar to other functions that take the document name.

The reason this would be useful is to not require the UI part to know anything about the database structure. We can just have string constants in this file with the names of the documents and use them directly, so if we at some point rename these documents we only need to change them in one place.

@@ -239,4 +237,47 @@ class FeedbackProvider with ChangeNotifier {
return null;
}
}

bool userAlreadyRequestedCache;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe move to the top of the class for consistency with other providers

'done': true,
'accepted': accepted
await _db.collection('forms').doc('permission_request_answers').update({
'$requestId.processedBy': _authProvider.uid,
Copy link
Member

Choose a reason for hiding this comment

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

Didn't know this syntax is a thing, this is pretty cool!

@@ -45,7 +50,7 @@ class _RequestPermissionsPageState extends State<RequestPermissionsPage> {
color: Theme.of(context).accentColor,
width: 130,
onTap: () async {
Navigator.of(context).pop();
await _sendRequest();
Copy link
Member

Choose a reason for hiding this comment

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

Nit: This actually doesn't only send the request, but also pops the page. It would be a bit cleaner if you made _sendRequest return a bool (true if success), and then do:

final res = await _sendRequest();
if (!res) {
  AppToast...
} else {
  AppToast...
  Navigator.pop...
}

_fetchUser();
}

Future<Map<String, dynamic>> fetchFeedbackQuestions() async {
Copy link
Member

Choose a reason for hiding this comment

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

You forgot to change the name

.fetchQuestions('permission_request_questions')
.then((questions) => setState(() => requestQuestions = questions));
for (int i = 0; i <= requestQuestions.length; i++) {
answerValues.insert(i, {
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand what this does

Copy link
Member Author

Choose a reason for hiding this comment

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

This initializes this 'andswerValues' field, which is specific to questions that require a rating. We probably won't use this type of question here though, I will delete this.

@override
Widget build(BuildContext context) {
final requestProvider = Provider.of<RequestProvider>(context);
final requestProvider = Provider.of<FeedbackProvider>(context);
Copy link
Member

Choose a reason for hiding this comment

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

This is the same code as on the feedback page, no? Why not make a reusable widget like FeedbackPage now that we have common logic?

Copy link
Member Author

Choose a reason for hiding this comment

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

It isn't really the same from what I can see. So I think it is better to keep them separated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cancel new permission request
3 participants