refactor: Don't leak rocket::State into models Previously the State was passed into the models where it had no reason to be. So a minor cleanup has been performed to right this.

zj
Oct 26, 2021, 1:40 PM
YZAHAQRQHK24QY2H3AXKCPPDIE2F53H35C5CNYUSXRDSNCWOUJVQC

Dependencies

  • [2] JNOEM73W User: improve create code to use as factory Removes duplication and improves code style.
  • [3] RYCS2BYF authz: Only repository owners can push changes Before all users could push changes to a repository. This was a shortcut which is changed now. For now only owners can push new changes to a repository. This isn't great either, as it doesn't allow for collaboration as of yet. However, it's a better default and allows nidobyte to be deployed on the internet soon after. As such this default has now been chosen, and will later be updated.
  • [4] SZIYDOFD refactor: Move User guard to the model The User model didn't have the FromRequest 'constructor' for the guard. This felt off. Now some Request knowledge leaks to the model, but still it seems better.
  • [5] FS2NWBVN pijul: Start of push/pull work This change includes one API endpoint, .pijul. It allows for getting a channels remote ID. A lot of plumbing around repositories is added too, from init to opening pristine and actions like it.
  • [6] DSWQKJRH users: Introduce User guard for routes Rockets guards are very powerful to disallow users for certain routes. This far this wasn't implemented, and allowed no-one other than the first user to sign up. This change introduces the User guard and employs it for a few routes. The guard works by checking the encrypted cookie for the user_id, and perform a database lookup on it.
  • [7] F5DMFQAO routes: Move project routes to controllers module Much like other routes, just move the files and clean up the tree.
  • [8] TWIZ7QV4 db: Add interface to add a project Right now a project has a name, and an owner which is hardcoded to 1. This is because basically I'm speedrunning to implement push/pull of Pijul and then revisit to add depth to features and tests. Model code is now split into files properly too.
  • [9] GD7FCQ2K ui: Fix navigation issues To get the bare minimum working, this change adds some basic navigation to the applicaiton. It's far from perfect, but nonetheless, it's something. :)
  • [10] E4OBIIUB templates: Fix navigation mocks Cleans up the directory structure for templates and fixes the navigation bugs in the applications too. Includes a context! macro which is lifted from upstream, but is currently unreleased. When rocket_dyn_templates is updates, it could be DRY'ed out.

