Editing my own user page in Grails - security

I'm building a web application with Grails, using the Acegi/Spring Security plugin.
I want to only show the 'Edit' link if the page is showing the details of the currently logged in user.
For example, the logged in user with id = 44 is viewing the page 'localhost:8080/app/user/show/44'
I've tried the following but it's not working. Any ideas on how to make this work, or is there some really simple way I've missed?
<g:isLoggedIn>
<g:if test="${person.id == loggedInUserInfo(field='id')}">
<g:link controller="user" action="edit" id="${person.id}">Edit</g:link>
</g:if>
</g:isLoggedIn>

i don't know if it is just a typo in this question but loggedInUserInfo should be called with a map.
you make an assignment in the method call, which results in giving just the value 'id' to loggedInUserInfo
instead of field='id' it should say field : 'id'
<g:isLoggedIn>
<g:if test="${person.id == loggedInUserInfo(field : 'id')}">
<g:link controller="user" action="edit" id="${person.id}">Edit</g:link>
</g:if>
</g:isLoggedIn>

Related

Alert in view record for Netsuite

I have been trying to get a alert in Netsuite for view mode but can't get it for customer record.
Though when I tried to get the alert for the edit record then I got it but I want it for view.
I tried client script, user event script and also workflow. But all support only for edit. Can I get the alert by any means for the view record option.
Thanks
Gladiator
One workaround that I've done is to add a custom field of type 'Inline HTML' to the customer form. Then during the beforeLoad event you can check if type == 'view' and update the custom field's value with the HTML that is needed to display the alert.
Basically form.setScript used to work with SS1 but there was no (not hacked) API access to Netsuite's alerts
SS2.0 gives nice access to the alert system but it doesn't load in view mode unless you take a supported action (clicking a button)
See this answer for a sample with SS2 that loads your script and shows an integrated alert.
SS2.0 Display Message on Record
Thanks Mike, Michoel and Bknights.
Here is the solution to the problem.
Create an inline html field on the customer form.
Since the field does not store value nlapiSetFieldValue for before load function works absolutely fine.
Below is the snippet of the working code.
function before_load(type)
{
if (type == 'view')
{
var pass_value = "<html><body><script type='text/javascript'>window.alert('Hello World!!!')</script></body></html>";
nlapiSetFieldValue("custentity25", pass_value); //custentity25 is the id of Inline HTML field we created
}
}
Note : The "" used should be different then the one used in the HTML code which is ''. If same are used then there will be an error.
You need to use a User Event Script, and in the before load event, set a Client Script via form.setScript(). In your "injected" Client Script, you can display the alert.

How to delete an item in expressJS view

