chyabrung-cli 0.2.2

The `chy` command line tool for Chyabrung: scaffolding, dev server with hot reload, builds, generators, migrations and one-command deploys
use chyabrung::prelude::*;

/// A row of the `posts` table (created in `migrations/..._create_posts_table.up.sql`).
#[derive(Debug, Clone, Serialize, Deserialize, Model)]
#[model(timestamps)]
pub struct Post {
    pub id: i64,
    pub user_id: i64,
    pub title: String,
    pub body: String,
    pub published: bool,
    pub created_at: Option<String>,
    pub updated_at: Option<String>,
}

impl Post {
    /// Whether `user` may change this post: its author, or anyone with `permission`.
    pub fn can_be_changed_by(&self, user: &Identity, permission: &str) -> bool {
        user.id == self.user_id.to_string() || user.can(permission)
    }
}