Skip to content

Commit

Permalink
fix basic layout
Browse files Browse the repository at this point in the history
  • Loading branch information
shreeharsha-factly committed Jul 5, 2024
1 parent bdd6c41 commit 3f1bb52
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 93 deletions.
42 changes: 18 additions & 24 deletions server/config/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,34 +23,28 @@ func SetupVars() {
log.Fatal("please provide zitadel_domain config param")
}

if !Sqlite() {
if !viper.IsSet("database_host") {
log.Fatal("please provide database_host config param")
}
if !viper.IsSet("database_host") {
log.Fatal("please provide database_host config param")
}

if !viper.IsSet("database_user") {
log.Fatal("please provide database_user config param")
}
if !viper.IsSet("database_user") {
log.Fatal("please provide database_user config param")
}

if !viper.IsSet("database_name") {
log.Fatal("please provide database_name config param")
}
if !viper.IsSet("database_name") {
log.Fatal("please provide database_name config param")
}

if !viper.IsSet("database_password") {
log.Fatal("please provide database_password config param")
}
if !viper.IsSet("database_password") {
log.Fatal("please provide database_password config param")
}

if !viper.IsSet("database_port") {
log.Fatal("please provide database_port config param")
}
if !viper.IsSet("database_port") {
log.Fatal("please provide database_port config param")
}

if !viper.IsSet("database_ssl_mode") {
log.Fatal("please provide database_ssl_mode config param")
}
} else {
if !viper.IsSet("sqlite_db_path") {
log.Fatal("please provide sqlite_db_path config param")
}
if !viper.IsSet("database_ssl_mode") {
log.Fatal("please provide database_ssl_mode config param")
}

if !viper.IsSet("kavach_url") {
Expand Down Expand Up @@ -88,5 +82,5 @@ func SearchEnabled() bool {
}

func Sqlite() bool {
return viper.IsSet("use_sqlite") && viper.GetBool("use_sqlite")
return viper.IsSet("use_sqlite") && viper.GetBool("use_sqlite") && false
}
1 change: 0 additions & 1 deletion server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ require (
github.com/lib/pq v1.10.2 // indirect
github.com/magiconair/properties v1.8.5 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-sqlite3 v1.14.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/mapstructure v1.4.1 // indirect
github.com/moul/http2curl v1.0.0 // indirect
Expand Down
3 changes: 1 addition & 2 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,8 @@ github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHX
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/meilisearch/meilisearch-go v0.20.0 h1:dhGrSbOzJ5z7/efEIvo9lFazeJN+J4yYI3FDiTUTlPA=
Expand Down
1 change: 1 addition & 0 deletions server/service/core/model/post.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,6 @@ func (pa *PostAuthor) BeforeCreate(tx *gorm.DB) error {

pa.CreatedByID = uID
pa.UpdatedByID = uID
pa.ID = uuid.New()
return nil
}
72 changes: 6 additions & 66 deletions studio/src/layouts/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import routes from '../config/routesConfig';
import _ from 'lodash';
import { setSpaceSelectorPage } from '../actions/spaceSelectorPage';
import MobileSidebar from '../components/GlobalNav/MobileSidebar';
import { permissionRequirements } from '../utils/getUserPermission';

function BasicLayout(props) {
const [isMobileScreen, setIsMobileScreen] = React.useState(false);
Expand Down Expand Up @@ -120,80 +121,19 @@ function BasicLayout(props) {
);
}

console.log('location.pathname', location.pathname);

const hideSidebar =
(location.pathname.includes('posts') ||
location.pathname.includes('fact-checks') ||
location.pathname.includes('pages')) &&
(location.pathname.includes('edit') || location.pathname.includes('create'));

const permissionRequirements = {
'/posts': [
{ resource: 'categories', action: 'get' },
{ resource: 'tags', action: 'get' },
{ resource: 'posts', action: ['get', 'create'] },
],
'/posts/create': [
{ resource: 'categories', action: 'get' },
{ resource: 'media', action: 'get' },
{ resource: 'tags', action: 'get' },
{ resource: 'posts', action: ['get', 'create'] },
],
'/pages': [
{ resource: 'categories', action: 'get' },
{ resource: 'tags', action: 'get' },
{ resource: 'pages', action: ['get', 'create'] },
],
'/pages/create': [
{ resource: 'categories', action: 'get' },
{ resource: 'media', action: 'get' },
{ resource: 'tags', action: 'get' },
{ resource: 'pages', action: ['get', 'create'] },
],
'/fact-checks': [
{ resource: 'categories', action: 'get' },
{ resource: 'tags', action: 'get' },
{ resource: 'fact-checks', action: ['get', 'create'] },
],
'/fact-checks/create': [
{ resource: 'categories', action: 'get' },
{ resource: 'tags', action: 'get' },
{ resource: 'media', action: 'get' },
{ resource: 'claims', action: 'get' },
{ resource: 'fact-checks', action: ['get', 'create'] },
],
'/claims': [
{ resource: 'claimants', action: 'get' },
{ resource: 'ratings', action: 'get' },
{ resource: 'claims', action: ['get', 'create'] },
],
'/claims/create': [
{ resource: 'claimants', action: 'get' },
{ resource: 'ratings', action: 'get' },
{ resource: 'claims', action: ['get', 'create'] },
],
'/categories/create': [
{ resource: 'media', action: 'get' },
{ resource: 'categories', action: ['get', 'create'] },
],
'/tags/create': [
{ resource: 'media', action: 'get' },
{ resource: 'tags', action: ['get', 'create'] },
],
'/claimants/create': [
{ resource: 'media', action: 'get' },
{ resource: 'claimants', action: ['get', 'create'] },
],
'/ratings/create': [
{ resource: 'media', action: 'get' },
{ resource: 'ratings', action: ['get', 'create'] },
],
};

function checkPermissions(pathname, selected, orgs, userPermission) {
function checkPermissions(pathname, userPermission) {
const requiredPermissions = permissionRequirements[pathname];

if (!requiredPermissions) {
return null;
}

// Check if userPermission includes 'admin' for any resource
const isAdmin = userPermission.some((perm) => perm.resource === 'admin');

Expand Down
63 changes: 63 additions & 0 deletions studio/src/utils/getUserPermission.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,66 @@
export const permissionRequirements = {
'/posts': [
{ resource: 'categories', action: 'get' },
{ resource: 'tags', action: 'get' },
{ resource: 'posts', action: ['get', 'create'] },
],
'/posts/create': [
{ resource: 'categories', action: 'get' },
{ resource: 'media', action: 'get' },
{ resource: 'tags', action: 'get' },
{ resource: 'posts', action: ['get', 'create'] },
],
'/pages': [
{ resource: 'categories', action: 'get' },
{ resource: 'tags', action: 'get' },
{ resource: 'pages', action: ['get', 'create'] },
],
'/pages/create': [
{ resource: 'categories', action: 'get' },
{ resource: 'media', action: 'get' },
{ resource: 'tags', action: 'get' },
{ resource: 'pages', action: ['get', 'create'] },
],
'/fact-checks': [
{ resource: 'categories', action: 'get' },
{ resource: 'tags', action: 'get' },
{ resource: 'fact-checks', action: ['get', 'create'] },
],
'/fact-checks/create': [
{ resource: 'categories', action: 'get' },
{ resource: 'tags', action: 'get' },
{ resource: 'media', action: 'get' },
{ resource: 'claims', action: 'get' },
{ resource: 'fact-checks', action: ['get', 'create'] },
],
'/claims': [
{ resource: 'claimants', action: 'get' },
{ resource: 'ratings', action: 'get' },
{ resource: 'claims', action: ['get', 'create'] },
],
'/claims/create': [
{ resource: 'claimants', action: 'get' },
{ resource: 'ratings', action: 'get' },
{ resource: 'claims', action: ['get', 'create'] },
],
'/categories/create': [
{ resource: 'media', action: 'get' },
{ resource: 'categories', action: ['get', 'create'] },
],
'/tags/create': [
{ resource: 'media', action: 'get' },
{ resource: 'tags', action: ['get', 'create'] },
],
'/claimants/create': [
{ resource: 'media', action: 'get' },
{ resource: 'claimants', action: ['get', 'create'] },
],
'/ratings/create': [
{ resource: 'media', action: 'get' },
{ resource: 'ratings', action: ['get', 'create'] },
],
};

function getUserPermission({ resource, action, spaces }) {
const { selected, details } = spaces;
const userPermission =
Expand Down

0 comments on commit 3f1bb52

Please sign in to comment.