I am building an ExpressJS app and want to add a delete icon on a collection to delete individual items.
I am a bit confused how to do this.
One method I thought of is binding a click event to the icon in the express view and doing an ajax call to the server when clicked.
Another method is to create a form around the icon and the icon will be a button that when clicked submits the form.
I am not confident of the two approaches, anybody have thought on an elegant way to do this the express way
i recommend the second method because it's more easy to understand at this moment.
from your words i understand the delete button could be vulnerability or security hole if you did in the wrong way. Sure it's delete button on any way.
the most easy way to do it with more secure is to use session variable.
the user can't delete unless he is authorized (logged in). if so then you open session on your server and give the user the key of that session.
In the session you can store securely data about the user who interact with the server via providing the session key you gave him at login process.
at this step the user will click the button to delete document but guess what he should be authorized to delete this document. This the time for session key he provide to you to inform you his identity. then the decision is up to you either to delete or reject his request.
all of the above word are concept of what will happen in the code.
i will write two part one part for the login controller to give the user authorization. And the second is the delete document controller.
login:
if(var user = isUser(username, password){
//open session
req.session.user_id = user._id
}
delete document controller:
if(req.session.user_id){
//if true that means he is logged in authorized user
//you can also to check by his user_id if he has the privilege to delete the document
document.delete();//in mongoose model.remove();
}
this solution is for security in deleting any document.
There are multiple ways you can achieve the result you seek.
You could use a link that has the id of the item you want to delete YourURL.com/item/delete/id and attach a click event to it. When the link is clicked your handler should be able to get the id query params and use it to make an AJAX call to the server.
Also, you can use a button like you said, which is basically the same thing as the one above
Bottom line is, both methods are pretty standard, some people could use hidden elements, HTML elements, almost anything that can store an ID or a value, but you will find that most people also use the above methods as well, Which IMHO is pretty standard.
Below is a snippet of how it should work, I am not sure if you are using any Javascript libraries so I scripted it with Vanilla Javascript, if you are not using any Javascript libraries or frameworks I strongly advice you do, it helps reduce a lot of headaches you get from browser difference in the way the handle Javascript.
PS: Include codes you have tried to help give context to how your question could be answered.
var makeDeleteCall = function(e, id) {
e.preventDefault();
console.log(id);
// Make AJAX Call here to server to delete item with the ID
//After call to remote server you can then update the DOM to remove the item
document.getElementById(id).remove();
}
<!-- Using Link -->
<a href="#/delete/1" onclick="makeDeleteCall(event, 1);" id="1">
Delete Item
</a>
<br/>
<br/>
<!-- Using a Button-->
<button onclick="makeDeleteCall(event, 2);" id="2">
Delete Button
</button>
Link to JSFiddle

Xpage edit/read mode error: The form does not contain an input: $$viewid

need some help about my xpage application not getting into read/edit mode. Here is the scenario. I created a view that contains a couple of entries in my landing page, the user clicks the link on the view and go to another page to open the document. In that page I've got set to edit, set to read mode buttons, just like the tutorial on the bootstrap4xpage. And here is where the error occur, I click the "set to edit" or "set to read" button and a pop up shows saying : " Problem submitting the page. The form does not contain an input:$$viewid" I'm new to both notes and xpage so I don't have the skills yet to identify this kind of error. Thank you in advance.
By the way I use bootstrap4xpage template.
I found that using the <form> tag of bootstrap instead of <div> tag produces this kind of error.I think there is some issue about using that tag in xpage. What it is, well, that's something I don't know. But anyhow changing my <form> tags into divs did solved the error.

Orchard Fields Validation

In Orchard 1.4.2, when fields like input field are marked as required, validation pop up appears. How is the validation happening without re-directing the user to another view?
To explain in details, If I have a form that I have attached to a page, the form field validation displays an error message ( may be it is through AJAX or javascript), but there is no re-direction to the 'form' view - it stays on that page view.
I need to add validation to another module without it re-directing to another view.
Any idea?
You can find this bit of code in the InputFieldDriver class...
if (settings.Required && string.IsNullOrWhiteSpace(field.Value)) {
updater.AddModelError(GetPrefix(field, part), T("The field {0} is mandatory.", T(field.DisplayName)));
}
Adding a model error will send the user right back to the same page.
FYI, the fields module is a sub repository located here: https://orchardfields.codeplex.com/
The class I'm talking about is right here: https://orchardfields.codeplex.com/SourceControl/changeset/view/4d125be1a6b3#Drivers%2fInputFieldDriver.cs

change layout content from controller

I am using Yii. I want to have a dynamic link on a layout. This dynamic link will be modified by controllers. Let's say that dynamic link uses a user's id given by controllers to perform a task.
I am thinking to use jQuery script to get user id returned by controllers then use the user id to modify a div that holds the dynamic link.
What do you think about this technique?
It seems like you want to dynamically change a link AFTER the page is rendered, with client-side JavaScript. But it makes more sense to dynamically render a different link the first time, during the server-size PHP rendering process. The controller generates the view, after all! I would get the user ID from the controller during the page request, pass the ID in to the view, and then build the link in the view dynamically on the initial page load.
If you are modifying a link in a layout (not a view), then the best thing to do is create a variable in the Controller, and set that variable with the view. Look at how Yii uses the $layout, $menu and $breadcrumbs variables to do this.
Assuming that the user is logged in and you want their ID, you can get the ID from the Yii::app() object as well, like so:
<?php echo CHtml::link('Edit user',array('user/edit','userId'=>Yii::app()->user->id)); ?>
But at that point, you can just request the user's ID in the controller, and don't need to build a link like this.
Assuming that you want a different user ID than the logged in user, pass that ID ($userId) from the controller into the view, and just do this (as Moyersy said):
<?php echo CHtml::link('Edit user',array('user/edit','userId'=>$userId)); ?>
This will build the following link (where $userId = 99999999):
Edit user
So when the linked is clicked, in the actionEdit() you now have access to the user's ID via the GET variable $_GET['userId'].
NOW, if what you want to do is change an already created link, then you would need to use jQuery. But you will need to explain in more detail why you are doing this and what is triggering the link change (a dropdown menu?).
I'm sorry, I can't understand what you are trying to do. Specifically I don't understand what a dynamic link is.
Edit:
<? echo CHtml::link('Edit user',array('user/edit','userId'=>$userId)); ?>

Resources