Change contents

  • replacement in "src/models/users.rs" at line 19
    [2.67][2.67:97]()
    db: &State<Database>,
    [2.67]
    [2.97]
    db: &Database,
  • replacement in "src/models/users.rs" at line 30
    [4.2733][4.2733:2759]()
    .fetch_one(&**db)
    [4.2733]
    [4.2759]
    .fetch_one(db)
  • replacement in "src/models/users.rs" at line 36
    [2.458][2.458:542]()
    pub async fn find(db: &State<Database>, id: i32) -> Result<Self, sqlx::Error> {
    [2.458]
    [2.542]
    pub async fn find(db: &Database, id: i32) -> Result<Self, sqlx::Error> {
  • replacement in "src/models/users.rs" at line 38
    [2.607][2.607:637]()
    .fetch_one(&**db)
    [2.607]
    [2.637]
    .fetch_one(db)
  • replacement in "src/models/users.rs" at line 45
    [4.2995][4.2995:3025]()
    db: &State<Database>,
    [4.2995]
    [4.3025]
    db: &Database,
  • replacement in "src/models/users.rs" at line 55
    [4.3303][4.3303:3334]()
    .fetch_optional(&**db)
    [4.3303]
    [4.3334]
    .fetch_optional(db)
  • edit in "src/models/projects.rs" at line 3
    [4.3493][4.3493:3512]()
    use rocket::State;
  • replacement in "src/models/projects.rs" at line 14
    [4.1425][4.1425:1523]()
    pub async fn find(db: &State<Database>, org_path: String, proj_path: String) -> Option<Project> {
    [4.1425]
    [4.1523]
    pub async fn find(db: &Database, org_path: String, proj_path: String) -> Option<Project> {
  • replacement in "src/models/projects.rs" at line 17
    [4.1669][4.819:870]()
    proj_path, org_path).fetch_optional(&**db)
    [4.1669]
    [4.1712]
    proj_path, org_path).fetch_optional(db)
  • replacement in "src/models/projects.rs" at line 23
    [4.1749][4.871:950]()
    pub async fn list(db: &State<Database>) -> Result<Vec<Project>, sqlx::Error> {
    [4.1749]
    [4.950]
    pub async fn list(db: &Database) -> Result<Vec<Project>, sqlx::Error> {
  • replacement in "src/models/projects.rs" at line 25
    [4.1005][4.1005:1031]()
    .fetch_all(&**db)
    [4.1005]
    [4.1031]
    .fetch_all(db)
  • replacement in "src/models/projects.rs" at line 30
    [4.1770][4.1770:1796]()
    db: &State<Database>,
    [4.1770]
    [4.1796]
    db: &Database,
  • replacement in "src/models/projects.rs" at line 40
    [4.2044][4.2044:2066]()
    .fetch_one(&**db)
    [4.2044]
    [4.2066]
    .fetch_one(db)
  • replacement in "src/models/projects.rs" at line 52
    [4.3728][4.1083:1160]()
    pub async fn organisation(&self, db: &State<Database>) -> Result<User> {
    [4.3728]
    [3.1195]
    pub async fn organisation(&self, db: &Database) -> Result<User> {
  • replacement in "src/models/projects.rs" at line 56
    [3.1231][3.1231:1301]()
    pub async fn owner(&self, db: &State<Database>) -> Result<User> {
    [3.1231]
    [4.1160]
    pub async fn owner(&self, db: &Database) -> Result<User> {
  • replacement in "src/models/projects.rs" at line 83
    [4.1404][4.1404:1475]()
    pub async fn new(db: &State<Database>, project: Project) -> Self {
    [4.1404]
    [4.1475]
    pub async fn new(db: &Database, project: Project) -> Self {
  • replacement in "src/models/pijul/repositories.rs" at line 164
    [3.1874][3.1874:1960]()
    pub async fn owner(&self, db: &rocket::State<Database>) -> anyhow::Result<User> {
    [3.1874]
    [3.1960]
    pub async fn owner(&self, db: &Database) -> anyhow::Result<User> {
  • replacement in "src/controllers/projects.rs" at line 50
    [4.1107][4.1107:1177]()
    match projects::create(db, user.id, project.name.clone()).await {
    [4.1107]
    [4.1177]
    match projects::create(&**db, user.id, project.name.clone()).await {
  • replacement in "src/controllers/projects.rs" at line 66
    [4.2024][4.2024:2101]()
    let p = if let Some(p) = projects::find(db, org_path, proj_path).await {
    [4.2024]
    [4.2101]
    let p = if let Some(p) = projects::find(&**db, org_path, proj_path).await {
  • replacement in "src/controllers/projects.rs" at line 76
    [4.2303][4.2303:2360]()
    organisation: p.organisation(db).await.ok(),
    [4.2303]
    [4.2360]
    organisation: p.organisation(&**db).await.ok(),
  • replacement in "src/controllers/projects.rs" at line 87
    [4.2532][4.2532:2609]()
    let p = if let Some(p) = projects::find(db, org_path, proj_path).await {
    [4.2532]
    [4.2609]
    let p = if let Some(p) = projects::find(&**db, org_path, proj_path).await {
  • replacement in "src/controllers/projects.rs" at line 98
    [4.2843][4.2843:2900]()
    organisation: p.organisation(db).await.ok(),
    [4.2843]
    [4.2900]
    organisation: p.organisation(&**db).await.ok(),
  • replacement in "src/controllers/projects.rs" at line 110
    [4.3091][4.3091:3159]()
    let projects = if let Ok(projects) = projects::list(db).await {
    [4.3091]
    [4.3159]
    let projects = if let Ok(projects) = projects::list(&**db).await {
  • replacement in "src/controllers/projects.rs" at line 118
    [4.3325][4.3325:3395]()
    disp.push(projects::DispProject::new(db, proj.clone()).await)
    [4.3325]
    [4.4657]
    disp.push(projects::DispProject::new(&**db, proj.clone()).await)