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

Add Endpoints for Notifications #950

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

Conversation

Santosh3007
Copy link
Contributor

Changes

Adding extra endpoints needed for notifications

Santosh3007 and others added 30 commits February 14, 2023 15:32
- Create Notifications module and NotificationType model
- Start migration for adding notifications
- No functionalities added yet only template code
Changes:
* Replaced is_enable to is_enabled for Notification Preferences
* Update default is_enabled to true for Notifcation Types
`import_config` must always appear at the bottom for environment
specific configurations to be applied correctly. All configurations
after this line will overwrite configurations that exists in the
environment specific ones.
- remove auto-generated controllers and views that are not used
If user preference has no time option, use the time_option from
notification_config instead. This is so that the behaviour of these
users with no preferences would always follow the default chosen by the
course admin
Junyi00 and others added 8 commits April 4, 2023 16:42
* Query returns an array of preferences per config due to LEFT OUTER
  JOIN, the change ensures either nil or the first preference is
  returned
* It is guaranteed there is maximally one preference in the array due to
  the unique constraint in the new migration
- Add put upsert time options endpoints
- Fix changeset issues with upsert noti config endpoints
@coveralls
Copy link

coveralls commented Jun 14, 2023

Coverage Status

coverage: 94.693% (-0.7%) from 95.358% when pulling 39fe3cb on Santosh3007:add-notifications-endpoints into 5d09b51 on source-academy:master.

@Santosh3007 Santosh3007 marked this pull request as ready for review June 18, 2023 18:51
@Santosh3007 Santosh3007 marked this pull request as draft June 18, 2023 19:11
@Santosh3007 Santosh3007 marked this pull request as ready for review June 18, 2023 23:35
Copy link
Contributor

@YaleChen299 YaleChen299 left a comment

Choose a reason for hiding this comment

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

Thanks for the quick work! However, I think the design needs major changes.

First of all, try to follow the current routing scopes, if a notification belongs to a course, semantically it should be under /course. In that way, you will naturally pipe through authentication checks, course checks sand staff checks.

Second, please separate admin routes from student routes (or do you want to separate them from staff also?). Do think about the privilege of each route. The backend needs to be intact without the assumption of the well-behaviour of the frontend.

Lastly, please clean up unnecessary comments and use query styles in the piping fashion(which aligns with the current code base). Try to use Logger instead of IO for logging.

@@ -169,6 +169,19 @@ defmodule CadetWeb.Router do
)
end

# Notifications endpoints
Copy link
Contributor

Choose a reason for hiding this comment

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

How are these APIs being called from the frontend? Why are they not piped through authentication and course-specific assignment? I am not sure what might happen here. If some request is fired from a student that already has his log in session expired or if the student changed course(which might lead to some cache issue or privilege issue)...

Copy link
Contributor

Choose a reason for hiding this comment

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

Also please separate the admin routes from the student routes

Copy link
Contributor

Choose a reason for hiding this comment

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

This could be potentially very dangerous as some students may edit the configs that only admins can edit. We should not assume that the frontend will behave as expected.

Copy link
Contributor

Choose a reason for hiding this comment

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

or is there any justification that these APIs do not need any authentication at all?

if length(ungraded_submissions) < ungraded_threshold do
IO.puts("[AVENGER_BACKLOG] below threshold!")
else
IO.puts("[AVENGER_BACKLOG] SENDING_OUT")
Copy link
Contributor

Choose a reason for hiding this comment

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

is a logger better here?

query =
from(n in Cadet.Notifications.NotificationConfig,
where: n.course_id == ^course_id
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is the query here in a different style?

ntype.for_staff == ^is_staff and
n.course_id == ^cr.course_id and
(p.course_reg_id == ^cr.id or is_nil(p.course_reg_id))
)
Copy link
Contributor

Choose a reason for hiding this comment

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

A different style of query. Please stick to piping. |>

# end

# case Repo.delete(time_option) do
# JUNYI AND SANTOSH: NOT DEFINED???
Copy link
Contributor

Choose a reason for hiding this comment

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

please clean up unused comments as well.

@YaleChen299
Copy link
Contributor

This PR is superseded by #973. Hence, this will be closed when #973 is merged.

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.

None yet

6 participants