Skip to content

Conversation

@indocomsoft
Copy link
Member

Not sure whether I am doing it the right way, do give me feedback on how to correctly do this.

@indocomsoft indocomsoft requested a review from evansb April 14, 2018 06:40
@evansb evansb changed the title Add admin interface Scaffold Admin Interface Apr 14, 2018
@@ -0,0 +1,17 @@
defmodule CadetWeb.AdminControllerTest do
Copy link
Contributor

Choose a reason for hiding this comment

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

Please implement the test. I just fixed Coveralls

@@ -0,0 +1,22 @@
defmodule CadetWeb.Plug.CheckAdmin do
@moduledoc """
A plug that checks whether :current_user is an admin
Copy link
Contributor

Choose a reason for hiding this comment

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

A plug is redundant, we know it's a Plug from the module name

Copy link
Contributor

Choose a reason for hiding this comment

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

A more detailed (but not too verbose) explanation will do, e.g what happens if user is not admin?

def init(opts), do: opts

def call(conn, _) do
if conn.assigns[:current_user] != nil && conn.assigns[:current_user].role == :admin do
Copy link
Contributor

Choose a reason for hiding this comment

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

You can make an assumption that this Plug will be run after user is authenticated, otherwise it's programmer's error. assert is good for this.

@coveralls
Copy link

coveralls commented Apr 17, 2018

Pull Request Test Coverage Report for Build 35

  • 11 of 11 (100.0%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 96.471%

Totals Coverage Status
Change from base Build 30: 0.2%
Covered Lines: 164
Relevant Lines: 170

💛 - Coveralls

@indocomsoft
Copy link
Member Author

All changes done.

@@ -0,0 +1,21 @@
defmodule CadetWeb.Plug.CheckAdmin do
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, can you rename this to EnsureAdmin? this is to be consistent with Guardian's EnsureAuthenticated

def init(opts), do: opts

def call(conn, _) do
if conn.assigns[:current_user].role == :admin do
Copy link
Contributor

Choose a reason for hiding this comment

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

Also I just realised this is wrong, the admin interface is meant to be opened by both Admin and Staff. So EnsureStaff will do

CheckAdmin.init(%{})
# nothing to test
end

Copy link
Contributor

Choose a reason for hiding this comment

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

You also need to test for :admin and :staff right?

@evansb evansb changed the title Scaffold Admin Interface Scaffold Staff Interface Apr 18, 2018
@indocomsoft
Copy link
Member Author

Instead I refactored them into EnsureRoles plug, I think this would be more versatile.

As for the test for when authenticated as admin and staff, the plug is supposed to 'do nothing', so I just refute conn.status (when there is no response yet, conn.status should be nil )

@indocomsoft
Copy link
Member Author

Responsibility handed over to frontend team @ningyuansg and @remo5000 in repo https://github.com/source-academy/cadet-frontend. Closing this.

@indocomsoft indocomsoft deleted the admin-interface branch May 19, 2018 02:31
@ning-y
Copy link
Member

ning-y commented May 19, 2018

@indocomsoft gotcha fam

angelsl pushed a commit that referenced this pull request May 22, 2020
Merges #581

Squashed commit of the following:

commit 03fb0c4753b2a10fc34d5861caa9b18ed8e60723
Author: angelsl <angelsl@in04.sg>
Date:   Sat May 23 01:13:35 2020 +0800

    Fix formatting and Credo lints

commit 2f346227ea19ef15012fcd39b99f773b4fdbce0b
Merge: a46af78 0593ca9
Author: angelsl <angelsl@in04.sg>
Date:   Sat May 23 01:09:30 2020 +0800

    Merge branch 'sa_2021' into rebase

commit a46af78
Author: Yuc Sun <sunyuchengsyc@163.com>
Date:   Wed Apr 29 20:00:49 2020 +0800

    modified positioning of test cases

commit f2e3b3f
Author: Yuc Sun <sunyuchengsyc@163.com>
Date:   Wed Apr 29 19:46:42 2020 +0800

    fix issues proposed

commit b71612a
Author: Yuc Sun <sunyuchengsyc@163.com>
Date:   Wed Apr 29 19:44:01 2020 +0800

    fix issues proposed by reviewer

commit 1525c25
Author: Yuc Sun <sunyuchengsyc@163.com>
Date:   Thu Apr 23 19:54:21 2020 +0800

    Some format change to adhere to backend style

commit 9e7f141
Author: Yuc Sun <sunyuchengsyc@163.com>
Date:   Thu Apr 23 19:15:20 2020 +0800

    Modified Module Name

commit c34784c
Merge: 0d59384 6597a3e
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 23 00:32:58 2020 +0800

    Merge pull request #2 from Source-Academy-Game/mergeGroundControl

    Merge ground control with our Collectibles System.

commit 0d59384
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 23 00:29:16 2020 +0800

    Added tests on collectible system

commit cca29ea
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 23 00:26:32 2020 +0800

    Eliminated one compile warning

commit 3ff9e52
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Wed Apr 22 18:11:28 2020 +0800

    Minor change to user.ex

    This change is to fit the testing format.

commit a47cbab
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Wed Apr 22 18:09:24 2020 +0800

    Update accounts_test.exs

    Modified this to fit our collectible system.

commit 45448ba
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Wed Apr 22 18:07:27 2020 +0800

    Modified user_controller_test.exs

    Modified this to fit collectible system.

commit 6597a3e
Author: travisryte <thuyaoo200@gmail.com>
Date:   Wed Apr 22 05:21:32 2020 +0800

    Ran Mix Format

commit 0a4cdb3
Merge: 3c3c780 ae7beac
Author: travisryte <thuyaoo200@gmail.com>
Date:   Tue Apr 21 22:45:12 2020 +0800

    Merge branch 'ground_control' into mergeGroundControl

commit ae7beac
Author: ScrubWzz <wongzhengzhi@gmail.com>
Date:   Mon Apr 20 18:33:39 2020 +0800

    Updated AssessmentOverview schema

commit 5d4e6d8
Author: ScrubWzz <wongzhengzhi@gmail.com>
Date:   Mon Apr 20 14:11:52 2020 +0800

    Minor formatting change

commit c7f01c2
Author: ScrubWzz <wongzhengzhi@gmail.com>
Date:   Mon Apr 20 13:48:59 2020 +0800

    Changed assessment deletion such that associated submissions are also deleted

commit 159a2d3
Author: ScrubWzz <wongzhengzhi@gmail.com>
Date:   Mon Apr 20 13:39:55 2020 +0800

    Updated XML parsers tests

commit 7663bf2
Author: ScrubWzz <wongzhengzhi@gmail.com>
Date:   Mon Apr 20 02:26:25 2020 +0800

    Modified AssessmentsController tests to fit with changes to how the is_published parameter is now handled

commit 1a07757
Author: ScrubWzz <wongzhengzhi@gmail.com>
Date:   Sun Apr 19 22:22:55 2020 +0800

    Fixed format

commit b39ad61
Author: ScrubWzz <wongzhengzhi@gmail.com>
Date:   Sun Apr 19 22:15:26 2020 +0800

    Added swagger paths

commit 3c3c780
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 16 11:44:32 2020 +0800

    Add function to differentiate students from others

commit 3ca9dc6
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 16 11:23:20 2020 +0800

    Added status codes information

commit 3d5e37d
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 16 11:19:56 2020 +0800

    Added status codes information

commit efbc305
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 16 11:19:24 2020 +0800

    Update game_states.ex

commit 0f59ab0
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 16 03:44:25 2020 +0800

    Solved no status codes error

commit 34c4567
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 16 03:43:00 2020 +0800

    Fixed no status codes error

    Also, satisfied frontend's need to make gameStates an object to input. Maintained consistency with other parts of the backend.

commit 8c956cf
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 16 02:55:42 2020 +0800

    Update user_view.ex

commit 53141ea
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 16 02:52:51 2020 +0800

    Add files via upload

commit 9d482c1
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 16 02:52:17 2020 +0800

    Delete add_game_states

commit 72d9744
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 16 02:45:56 2020 +0800

    Delete 20200402094115_add_user_game_states.exs

commit e3eddd6
Author: ScrubWzz <wongzhengzhi@gmail.com>
Date:   Wed Apr 15 20:50:49 2020 +0800

    Fixed bug when force updating assessments that are not opened. Added requirement that all question types remain the same when force updating

commit c0c73c9
Author: ScrubWzz <wongzhengzhi@gmail.com>
Date:   Wed Apr 15 18:13:17 2020 +0800

    Changed variable naming

commit 4ca0ffb
Merge: fbdf592 8654b13
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Mon Apr 13 21:14:49 2020 +0800

    Merge branch 'sa_2021' into master

commit fbdf592
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Apr 10 17:15:53 2020 +0800

    Update user_controller.ex

commit 71f1ac9
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Apr 10 17:07:44 2020 +0800

    fixed a consistency problem

commit 3f2bcb3
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Apr 10 16:06:57 2020 +0800

    Update game_states.ex

commit 6b42190
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Apr 10 16:06:07 2020 +0800

    Update user_controller.ex

commit 39791c3
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Apr 10 16:05:33 2020 +0800

    Update router.ex

commit ac472d3
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Apr 10 16:05:02 2020 +0800

    Create add_game_states

commit 2053868
Author: travisryte <thuyaoo200@gmail.com>
Date:   Thu Apr 2 01:52:01 2020 +0800

    Update to allow for xml files

commit 26ac37c
Author: jiachen <jiachen247@users.noreply.github.com>
Date:   Wed Jan 29 22:07:49 2020 +0800

    Update README.md (#570)

commit 5bb40e9
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Apr 10 13:53:39 2020 +0800

    Added some functios regarding game states.

commit 14f5025
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Apr 10 13:51:41 2020 +0800

    Added some routes regarding game states.

commit 0218305
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Apr 10 13:50:49 2020 +0800

    Added few functions regarding game data

commit 5a865d9
Author: ScrubWzz <wongzhengzhi@gmail.com>
Date:   Tue Apr 7 21:47:10 2020 +0800

    Minor edit

commit 431a058
Author: ScrubWzz <wongzhengzhi@gmail.com>
Date:   Mon Apr 6 21:22:00 2020 +0800

    Added GroundControl

commit 210cff6
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 2 20:54:04 2020 +0800

    make changes to model the behavior of game_states

    changed from the previous collectibles version to game_states version. add a few to-dos for futrue implementation of save_data related functions. Also noted that the error handling part is not implemented yet, which is also a to-do.

commit e92b5c0
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 2 20:51:13 2020 +0800

    added one line to be consistent with migration

commit 9635a2b
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 2 20:49:32 2020 +0800

    updated to game_states version

    Updated to game_states version and added some to-dos for the save_data part

commit 18375b5
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 2 20:47:58 2020 +0800

    changed some post actions to put actions

commit 16323c9
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 2 20:46:32 2020 +0800

    added trivial change to maitain consitency

commit d052ce4
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 2 20:45:00 2020 +0800

    Delete original collectibles.

commit 709e02a
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Thu Apr 2 20:44:08 2020 +0800

    Add a game_states column to the database.

commit d2fc579
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Mon Mar 30 20:40:03 2020 +0800

    Update collectibles.ex

commit b22dc98
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Sun Mar 29 19:44:32 2020 +0800

    Update user_controller.ex

commit bcf34a9
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Sun Mar 29 19:42:32 2020 +0800

    Update router.ex

commit 517dca7
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Sun Mar 29 19:41:21 2020 +0800

    Update collectibles.ex

commit 495a915
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Mar 27 14:48:37 2020 +0800

    Create collectibles.ex

commit bed98a9
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Mar 27 14:46:59 2020 +0800

    Update user_view.ex

commit faca0ca
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Mar 27 14:46:01 2020 +0800

    Update router.ex

commit 2acbf8a
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Mar 27 14:44:52 2020 +0800

    Update user_controller.ex

commit 82605a9
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Mar 27 14:43:53 2020 +0800

    Add files via upload

commit 9c9702c
Author: Cheng20010201 <53768585+Cheng20010201@users.noreply.github.com>
Date:   Fri Mar 27 14:42:16 2020 +0800

    Update user.ex
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.

4 participants