Typical vuex action is:
const actions = {
/**
* #param {ActionContext} context passed by vuex
* #param {Object} payload
* #return {void}
*/
myAction(vuexContext, payload) {...}
}
Where vuexContext would be injected for me, and in app I would use this function just as myAction(payload). But for that case my WebStorm IDE complains about invalid number of arguments.
Maybe there is some workaround for it?
You can try marking context parameter optional:
/**
* #param {ActionContext} [vuexContext]
* #param {Object} payload
* #return {void}
*/
myAction(vuexContext, payload) {}
Please also vote for the related feature request: WEB-29740
Related
I am building a web app whereby after an admin(with the role of a manager) approves a booking, the booking passes to another admin(with the role of an accountant) who then starts working on it.I want the manager to send a notification to only the accountant after approving the booking.i tried this code below and it sends to all admins which is not what I want to achieve
$users=User::where('is_admin','1')->get();
Notification::send($users,new Newbookingrecieved($bookingstatus));
then i tried getting the email from the role model
$users=Role::where('Role_name','The Accountant')->get();
Notification::send($users,new Newbookingrecieved($bookingstatus));
but it responded with an error
BadMethodCallException
Call to undefined method App\Models\Role::routeNotificationFor()
here is my notification
<?php
namespace App\Notifications;
use App\Models\Bookings;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class Newbookingrecieved extends Notification
{
use Queueable;
public $bookingstatus;
/**
* Create a new notification instance.
*
* #return void
*/
public function __construct($bookingstatus)
{
$this->bookingstatus = $bookingstatus;
}
/**
* Get the notification's delivery channels.
*
* #param mixed $notifiable
* #return array
*/
public function via($notifiable)
{
return ['mail'];
}
/**
* Get the mail representation of the notification.
*
* #param mixed $notifiable
* #return \Illuminate\Notifications\Messages\MailMessage
*/
public function toMail($notifiable)
{
return (new MailMessage)
->greeting('Hello there sir/madam')
->subject('New Booking by' .$this->bookingstatus->full_name)
->line('We have received a new Booking and approved it to you to request payment from the client' . $this->bookingstatus->email)
->action('Review This Booking', route('changestatus', $this->bookingstatus->id));
}
/**
* Get the array representation of the notification.
*
* #param mixed $notifiable
* #return array
*/
public function toArray($notifiable)
{
return [
//
];
}
}
here are all the roles
how can i achieve this such that i send the notification to the only adminand the notification wont be sent to other admins.
As I don't know the structure of your User model, I will assume that there is a role_id field.
Here is a piece of my code from one of my old projects that I will modify to your liking (it works for me) :
$users = User::where('role_id', 3)->get(); //3 is the id of The Accountant role
Notification::send($users, new Newbookingrecieved($bookingstatus));
In my GCP project, I created a new api key. I restricted the key to IOS apps, and properly set my IOS application bundle id.
The api key is being used in an Ionic 5 app, which has been built in Xcode and is running on an IOS device.
The api key is being passed on a Google Maps static API request.
To test the api key restriction I crafted a url that looks like this:
https://maps.googleapis.com/maps/api/staticmap?center=290%20Bremner%20Blvd%2C%20Toronto%2C%20ON%20M5V%203L9&key=[restricted key here]&zoom=12&size=400x400
When I load this url from my laptop web browser a map is returned, but I expected this not to work, and instead that I would receive an http 403 error.
Any insight into what I'm missing here appreciated; how do I properly restrict my maps api key when using it in an Ionic 5 app?
I found the answer to my question: in addition to using a restricted API key, each Maps Static API request must be digitally signed when making the request.
Here's sample Node js code from Google on how to do this:
'use strict'
const crypto = require('crypto');
const url = require('url');
/**
* Convert from 'web safe' base64 to true base64.
*
* #param {string} safeEncodedString The code you want to translate
* from a web safe form.
* #return {string}
*/
function removeWebSafe(safeEncodedString) {
return safeEncodedString.replace(/-/g, '+').replace(/_/g, '/');
}
/**
* Convert from true base64 to 'web safe' base64
*
* #param {string} encodedString The code you want to translate to a
* web safe form.
* #return {string}
*/
function makeWebSafe(encodedString) {
return encodedString.replace(/\+/g, '-').replace(/\//g, '_');
}
/**
* Takes a base64 code and decodes it.
*
* #param {string} code The encoded data.
* #return {string}
*/
function decodeBase64Hash(code) {
// "new Buffer(...)" is deprecated. Use Buffer.from if it exists.
return Buffer.from ? Buffer.from(code, 'base64') : new Buffer(code, 'base64');
}
/**
* Takes a key and signs the data with it.
*
* #param {string} key Your unique secret key.
* #param {string} data The url to sign.
* #return {string}
*/
function encodeBase64Hash(key, data) {
return crypto.createHmac('sha1', key).update(data).digest('base64');
}
/**
* Sign a URL using a secret key.
*
* #param {string} path The url you want to sign.
* #param {string} secret Your unique secret key.
* #return {string}
*/
function sign(path, secret) {
const uri = url.parse(path);
const safeSecret = decodeBase64Hash(removeWebSafe(secret));
const hashedSignature = makeWebSafe(encodeBase64Hash(safeSecret, uri.path));
return url.format(uri) + '&signature=' + hashedSignature;
}
More information / documentation here:
https://developers.google.com/maps/documentation/maps-static/get-api-key#gen-sig
In my Restler API class I have an object defined like so (with lots of other params)
class PatchTaskObj extends TaskObj {
/**
* #var bool|null Whether or not this Task should be pinned to the top of the list {#required false}
*/
public $pinned = null;
}
And then I attempt to use it in my PATCH method:
/**
* Updates an existing Task record.
*
* #param int $id The SQL ident of the task you wish to update. {#min 1} {#from path}
* #param PatchTaskObj $info The properties of the Task to update.
*
* #throws RestException 412 Thrown if at least one update isn't passed in.
*
* #status 204
*/
function patch($id, PatchTaskObj $info)
If I pass in true for the pinned property it works fine, but if I pass false then I get a 400 from Restler with the message:
Bad Request: Invalid value specified for info[pinned]
OK, discovered that Restler's Validator.php is failing to parse the #var property the way it's written. If you remove the |null part then it works as expected. I've submitted an issue to the github site.
I created a Behavior which contains function. This function should be afterLogon of User (yii/web/User::EVENT_AFTER_LOGIN).
But this function never will be triggered unfortunatelly.
I have a Behaviour class for the user model:
class UserBehavior extends Behavior
{
/**
* #inheritdoc
* #param \yii\base\Component $owner
*/
public function attach($owner)
{
parent::attach($owner);
$owner->on(\yii\web\User::EVENT_AFTER_LOGIN, [$this, 'updateLoginInformation']);
}
/**
* Update login information data:
* - login ip address
* - login time
*/
public function updateLoginInformation()
{
/** #var \common\models\User $owner */
$owner = $this->owner;
$owner->logged_in_ip = Yii::$app->request->getUserIP();
$owner->logged_in_at = time();
$owner->save();
}
}
I declared the events and the attach too.
But this events never be run after login...
I attached this behavior to the user model:
/**
* #inheritdoc
*/
public function behaviors()
{
return [
TimestampBehavior::className(),
UserBehavior::className()
];
}
If I know well the the EVENT_AFTER_LOGIN will be triggered automatically by the Yii framework, this is the reason why I do not trigger it again.
And I do not where is the problem, because the updageLoginInformatin never called.
I usually use any logic I want in a model inside the proper action that calls it (IE: actionLogin). But I like your approach.
I just made a test here and the correct way to call the event is something like this:
$user = \Yii::$app->user;
$user->on($user::EVENT_AFTER_LOGIN, [$this, 'updateLoginInformation']);
I didn't create a behavior class, I just added this lines in my init(), but the logic is probably the same as yours.
I am using the latest version of Restler v3 (commit 0d79cd8) but I'm having some problems having my Swagger-based UI look the same as in the examples. The two problems I'm noticing are that variable typing and #return objects are not being displayed.
On the Restler site, here's a good example of both of these working:
example
Instead, in my Actions class I get this:
And yet as you can see from definition of the class both type information and a response object is specified:
class Actions {
/**
* LIST action types
*
* List all the action-types available
*
* #url GET /
*/
function list_actions() {
throw new RestException(501);
}
/**
* GET today's Actions
*
* Get the set of actions done today
*
* #url GET /{user_id}
* #param integer $user_id The user_id for whom the actions apply; you can insert the text "self" and it will resolve to the current/default user
* #param string $time_of_day {#from url} Allow's you to optionally set a time-of-day; if set then actions are only returned after that. Time should be in the format of HH:MM:SS
* #return ActionList
*/
public function action_today ($user_id, $time_of_day = false )
{
throw new RestException(501, "Today's actions for user '{$user_id}' not implemented.");
}
and my definition of ActionList class is:
class ActionList {
/**
* Unique identifier of action
*
* #var integer
*/
public $action_id;
/**
* String based unique identifier
*
* #var string
*/
public $action_slug;
}
If your class is versioned, e.g. in the namespace v1\Actions, you have to annotate the return type in the namespace too, e.g. #return v1\ActionList