Skip to content

Commit

Permalink
chore: prepare 3.0.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
DDtKey committed Apr 3, 2022
1 parent 0731e9d commit e060f5d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 19 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

## [v3.0.0] - 22-04-02
## [v3.0.0] - 22-04-03
### Added
- `actix-web: 4.0.1` support [#30]

Expand Down
2 changes: 1 addition & 1 deletion examples/enum-role/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-web = { version = "4.0.0-beta.19" }
actix-web = { version = "4.0" }
actix-web-grants = { path = "../../" }
21 changes: 10 additions & 11 deletions examples/enum-role/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use crate::role::Role::{self, Admin};
use actix_web::dev::ServiceRequest;
use actix_web::{get, middleware, web, App, Error, HttpResponse, HttpServer};
use actix_web_grants::{proc_macro::has_any_role, GrantsMiddleware, PermissionGuard};
use actix_web_grants::permissions::{AuthDetails, RolesCheck};
use crate::role::Role::{self, ADMIN};
use actix_web_grants::{proc_macro::has_any_role, GrantsMiddleware, PermissionGuard};

mod role;

#[get("/macro_secured")]
// `proc-macro` way require specify your type. It can be an import or a full path.
#[has_any_role("ADMIN", "role::Role::MANAGER", type = "Role")]
#[has_any_role("Admin", "role::Role::Manager", type = "Role")]
// For the `ADMIN` or `MANAGER` - endpoint will give the HTTP status 200, otherwise - 403
async fn macro_secured() -> HttpResponse {
HttpResponse::Ok().finish()
Expand All @@ -17,7 +17,7 @@ async fn macro_secured() -> HttpResponse {
#[get("/manual")]
// An example of programmable protection with custom type
async fn manual_secure(details: AuthDetails<Role>) -> HttpResponse {
if details.has_role(&Role::ADMIN) {
if details.has_role(&Role::Admin) {
return HttpResponse::Ok().body("Hello Admin!");
}
HttpResponse::Ok().body("Hello!")
Expand All @@ -36,13 +36,13 @@ async fn main() -> std::io::Result<()> {
.service(
web::resource("/guard_admin")
.to(|| async { HttpResponse::Ok().finish() })
.guard(PermissionGuard::new(ADMIN)),
.guard(PermissionGuard::new(Admin)),
)
})
.bind("localhost:8082")?
.workers(1)
.run()
.await
.bind("localhost:8082")?
.workers(1)
.run()
.await
}

// You can specify any of your own type (`PartialEq` + `Clone`) for the return type wrapped in a vector: Result<Vec<YOUR_TYPE_HERE>, Error>
Expand All @@ -51,6 +51,5 @@ async fn extract(_req: &mut ServiceRequest) -> Result<Vec<Role>, Error> {
// For example from a token or database

// Stub example
Ok(vec![Role::ADMIN])
Ok(vec![Role::Admin])
}

7 changes: 3 additions & 4 deletions examples/enum-role/src/role.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

// `PartialEq` and `Clone` is required
#[derive(PartialEq, Clone)]
pub enum Role {
ADMIN,
MANAGER
}
Admin,
Manager,
}
4 changes: 2 additions & 2 deletions examples/jwt-httpauth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
actix-web = { version = "4.0.0-beta.19" }
actix-web = { version = "4.0" }
actix-web-grants = { path = "../../" }
actix-web-httpauth = "0.6.0-beta.7"
actix-web-httpauth = "0.6.0"
jsonwebtoken = "7"
serde = {version = "1.0", features = ["derive"] }
chrono = "0.4.19"
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![doc(html_logo_url = "https://raw.githubusercontent.com/DDtKey/actix-web-grants/main/logo.png")]
//! A crate for validate user permissions in `actix-web`.
//!
//! For built-in configure see: [`GrantsMiddleware`].
Expand Down

0 comments on commit e060f5d

Please sign in to comment.