forked from Submitty/Submitty
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial notification settings (Submitty#3133)
* first changes * db * Notification settings * Fix merge to all * tweaks * all_threads * tweak db * Fix query * tweaks * Fixes * Migration tweaks for fix on rollback * Fix dupes * Fix user unit * type * Fix array * Fix announcements * tweaks * move sql * remove log * remove imports.. * reword * reword more * typos * spelling * rephrase * more spelling challenges * fix spacing * fix if spacing
- Loading branch information
1 parent
cfb7dfd
commit 5bd0951
Showing
19 changed files
with
345 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
migration/migrations/course/20181028001826_simplify_gradeable_view.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
migration/migrations/course/20181116052235_notification_settings.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
def up(config, conn, semester, course): | ||
with conn.cursor() as cursor: | ||
cursor.execute("""CREATE TABLE IF NOT EXISTS notification_settings ( | ||
user_id character varying NOT NULL, | ||
merge_threads BOOLEAN DEFAULT FALSE NOT NULL, | ||
all_new_threads BOOLEAN DEFAULT FALSE NOT NULL, | ||
all_new_posts BOOLEAN DEFAULT FALSE NOT NULL, | ||
all_modifications_forum BOOLEAN DEFAULT FALSE NOT NULL, | ||
reply_in_post_thread BOOLEAN DEFAULT FALSE NOT NULL);""") | ||
cursor.execute("ALTER TABLE ONLY notification_settings DROP CONSTRAINT IF EXISTS notification_settings_pkey;") | ||
cursor.execute("ALTER TABLE ONLY notification_settings DROP CONSTRAINT IF EXISTS notification_settings_fkey;") | ||
cursor.execute("ALTER TABLE ONLY notification_settings ADD CONSTRAINT notification_settings_pkey PRIMARY KEY (user_id);") | ||
cursor.execute("ALTER TABLE ONLY notification_settings ADD CONSTRAINT notification_settings_fkey FOREIGN KEY (user_id) REFERENCES users(user_id) ON UPDATE CASCADE;") | ||
cursor.execute("INSERT INTO notification_settings SELECT user_id from users ON CONFLICT DO NOTHING") | ||
|
||
def down(config, conn, semester, course): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?php | ||
|
||
namespace app\controllers; | ||
|
||
use app\libraries\Core; | ||
use app\models\Notification; | ||
use app\controllers\AbstractController; | ||
use app\libraries\Output; | ||
|
||
/** | ||
* Class NotificationSettings | ||
* | ||
*/ | ||
class NotificationSettings extends AbstractController { | ||
|
||
const NOTIFICATION_SELECTIONS = ['merge_threads', 'all_new_threads', 'all_new_posts', 'all_modifications_forum', 'reply_in_post_thread']; | ||
const NUM = 5; | ||
|
||
public function __construct(Core $core) { | ||
parent::__construct($core); | ||
} | ||
|
||
public function run() { | ||
switch ($_REQUEST['page']) { | ||
case 'alter_notifcation_settings': | ||
$this->changeSettings(); | ||
break; | ||
} | ||
} | ||
|
||
public function changeSettings() { | ||
//Change settings for the current user... | ||
$new_settings = $_POST; | ||
$result = ['error' => 'Notification settings could not be saved. Please try again.']; | ||
if($this->validateNotificationSettings(array_keys($new_settings))) { | ||
$values_not_sent = array_diff(self::NOTIFICATION_SELECTIONS, array_keys($new_settings)); | ||
foreach(array_values($values_not_sent) as $value) { | ||
$new_settings[$value] = 'false'; | ||
} | ||
$this->core->getQueries()->updateNotificationSettings($new_settings); | ||
$result = ['success' => 'Notification settings have been saved.']; | ||
} | ||
$this->core->getOutput()->renderJson($result); | ||
return $this->core->getOutput()->getOutput(); | ||
} | ||
|
||
private function validateNotificationSettings($columns) { | ||
if(count($columns) <= self::NUM && count(array_intersect($columns, self::NOTIFICATION_SELECTIONS)) == count($columns)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.