-
Notifications
You must be signed in to change notification settings - Fork 86
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
Switch OrganizationGithubAppInstallationController away from ja_resource and canary #893
Milestone
Comments
begedin
added this to the Move away from ja_resource and canary in controllers milestone
Sep 4, 2017
Closed
treble37
added a commit
to treble37/code-corps-api
that referenced
this issue
Sep 10, 2017
Switch OrganizationGithubAppInstallationController away from ja_resource and canary Closes code-corps#893
treble37
added a commit
to treble37/code-corps-api
that referenced
this issue
Sep 17, 2017
Switch OrganizationGithubAppInstallationController away from ja_resource and canary Closes code-corps#893
treble37
added a commit
to treble37/code-corps-api
that referenced
this issue
Sep 18, 2017
Switch OrganizationGithubAppInstallationController away from ja_resource and canary Closes code-corps#893
treble37
added a commit
to treble37/code-corps-api
that referenced
this issue
Sep 18, 2017
Switch OrganizationGithubAppInstallationController away from ja_resource and canary Closes code-corps#893
treble37
added a commit
to treble37/code-corps-api
that referenced
this issue
Sep 18, 2017
Switch OrganizationGithubAppInstallationController away from ja_resource and canary Closes code-corps#893
treble37
added a commit
to treble37/code-corps-api
that referenced
this issue
Sep 18, 2017
Switch OrganizationGithubAppInstallationController away from ja_resource and canary Closes code-corps#893
treble37
added a commit
to treble37/code-corps-api
that referenced
this issue
Sep 18, 2017
Switch OrganizationGithubAppInstallationController away from ja_resource and canary Closes code-corps#893
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Progress on #864
Problem
We want to move away from the
ja_resource
andcanary
combo used in most of our controller modules. The central issue for this project is #864There is a generic process of how to do it in that issue, as well as tracking for the milestone progress.
The procedure is also pasted below. If this specific controller deviates from this standard procedure, feel free to ask for help here, or by opening a PR.
The PR should indicate that it's closing this issue and is progressing #864 further along.
Procedure
lib/code_corps_web/router.ex
action_fallback CodeCorpsWeb.FallbackController
. This makes it so in case a with clause within the controller action fails, a sort of "catch all" function will be called fromFallbackController
plug CodeCorpsWeb.Plug.DataToAttributes
. This converts thedata
hash within the conn params from the json api structure into a flat map convenient for usage with changesetsload_resource
,load_and_authorize_resource
, etc. plugs in that controllerdef handle_#{action}
functionsdef #{action}(conn, params) do
. For the standardcreate
,update
delete
,show
and index actions. See examples below on how these functions should be written, usuallyThat should be the whole procedure. We already have controller tests in place, so if the process has been done correctly, the tests should pass.
Some additional steps might be necessary, however, if there are some specifics to an action. For those, we will be here to provide feedback.
How to rewrite controller actions
So to recap, the actions work like
index
actionshow
actioncreate
action{:ok, :authorized}
update
anddelete
actions{:ok, :authorized}
Examples in code
-
CodeCorpsWeb.CommentController
has examples for standardindex
,show
,create
andupdate
actionsHow to rewrite policies
This consists of several relatively simple steps.
For each action being switch away, we need to move the
def can
function clause out of thedefimpl
block inpolicy.ex
into the root namespace of theCodeCorps.Policy
module.We also need to make the clause private instead of public.
If any of the clauses expect a changeset, they should now expect a simple map of params:
becomes
changeset.changes
map, the rewrite ought to be simpler. If there is trouble, someone will be available to provide pointers.Examples in code
Policy.Comment.create?
The text was updated successfully, but these errors were encountered: