Permission per user/page
#1
Posted 08 May 2012 - 05:01 AM
I've been trying to put together the bits I found on the forums about permissions/users/ login etc but still can figure it out.
I want to have a simple Network application that will list the students from a certain University involved in some common projects.
Projects:
-Project1
--Student1
--Student2
--StudentX
-Project2
--Student3
--Student4
--StudentY
StudentX is a page where UserX can write updates for his assignment. How can I create permissions for UserX to be able to edit only his page, StudentX. StudentX can't edit/create any other page.
If you can point me into the right direction I'd really appreciated.
Norboo
#2
Posted 08 May 2012 - 07:07 AM
This will happen in the backend or frontend?StudentX is a page where UserX can write updates for his assignment.
edit: I think I can deduce from your other post that you want to do it on the backend
#3
Posted 08 May 2012 - 08:04 AM
I don't really know. Which way will be better?
Probably backend, because I'll not have to create another login form and another admin template. Right?
Can you explain me a bit what it will imply for each solution (backend/frontend). It may be helpful for other newbies like me.
Thanks!
Paul
#4
Posted 08 May 2012 - 10:05 AM
If, on the frontend, you can easily put on your template some logic that only allows user with the same name as the page to see it:
if($user->name === $page->name){
echo "you are allowed <img src='http://processwire.com/talk/public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />";
}else{
echo "you are NOT allowed <img src='http://processwire.com/talk/public/style_emoticons/<#EMO_DIR#>/sad.png' class='bbc_emoticon' alt=':(' />";
}
#5
Posted 08 May 2012 - 12:56 PM
#6
Posted 08 May 2012 - 09:59 PM
Thank you very much for your replies.
The structure of my website will be:
-------------
Project
-------------
-project name
-project description ->textarea field
-list of students involved in this project
-simple login form so students involved can edit their Profile or Student page.
<<Join this Project>> (a link to a registration for for students who want to join this project)
------------
Student
------------
Here I want to have three tabs easily outputed on frontpage with jqueryUI and on backend with "jquery wire tabs"
[1]About Tab
----Profile Image->image field (retrieved from the Registration Form)
----Student bio->textarea field (each student can write a bit about him/herself/ also retrieved from the Registration Form)
[2]Project Updates
----Repeater
---------Update Image->image field
---------Update details->textarea field
[3]Contact
---a very simple contact for sending direct messages to each student (email retrieved from the Registration Form)
----------------------
Registration Form
----------------------
---Student Name (all the users will be students. No other type of users will be allowed)
---Bio (used on the About Tab)
---Profile Image (used on the About Tab)
---Email (used on the Contact Tab form, hidden for the public)
---Project (a dropdown list of existing Projects. Field already populated if sent from <<Join Project link>> displayed on each Project page)
I don't know if it will be possible to create automatically a StudentX page on UserX registration using the above form under the Project they choose from the dropdown menu.
Thanks a lot! I'd really appreciate your help. I've been trying to accomplish this with other CMS/ CMF but none supports the user/page permission I want and also the automation of Student page.
#7
Posted 09 May 2012 - 12:00 PM
#8
Posted 09 May 2012 - 09:35 PM
Thank you very much for your reply. I bet you are an extremely busy man and I appreciate taking time to answer my questions.
Yes, you are right, I'm looking for a framework and as I mentioned in my previous post, I tried several CMFs and even though they are extremely flexible, when it comes to very customized applications only you realize their limitations.
Just looking through the PW's API documentation, it seems to be able to do most of the things I want, but I only have to find the right flow.
I want strip down the structure I posted before and have the following scenarios:
1. StudentX is a simple page with the following fields:
--title
--author (a hidden field to show the relationship with UserX)
--content->a textarea field
UserX is already registered and he loges in to edit his page. He has permission only to edit his own page and nothing else.
What will be the security concerns in this case if we allow the UserX to edit StudentX page in the Backend?
2. UserY is not registred yet.
He accesses the Registration form and StudentY page is created and he's redirected to that page and he will be able to add the content of the page.
Probably the Registration Form is not that difficult to create. Just create a template and add the right Processes to it. Right?
The biggest problem is the Editing. How can I accomplish that in the Frontend?
Diogo posted this chunk of code
if($user->name === $page->name){
echo "you are allowed <img src='http://processwire.com/talk/public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />";
}else{
echo "you are NOT allowed <img src='http://processwire.com/talk/public/style_emoticons/<#EMO_DIR#>/sad.png' class='bbc_emoticon' alt=':(' />";
}
Can you elaborate a bit? What should I add in the "you are allowed case"?
And I was thinking that the condition should be in my case
if($user->name === $page->author){
echo "you are allowed <img src='http://processwire.com/talk/public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />";
}else{
echo "you are NOT allowed <img src='http://processwire.com/talk/public/style_emoticons/<#EMO_DIR#>/sad.png' class='bbc_emoticon' alt=':(' />";
}
because I don't see the logic in user and page name to be the same.Thanks again! And I hope you'll have time to help me with more advises concerning this application.
#9
Posted 10 May 2012 - 03:27 AM
if($user->name === $page->author){
echo "you are allowed <img src='http://processwire.com/talk/public/style_emoticons/<#EMO_DIR#>/smile.png' class='bbc_emoticon' alt=':)' />";
}else{
echo "you are NOT allowed <img src='http://processwire.com/talk/public/style_emoticons/<#EMO_DIR#>/sad.png' class='bbc_emoticon' alt=':(' />";
}Of course you can do it, given that the user creates the page. The code I posted would allow you to do what you asked even if the page wouldn't be created by this user.
He accesses the Registration form and StudentY page is created
You can create a page on the fly like this
$p = new Page();
$p->template = $templates->get("person");
$p->parent = $pages->find(1015); // whatever page you want to be the parent
$p->name = $user->name; // I insist on this, like this you don't need the hidden field that you mentioned <img src='http://processwire.com/talk/public/style_emoticons/<#EMO_DIR#>/wink.png' class='bbc_emoticon' alt=';)' />
$p->title = $user->name . "'s personal page";
$p->content = "write here something";
$p->save();
creating the form on the front end is not that difficult, in your case you can do something like this:
<?php
$myPage = $pages->find("name=$user->name");
if ($input->post->content){
$value = $sanitizer->textarea($input->post->content);
$myPage->content = $value;
$myPage->setOutputFormatting(false);
$myPage->save();
}?>
<form name="form" method="post" action="<?php echo $page->url ?>">
<label for="content">Content</label>
<textarea name="content" id="content"><?php echo $value ?></textarea>
<input type="submit" value="Submit" />
</form>
#10
Posted 10 May 2012 - 03:55 AM
Thanks Diogo! I did something similar, but my solution wasn't as clean and clear as yours!
This forum is amazing!
I have two more questions, and probably more after those those two will be answered
1. The registration form must contain the User creation also and I don't know the API for that, and after User and Student are created I have to redirect the User to the newly created Student page in order to add real content to it.
2. One reason I still have doubts about the Frontend solution is because I wanted to have a Repeater field as content, where users could post only "chunks" containing an image and some text. Is it possible to create a Module to do the same as above, but in the Backend? In this way all the fields would be already styled.
Thanks again! Really appreciate your help!
#11
Posted 10 May 2012 - 05:17 AM
True, I didn't find it on the API or on the cheatsheet... but to get the creation timestamp of page you use $page->created, so I tried $user->created, and it worked
You can use it like this:
$created = date('Y-m-d H:i:s', $user->created);edit: forgot the second part of 1.
you can use
$session->redirect($myPage->url);after the page creation code (this must be done before any markup output)
2.
I guess it's possible to create the module, or maybe it's even easier to reproduce the repeaters on the frontend. But I will let others help you with that...
#12
Posted 10 May 2012 - 03:18 PM
1. The registration form must contain the User creation also and I don't know the API for that, and after User and Student are created I have to redirect the User to the newly created Student page in order to add real content to it.
$student = $users->add('norboo');
$student->pass = 'some password';
$student->save();
$studentPage = new Page();
$studentPage->parent = '/path/to/student/pages/';
$studentPage->template = 'student';
$studentPage->name = 'norboo';
$studentPage->title = "Norboo's Student page";
$studentPage->save();
$session->redirect($studentPage->url);
2. One reason I still have doubts about the Frontend solution is because I wanted to have a Repeater field as content, where users could post only "chunks" containing an image and some text. Is it possible to create a Module to do the same as above, but in the Backend? In this way all the fields would be already styled.
If you need something to hold an image and some text, this is what the Image fieldtype already does. No reason to use repeaters when the Image fieldtype can already do this more efficiently. The fieldtype's settings will let you specify how many images you want to allow and how big of a text field should be provided with each image.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users












