In Padrino, where does access_control come from? - sinatra

The Padrino Admin Guide (http://www.padrinorb.com/guides/padrino-admin) has the object "access_control", but it is not clear to me where it is set? I can guess, but that is not good enough. We have essentially:
class Admin < Padrino::Application
register Padrino::Admin::AccessControl
enable :authentication
set :login_page, "/admin/sessions/new"
access_control.roles_for :any do |role| #How is access_control set?
role.protect "/"
role.allow "/sessions"
end
...
I am expecting that access_control is set somewhere, but where? I am guessing that this has to do with the "register" command, but have not found any help in docs yet.
thanks for any help...

Well, little interest in this, but I needed an answer, so here is mine.
I have at the top register Padrino::Admin::AccessControl which also lists Authorization, Base, ProjectModule. I can see some of the methods used in the app from the docs:
https://www.padrinorb.com/api/Padrino/Admin/AccessControl.html
However, nothing I could see about "access_control". I finally saw in the docs something I had missed, the line:
Defined in:padrino-admin/lib/padrino-admin/access_control.rb
AhHa! That is what I needed. Github if I need to look further.

Related

Protractor Implementation in Angular2 without using ids

I have application in Angularjs2, and developers have not been using ids into it. Now I have to implement the Protractor on same application. Is there anyway to implement the Protractor without using "absolute XPath"?
Thanks in advance!
Please find a huge range of locator-possibilities on the official Protractortest API Page
Every element on a page needs to be uniquely identifiable... else the page wouldn't work, no matter which technology. Therefore with the help of any of the above provided locator-possibilities you'll always find the element you're looking for.
And there is never a need for XPath, except for this only one. (though there is an parentElementArrayFinder introduced in the meantime, so not even that one exception is valid anymore)
UDPATE
If you could use XPath, you can for sure use CSS-Locators.
Here some examples for locators:
$('div.class#id[anyAttribute="anyValue"] div.child.somewhere-below-div-point-class')
element(by.cssContainingText('div[data-index="2"]', 'select this option'))
Or as a specific example the "Learn More" of the "Tree List" section of https://js.devexpress.com/ :
treeListSection = element(by.cssContainingText('div.tab-content h2', 'Tree List')).getDriver();
learnMoreBtn = treeListSection.element(by.cssContainingText('a.tab-button','Learn More'));
learnMoreBtn.click();
Those are just examples, but there is always a way to do it.
If you provide some example-HTML in your Question, I can direct you towards a solution.
UPDATE 2
For getting the Parent Web Element, one could use getDriver() as well

SuspectScore in Email Headers

I've Googled quite a bit and cannot find a definition to tell me what this means or how I can fix it.
I'm setting up some follow up emails, using mailgun.org as my SMTP provider and in the header I'm receiving this:
X-Proofpoint-Spam-Details: rule=notspam policy=default score=0
spamscore=0 suspectscore=99 phishscore=0 adultscore=0 bulkscore=100
classifier=spam adjust=0 reason=mlx scancount=1
engine=7.0.1-1308280000 definitions=main-1310230044
All of that looks fine with the exception of suspectscore=99 I can't find a definition for this, but it can't be a good thing to be a 99% suspect.
Anyone can enlighten me or point me to an accurate definition of suspectscore?
That's a header specific to a vendor product: Proofpoint. You'll have to work with them to understand what's going on.

RESTful urls for restore operation from a trash bin

I've been implementing a RESTful web service which has these operations:
List articles:
GET /articles
Delete articles (which should remove only selected articles to a trash bin):
DELETE /articles
List articles in the trash bin:
GET /trash/articles
I have to implement an operation for restoring "articles" from "/trash/articles" back to "/articles".
And here is the question. Ho do you usually do it? What url do I have to use?
I came up to the 2 ways of doing it. The first is:
DELETE /trash/articles
But it feels strange and a user can read it like "delete it permanently, don't restore".
And the second way is
PUT /trash/articles
Which is more odd and a user will be confused what this operation does.
I'm new to REST, so please advice how you do it normally. I tried to search in google but I don't know how to ask it right, so I didn't get something useful.
Another option could be to use "query params" to define a "complementary action/verb" to cover this "special condition" you have (given that this is not very easily covered by the HTTP verbs). This then could be done for example by:
PUT /trash/articles?restore=true
This would make the URI path still complaint with REST guideline (referring to a resource, and not encoding "actions" - like "restore") and would shift the "extra semantics" of what you want to do (which is a very special situation) to the "query parameter". "Query params" are very commonly used for "filtering" resources in REST, not so much for this kind of situation... but maybe this is a reasonable assumption given your requirements.
I would recommend using
PUT /restore/articles
or
PUT /restore/trash/articles
Late answer but, in my opinion, the best way is to change the resource itself.
For instance:
<article is_in_trash="true">
<title>come title</title>
<body>the article body</body>
<date>1990-01-01</date>
</article>
So, in order to remove the article from Trash, you would simple use PUT an updated version of the article, where is_in_trash="false".

Postgres SPI cursor options: Where is a complete list? / What are the default options?

From the Postgresql documentation:
int cursorOptions
Integer bit mask of cursor options; zero produces default behavior.
What is the default behavior? Where is a complete list of cursor options? I've been looking through the documentation for an hour now. Can someone provide a link or point me in the right direction?
I am compiling a list of cursorOptions as I peel through the documentation to help save the others the trouble.
Defined in <src/include/nodes/parsenodes.h>:
CURSOR_OPT_BINARY (0x0001)
CURSOR_OPT_SCROLL (0x0002) is required by several SPI commands. Setting this option will allow for more complex movement through cursors. Further details are explained in the documentation of SPI_cursor_fetch, SPI_cursor_move, SPI_scroll_cursor_fetch, SPI_scroll_cursor_move
CURSOR_OPT_NO_SCROLL (0x0004)
CURSOR_OPT_INSENSITIVE (0x0008)
CURSOR_OPT_HOLD (0x0010) is ignored by SPI_prepare_cursor. However, it's behavior for SPI_prepare_params and SPI_cursor_open_with_args is not specified in the documentation.
CURSOR_OPT_CUSTOM_PLAN (0x0020)
CURSOR_OPT_FAST_PLAN (0x0040)
CURSOR_OPT_GENERIC_PLAN (0x0080)
NOTE: If anyone with the ability to edit posts wishes to contribute to this answer (additional options, functionality or insights), please feel free to do so. I will try to move comments up into the answer as they come.

Customize Error Reporting via E-mail in Pylons

I am sending myself WebApp error reports from Pylons when users hit critical errors and I would love to be able to get the full output of session[] in the reports and customize it to my liking, but I've got no idea how to do that, or where the report is actually created / put together.
Anyone know how I can accomplish that?
The short answer is that you will have to roll your own for this functionality. WebError is the package used to handle this, and it doesn't provide any extension points. Your best bet may be to use a fork of it with your changes, although even then the code is not pretty.
I thank Michael for answering me, without really giving me anything to build on. That meant I had to figure it out myself, and that's always a good thing :)
What I did was, I looked at /config/middleware.py in my Pylons project and found this line:
app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
I made my own ErrorHandler def and my own ErrorMiddleware class at the top of the middleware.py file:
class ClaraErrorMiddleware(ErrorMiddleware):
def exception_handler(self, exc_info, environ):
# do what ever you want with the exc_info or environ vars
super(ClaraErrorMiddleware, self).exception_handler(exc_info, environ) # call parent
pass
def ClaraErrorHandler(app, global_conf, **errorware):
if asbool(global_conf.get('debug')):
return ErrorHandler(app, global_conf, **errorware)
else:
return ClaraErrorMiddleware(app, global_conf, **errorware)
So now, I can throw in some extra variables I want to be sent with my error emails. Simple enough ...