Context : I want my users to be able to moderate my themes. I created a role moderator, and added a "moderation" (array) field to my user. Therefore, I can give rights to a specific user to one or more Themes.
I'm creating a Back Office to manage users using EasyAdmin & Symfony4.
I want to have a multiple select field displaying my available theme to give rights to users.
Here is my current configuration of easy admin :
User:
class: App\Entity\User
disabled_actions: ['new']
edit:
fields:
- username
- email
- { property: 'roles', type: 'choice', type_options: { multiple: true, choices: { 'ROLE_USER': 'ROLE_USER', 'ROLE_MODERATOR': 'ROLE_MODERATOR', 'ROLE_ADMIN': 'ROLE_ADMIN' } } }
- { property: 'moderate', type: 'entity', type_options: { class: 'App\Entity\Theme', multiple: true } }
Things are going pretty well, since I'm able to edit my user, give him a role, and give him sites to moderate.
The issue :
The current state of my "moderate" array is not displayed. The select doesn't have the current value displayed when showing up.
Related
This what happens when I put translation:
# translations/messages.en.yaml
Post: Posts
easy_admin:
entities:
Post:
class: App\Entity\Post
list:
fields:
- { property: 'title', label: 'post.title' }
- { property: 'post', label: 'post.content' }
In the side menu I need it as Posts and in the create page as Create post. Can't find how to translate these.
I need to be able to extend the collection that accounts-ui creates by default of users.
import { Class } from 'meteor/jagi:astronomy';
import { Behavior } from 'meteor/jagi:astronomy-softremove-behavior';
/**
* #class User
*/
const User = Class.create ({
name: 'User',
collection: Meteor.Users,
secured: false,
fields: {
emails: {
type: Email,
optional: true
}
},
behaviors: {
softremove: {
removedFieldName: 'removed',
hasRemovedAtField: true,
removedAtFieldName: 'removedAt'
},
timestamp: {
hasCreatedField: true,
createdFieldName: 'createdAt',
hasUpdatedField: true,
updatedFieldName: 'updatedAt'
}
}
});
export default User;
I wan't use Meteor.user.(), only like to use the User class.
Welcome to Stack Overflow.
The users collection in Meteor is special. Under the hood in Mongo it is a regular collection.
For security reasons, you can't use the users collection like a regular collection, for example you can update your own user record, but you can't browse and edit other users records.
My advice is to create a separate collection for your user profile information. It's not a perfect solution, but it is better to leave the users collection under the control of the Meteor accounts package.
It is possible to extend the collection to store a few profile type data elements, but even that has some wrinkles, because when a user record is updated, the tracker runs, and your UI will refresh (with possible negative side effects if the refresh isn't expected)
I'm working in a project where a "super admin" user can create another users, setting they usernames and passwords. I have an AutoForm quickForm rendering a form based upon the SimpleSchema attached to the Meteor.users collection (using Collection2).
Following the Collection2 docs recommendation on attaching a schema to the users collection, my schema looks like this:
Usuarios.schema = new SimpleSchema({
...
username: {
type: String,
},
services: {
type: Object,
optional: true,
blackbox: true
},
"services.password": {
type: String,
optional: true,
autoform: {
type: 'password'
}
},
...
});
The rendered form looks like this:
But I would like to have the Password field rendered like the Username one (without the Services panel).
I haven't found a workaround to this. I need to have the Services Object type atribute in the schema or the validation upon user insert fails (with Accounts.createUser()), and so, the panel is rendered (because of the Object type of the atribute).
Any ideas on how I could achieve the desired template rendering?
Your password is part of the 'service' object, which is why it is automatically rendered inside a afObjectField when using quickForm or quickFields:
afObjectField
When you use the afQuickField component for a field that is an Object,
it is rendered using the afObjectField component unless you override
the type or specify options. This happens by default when you use a
quickForm for a schema that has a field of type Object.
The afObjectField component renders all of an object field's subfields
together as one group. The group is labeled with the name of the
object field. The actual visual representation of the group will vary
based on which theme template you use. For the "bootstrap3" default
template, the group appears in a panel with a heading.
Solution A: Manual Form Rendering
To render your password as a single field, you need to set up your autForm manually and reference the fields by using afFieldInput. The form mthen may look like (not tested but code should look like) this:
{{> autoForm id="login" schema=Usuarios.schema}}
{{> afFieldInput type="text" name="username"}}
{{> afFieldInput type="password" name="services.password"}}
{{/autoForm}}
Which has the advantage that your form looks exactly as you wish but has the disadvantage, that you have to add all extras (validation messages and stuff) manually.
Solution B: Change your Schema
When you pull password out of the service group, then you will have the same effect of auto-render as with username: a single input field.
Usuarios.schema = new SimpleSchema({
...
username: {
type: String,
},
services: {
type: Object,
optional: true,
blackbox: true
},
...
password: {
type: String,
optional: true,
autoform: {
type: 'password'
}
},
...
});
In the schema declaration I have:
CollectionName.attachSchema(new SimpleSchema({
issue: {
type: String,
label: "Describe the issue you noticed",
max:256
},
location: {
label: "Place a marker on your approximate location",
type: String,
autoform: {
type: 'map',
afFieldInput: {
type: 'map',
autolocate: true,
zoom:16
}
}
}
I'd like to allow a user to take a picture on this insert form
{{> quickForm collection="CollectionName" id="inserttoCollection" type="insert"}}
I'd like to be able to let an individual not only document the location of an issue but take a picture of what issue was noticed.
My question: How do I set up a field properly so that it allows a user to take and upload a photo.
This is one of the areas where Meteor shines - isomorphic APIs that work across desktop and mobile browsers.
You'll want to meteor add mdg:camera, add a button to your form, and set its click handler to run MeteorCamera.getPicture().
Read more at https://github.com/meteor/mobile-packages/tree/master/packages/mdg:camera
I'm using SonataAdminBundle with Symfony 2.2 and want to display the dashboard blocks depending on what user is logged in.
e.g.
Users with Group Superadmin will see blocks 'UserManagement' and 'Messages'
Users with Group Staff will see only block 'Messages'
I read the whole documentation especially the security doc but found no info on how to restrict the dashboard view. I already implemented a filter which will will show no entries in the list view of an entity class if the user's permissions are not enough.
But it would be way better to not show him the blocks at all.
Any ideas on how to do this ?
Well, for anyone running into this, I solved it by simply returning an empty Response in execute(). My use-case was one where I wanted to show a block to users with a specific role:
First I defined my service for using the security.context service like so:
sonata.block.service.foo:
class: Acme\DemoBundle\Block\FooBlockService
arguments: [ "sonata.block.service.foo", "#templating", "#doctrine", "#security.context" ]
tags:
- { name: sonata.block }
Then I defined the block service __construct() as:
//Acme\DemoBundle\Block\FooBlockService
public function __construct($name, EngineInterface $templating, $doctrine, $securityContext)
{
parent::__construct($name, $templating);
$this->doctrine = $doctrine;
$this->securityContext = $securityContext;
}
Finally, in the execute function the first thing I did was check for a specific role on the user like so:
//Acme\DemoBundle\Block\FooBlockService
public function execute(BlockContextInterface $blockContext, Response $response = null)
{
if( $this->securityContext->isGranted("ROLE_ACME_FOO") === false )
{
return new Response();
}
//... more code
This works, but it feels like a hack. Mainly, because the Block goes through all of its stages, and only on the output it return nothing, meaning overhead. A better solution would be to somehow prevent the entire Block from being loaded, based on some custom code.
In conclusion, this isn't the best way, but it worked for me!
You can restrict access to block using roles, like this:
sonata_admin:
dashboard:
blocks:
- { position: top, type: your_service_block_name, class: 'col-xs-4', roles: [ROLE_SOME_NAME_HERE_, ROLE_SOME_NAME_HERE_2] }
You can check under SonataAdminBundle:Core:dashboard.html.twig how this roles works:
{% if block.roles|length == 0 or is_granted(block.roles) %}
<div class="{{ block.class }}">
{{ sonata_block_render({ 'type': block.type, 'settings': block.settings}) }}
</div>{% endif %}